Take Microsoft.Web/staticSites/linkedBackends resource as an example, in the configuration, there's no location field defined and the schema validation also fails if the location is defined.
After the resource is created, the location field was set automatically by Azure and terraform wants to recreate the resource on every plan and apply. The configuration:
resource "azapi_resource" "webapp_linked_backend" {
type = "Microsoft.Web/staticSites/linkedBackends@2022-09-01"
name = "webapp-${var.env}-${var.location}"
parent_id = azurerm_static_web_app.web_app.id
body = {
kind = "Container App"
properties = {
backendResourceId = var.web_backend_id
region = var.location
}
}
}
The terraform output:
# module.web_app.azapi_resource.webapp_linked_backend must be replaced
-/+ resource "azapi_resource" "webapp_linked_backend" {
~ id = "/subscriptions/<SUBSCRIPTON>/resourceGroups/<RG>/providers/Microsoft.Web/staticSites/<STATIC_WEB>/linkedBackends/<NAME>" -> (known after apply)
- location = "East US 2" -> null # forces replacement
name = "webapp-dev-eastus2"
~ output = {} -> (known after apply)
# (6 unchanged attributes hidden)
}
Workaround
Step 1. Add the location field to the configuration to make the configuration match with the remote state. It's okay to use lifecycle.ignore_changes to suppress the difference too.
lifecycle {
ignore_changes = [
location,
]
}
Disable the scheme validation by adding the below configuration
schema_validation_enabled = false
Known resource types
It also happens to other resource types, listed as the following:
Behavior
Take
Microsoft.Web/staticSites/linkedBackends
resource as an example, in the configuration, there's no location field defined and the schema validation also fails if thelocation
is defined.After the resource is created, the
location
field was set automatically by Azure and terraform wants to recreate the resource on every plan and apply. The configuration:The terraform output:
Workaround
Step 1. Add the
location
field to the configuration to make the configuration match with the remote state. It's okay to uselifecycle.ignore_changes
to suppress the difference too.Known resource types
It also happens to other resource types, listed as the following:
Related issues
https://github.com/Azure/terraform-provider-azapi/issues/629 https://github.com/Azure/terraform-provider-azapi/issues/601 https://github.com/Azure/terraform-provider-azapi/issues/584 https://github.com/Azure/terraform-provider-azapi/issues/563 https://github.com/Azure/terraform-provider-azapi/issues/541 https://github.com/Azure/terraform-provider-azapi/issues/538 https://github.com/Azure/terraform-provider-azapi/issues/514 https://github.com/Azure/terraform-provider-azapi/issues/511