Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

azurerm_api_management_named_value not waiting for createOrUpdate #7539

Closed
xinyi-joffre opened this issue Jun 30, 2020 · 2 comments · Fixed by #7547
Closed

azurerm_api_management_named_value not waiting for createOrUpdate #7539

xinyi-joffre opened this issue Jun 30, 2020 · 2 comments · Fixed by #7547

Comments

@xinyi-joffre
Copy link
Contributor

xinyi-joffre commented Jun 30, 2020

Terraform (and AzureRM Provider) Version

Terraform: v0.12.26
AzureRM Provider: v2.8.0

Affected Resource(s)

  • azurerm_api_management_named_value

Terraform Configuration Files

data "external" "apis_hostkeys" {
  for_each = toset(var.function_app_names)

  program = ["bash", "-c", "az rest --method post --uri ${data.azurerm_resource_group.app_target_rg.id}/providers/Microsoft.Web/sites/${azurerm_function_app.apis[each.key].name}/host/default/listKeys?api-version=2018-11-01 --query functionKeys"]

  depends_on = [
    azurerm_function_app.apis
  ]
}

resource "azurerm_api_management_named_value" "apis_backend_code" {
  for_each = toset(var.function_app_names)

  name                = "${each.key}-function-code-${local.semantic_version}"
  resource_group_name = data.azurerm_resource_group.app_target_rg.name
  api_management_name = data.azurerm_api_management.apim.name
  display_name        = "${each.key}-function-code-${local.semantic_version}"
  value               = data.external.apis_hostkeys[each.key].result.default
  secret              = true
}

Debug Output

data.external.apis_hostkeys["devices"]: Refreshing state...
azurerm_api_management_named_value.apis_backend_code["devices"]: Creating...

Error:  retrieving Property "devices-function-code-0-1-2" (Resource Group "***" / API Management Service "****-apim-***"): apimanagement.NamedValueClient#Get: Failure responding to request: StatusCode=404 -- Original Error: autorest/azure: Service returned an error. Status=404 Code="ResourceNotFound" Message="Property not found."

  on functions.tf line 79, in resource "azurerm_api_management_named_value" "apis_backend_code":
  79: resource "azurerm_api_management_named_value" "apis_backend_code" {

Expected Behavior

Named value is created in Azure and terraform exits successfully.

Actual Behavior

This is intermittent race condition, but happens often enough to break our pipeline 2 days in a row.

The named value is created in Azure, but terraform fails to fetch/get the resource since Azure has not yet finished creating it.

This then means that the resources is successfully created but the TF state does not know about the created resource. In order to fix it, we need to manually import the resource into the state or delete the resources and try again.

Steps to Reproduce

  1. Try to deploy new named value many times.
  2. Eventually, the deployment will fail when it tries to "get" the resource right after creation.

References

This seems to be related to a recently fixed bug for azurerm_api_management_api resource having a similar problem. We likely need to add the same "future" fix for the named values resource as well.

@ghost
Copy link

ghost commented Jul 3, 2020

This has been released in version 2.17.0 of the provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading. As an example:

provider "azurerm" {
    version = "~> 2.17.0"
}
# ... other configuration ...

@ghost
Copy link

ghost commented Jul 31, 2020

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 feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. If you feel I made an error 🤖 🙉 , please reach out to my human friends 👉 hashibot-feedback@hashicorp.com. Thanks!

@hashicorp hashicorp locked and limited conversation to collaborators Jul 31, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
3 participants