This week we started getting the below error on an API deployment with Terraform and APIM using the azurerm_api_management_api_diagnostic resource.

Error: 
retrieving Diagnostic "applicationinsights" (Resource Group "My-ResourceGrouo" / 
API Management Service "My-APIM" / API "my-api"): 
apimanagement.APIDiagnosticClient#Get: 
Failure responding to request: StatusCode=404 -- Original Error: autorest/azure: Service returned an error. Status=404 Code="ResourceNotFound" Message="Diagnostic not found."

I am not 100% sure of the cause of this but my guess is an older version of the azurerm provider and an update to the Azure API’s are the cause.

If you update the provider and then re-run it you get a problem that the API is already deployed and has diagnostics configured so you cant create it because it already exists.

There are 2 choices:

Option 1 – Import the existing Azure resource into your state

This is easy enough and uses the terraform import command

Option 2 – Clear the diagnostics setting and re-apply

Go to your API, its settings tab and clear the enabled check box then rerun terraform apply which will recreate the diagnostics settings

 

Buy Me A Coffee