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.6k stars 4.64k forks source link

Executing request: unexpected status 404 (404 Not Found) with error: ResourceNotFound: NamedValue not found #26661

Open mpigram1 opened 3 months ago

mpigram1 commented 3 months ago

Is there an existing issue for this?

Community Note

Terraform Version

1.8.4

AzureRM Provider Version

3.110.0

Affected Resource(s)/Data Source(s)

azurerm_api_management_named_value

Terraform Configuration Files

resource "azurerm_api_management_named_value" "named_value" {
  for_each = { for secret in var.secrets : secret.secret_id => secret }

  name                = var.display_name
  resource_group_name = var.resource_group_name
  api_management_name = var.apim_name
  display_name        = var.display_name
  secret              = true

  value_from_key_vault {
    secret_id          = each.value.secret_id
    identity_client_id = each.value.identity_client_id
  }
}

module "apim_name_values" {
  source = "../../modules/api-name-values"

  display_name        = "XXXXXX"
  resource_group_name = module.resource_group.resource_group_name
  apim_name           = module.api_management.api_management_name

  secrets = [
    {
      secret_id          = data.terraform_remote_state.shared_services.outputs.key_vault_secret_id["XXXX"]
      identity_client_id = module.managed_identities.mi_principal_id
    }
  ]

  depends_on = [ module.key_vault_access_policies ]
}

Debug Output/Panic Output

❯ terraform apply tfplan                                                      
module.apim_name_values.azurerm_api_management_named_value.named_value["<KEY VAULT SECRET ID>"]: Creating...
module.apim_name_values.azurerm_api_management_named_value.named_value["<KEY VAULT SECRET ID>"]: Still creating... [10s elapsed]
╷
│ Error: creating or updating Named Value (Subscription: "XXXX"
│ Resource Group Name: "XXXX"
│ Service Name: "XXXX"
│ Named Value: "XXXXX"): polling after CreateOrUpdate: executing request: unexpected status 404 (404 Not Found) with error: ResourceNotFound: NamedValue not found.
│ 
│   with module.apim_name_values.azurerm_api_management_named_value.named_value["<KEY VAULT SECRET ID>"],
│   on ../../modules/api-name-values/main.tf line 1, in resource "azurerm_api_management_named_value" "named_value":
│    1: resource "azurerm_api_management_named_value" "named_value" {

Expected Behaviour

It should create the named value within the APIM and link to the key vault secret using the managed identity I created for the APIM.

Actual Behaviour

Does not create and the error appears above.

Steps to Reproduce

terraform plan -no-color -out tfplan terraform apply

Important Factoids

No response

References

No response

ricardochaves commented 2 months ago

Any update here?

nathangiuliani commented 2 months ago

We're experiencing the same issue. It does actually create the named value though, and terraform apply succeeds the second time (for this resource...)

aiden-liu commented 1 month ago

There can be various reasons behind, for my case it's the org's firewall rule not allowing the traffic between APIM and key vault. Enable the TF_LOG=debug may reveal much useful information.