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

Fix TC for TestAccAzureRMApplicationInsightsAPIKey_requiresImport #7650

Merged
merged 2 commits into from
Jul 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,33 @@ func resourceArmApplicationInsightsAPIKeyCreate(d *schema.ResourceData, meta int
appInsightsName := id.Path["components"]

if features.ShouldResourcesBeImported() {
var existingAPIKeyList insights.ApplicationInsightsComponentAPIKeyListResult
var keyId string
existingAPIKeyList, err = client.List(ctx, resGroup, appInsightsName)
if err != nil {
if !utils.ResponseWasNotFound(existingAPIKeyList.Response) {
return fmt.Errorf("checking for presence of existing Application Insights API key list (Application Insights %q / Resource Group %q): %s", appInsightsName, resGroup, err)
}
}

for _, existingAPIKey := range *existingAPIKeyList.Value {
existingAPIKeyId, err := azure.ParseAzureResourceID(*existingAPIKey.ID)
if err != nil {
return err
}

existingAppInsightsName := existingAPIKeyId.Path["components"]
if appInsightsName == existingAppInsightsName {
keyId = existingAPIKeyId.Path["apikeys"]
break
}
}

var existing insights.ApplicationInsightsComponentAPIKey
existing, err = client.Get(ctx, resGroup, appInsightsName, name)
existing, err = client.Get(ctx, resGroup, appInsightsName, keyId)
if err != nil {
if !utils.ResponseWasNotFound(existing.Response) {
return fmt.Errorf("Error checking for presence of existing Application Insights API key %q (Resource Group %q): %s", name, resGroup, err)
return fmt.Errorf("checking for presence of existing Application Insights API key %q (Resource Group %q): %s", name, resGroup, err)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ func TestAccAzureRMApplicationInsightsAPIKey_requiresImport(t *testing.T) {
),
},
{
Config: testAccAzureRMApplicationInsightsAPIKey_requiresImport(data, "[]", "[]"),
ExpectError: acceptance.RequiresImportError("azurerm_application_insights"),
Config: testAccAzureRMApplicationInsightsAPIKey_requiresImport(data, "[]", `["annotations"]`),
ExpectError: acceptance.RequiresImportError("azurerm_application_insights_api_key"),
},
},
})
Expand Down