Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

azurerm_api_management_subscription get Primary/Secondary Key #6938

Merged
merged 11 commits into from May 20, 2020
Expand Up @@ -187,13 +187,19 @@ func resourceArmApiManagementSubscriptionRead(d *schema.ResourceData, meta inter

if props := resp.SubscriptionContractProperties; props != nil {
d.Set("display_name", props.DisplayName)
d.Set("primary_key", props.PrimaryKey)
d.Set("secondary_key", props.SecondaryKey)
d.Set("state", string(props.State))
d.Set("product_id", props.Scope)
d.Set("user_id", props.OwnerID)
}

// Primary and secondary keys must be got from this additional api
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this documented as a breaking change from Microsoft? Just curious how you figured this out.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The service team comment it in swagger

keyResp, err := client.ListSecrets(ctx, resourceGroup, serviceName, subscriptionId)
if err != nil {
return fmt.Errorf("listing Subscription %q Primary and Secondary Keys (API Management Service %q / Resource Group %q): %+v", subscriptionId, serviceName, resourceGroup, err)
}
d.Set("primary_key", keyResp.PrimaryKey)
d.Set("secondary_key", keyResp.SecondaryKey)

return nil
}

Expand Down
Expand Up @@ -24,6 +24,8 @@ func TestAccAzureRMAPIManagementSubscription_basic(t *testing.T) {
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMAPIManagementSubscriptionExists(data.ResourceName),
resource.TestCheckResourceAttrSet(data.ResourceName, "subscription_id"),
resource.TestCheckResourceAttrSet(data.ResourceName, "primary_key"),
resource.TestCheckResourceAttrSet(data.ResourceName, "secondary_key"),
),
},
data.ImportStep(),
Expand All @@ -44,6 +46,8 @@ func TestAccAzureRMAPIManagementSubscription_requiresImport(t *testing.T) {
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMAPIManagementSubscriptionExists(data.ResourceName),
resource.TestCheckResourceAttrSet(data.ResourceName, "subscription_id"),
resource.TestCheckResourceAttrSet(data.ResourceName, "primary_key"),
resource.TestCheckResourceAttrSet(data.ResourceName, "secondary_key"),
),
},
data.RequiresImportErrorStep(testAccAzureRMAPIManagementSubscription_requiresImport),
Expand All @@ -65,6 +69,8 @@ func TestAccAzureRMAPIManagementSubscription_update(t *testing.T) {
testCheckAzureRMAPIManagementSubscriptionExists(data.ResourceName),
resource.TestCheckResourceAttr(data.ResourceName, "state", "submitted"),
resource.TestCheckResourceAttrSet(data.ResourceName, "subscription_id"),
resource.TestCheckResourceAttrSet(data.ResourceName, "primary_key"),
resource.TestCheckResourceAttrSet(data.ResourceName, "secondary_key"),
),
},
{
Expand Down Expand Up @@ -106,6 +112,8 @@ func TestAccAzureRMAPIManagementSubscription_complete(t *testing.T) {
testCheckAzureRMAPIManagementSubscriptionExists(data.ResourceName),
resource.TestCheckResourceAttr(data.ResourceName, "state", "active"),
resource.TestCheckResourceAttrSet(data.ResourceName, "subscription_id"),
resource.TestCheckResourceAttrSet(data.ResourceName, "primary_key"),
resource.TestCheckResourceAttrSet(data.ResourceName, "secondary_key"),
),
},
data.ImportStep(),
Expand Down