Skip to content

Commit

Permalink
Solved Issue 62: Unable to delete APIM when destroying infrastructure…
Browse files Browse the repository at this point in the history
… with Terraform. (#63)

* Update APIM type to use api version `2023-03-01-preview` which does not have the issue when deleting the APIM.
* Added dependency (`depends_on`) with  for `azurerm_api_management_named_value.tenant_id` for the `azurerm_api_management_api_policy.policy` which is required when deleting the APIM due to an indirect dependency with the Tenant ID value.
* Add `prevent_deletion_if_contains_resources` flag as `false` to mitigate an open bug in Terraform. or instance, the Resource Group is not deleted when a `Failure Anomalies` resource is present. Reference: hashicorp/terraform-provider-azurerm#18026
  • Loading branch information
rliberoff authored Jun 12, 2024
1 parent c60b35d commit 2af03f3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
3 changes: 2 additions & 1 deletion infra/modules/apim/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ locals {
}

resource "azapi_resource" "apim" {
type = "Microsoft.ApiManagement/service@2023-05-01-preview"
type = "Microsoft.ApiManagement/service@2023-03-01-preview"
name = var.apim_name
parent_id = var.resource_group_id
location = var.location
Expand Down Expand Up @@ -168,6 +168,7 @@ resource "azurerm_api_management_api_policy" "policy" {
</on-error>
</policies>
XML
depends_on = [ azurerm_api_management_named_value.tenant_id ]
}

# https://github.com/aavetis/azure-openai-logger/blob/main/README.md
Expand Down
6 changes: 6 additions & 0 deletions infra/providers.tf
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ provider "azurerm" {
api_management {
purge_soft_delete_on_destroy = true
}
resource_group {
# This flag is set to mitigate an open bug in Terraform. For instance, the Resource Group is not deleted when a `Failure Anomalies` resource is present.
# As soon as this is fixed, we should remove this.
# Reference: https://github.com/hashicorp/terraform-provider-azurerm/issues/18026
prevent_deletion_if_contains_resources = false
}
}
}

Expand Down

0 comments on commit 2af03f3

Please sign in to comment.