Azure / terraform-provider-azapi

Terraform provider for Azure Resource Manager Rest API
https://registry.terraform.io/providers/Azure/azapi/latest
Mozilla Public License 2.0
184 stars 48 forks source link

`azapi_resource` with `linkedBackends` wants to replace resource because of default value #629

Open jpenna opened 2 weeks ago

jpenna commented 2 weeks ago

I'm using azapi 2.0.0-beta.

I'm using azapi to link a backen to my static web app. The initial deployment worked great, but then when I do terraform plan, it outputs the following:

  # 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)
    }

There is no location param to define. It 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
    }
  }
}

Quickfix to stop updating

resource "azapi_resource" "webapp_linked_backend" {
...
  schema_validation_enabled = false
  lifecycle {
    ignore_changes = [
      location,
    ]
  }
}
jpenna commented 1 week ago

Same thing for custom domains:

resource "azapi_resource" "webapp_custom_domain" {
  type      = "Microsoft.Web/staticSites/customDomains@2022-09-01"
  name      = "<DOMAIN>"
  parent_id = azurerm_static_web_app.web_app.id

  body = {
    properties = {
      validationMethod = "cname-delegation"
    }
  }
}

Updating location, which isn't available through the API:

Terraform will perform the following actions:

  # module.web_app.azapi_resource.webapp_custom_domain must be replaced
-/+ resource "azapi_resource" "webapp_custom_domain" {
      ~ id                        = "<ID>" -> (known after apply)
      - location                  = "East US 2" -> null # forces replacement
        name                      = "<DOMAIN>"
      ~ output                    = {} -> (known after apply)
        # (6 unchanged attributes hidden)
    }

Plan: 1 to add, 0 to change, 1 to destroy.