hashicorp / terraform-provider-azurerm

Terraform provider for Azure Resource Manager
https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs
Mozilla Public License 2.0
4.58k stars 4.62k forks source link

Wrong destroy order when using named values for backend credentials #17080

Closed radui1398 closed 2 years ago

radui1398 commented 2 years ago

Is there an existing issue for this?

Community Note

Terraform Version

1.1.7

AzureRM Provider Version

2.99.0

Affected Resource(s)/Data Source(s)

azurerm_api_management_named_value, azurerm_api_management_backend

Terraform Configuration Files

- 1 APIM Instance
- 1 APIM API Instance
- 1 Named value that saves credentials "appKey"
- 1 Backend that uses the named value "my-backend"
- 1 Policy on the operation that uses a backend
- 1 Operation

Debug Output/Panic Output

╷
│ Error:  deleting Named Value: (Name "appKey" / Service Name "service-name" / Resource Group "rg"): apimanagement.NamedValueClient#Delete: Failure responding to request: StatusCode=400 -- Original Error: autorest/azure: Service returned an error. Status=400 Code="ValidationError" Message="The Api Management Property 'appKey' is used by the following entities:\r\n/backends/my-backend\r\n"
│ 
│ 
╵

Expected Behaviour

The delete order should be:

Actual Behaviour

The actual delete order probably is:

Steps to Reproduce

Only a terraform apply is enough to retrieve the error.

Important Factoids

Running in Europe West

References

No response

tombuildsstuff commented 2 years ago

hi @radui1398

Thanks for opening this issue.

Taking a look through here this appears to be an issue with the Terraform Configuration being used which can be solved by using a depends_on to explicitly define the dependencies, which'll enforce the ordering both when provisioning and tearing these resources down - which can be used in alongside interpolation (which creates an implied resource ordering).

Since this'll be fixed by updating the Terraform Configuration being used here, I'm going to close this issue for the moment as this forum is intended to be used for feature enhancements and bugs in the Azure Provider - however should you have further questions about the Terraform Configuration I'd direct you towards one of the Community Resources where someone should be able to assist further.

Thanks!

github-actions[bot] commented 2 years ago

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.