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_key_vault issues creating sercret, certificate, and key #18182

Closed
1 task done
ImperiumTakp opened this issue Aug 30, 2022 · 2 comments
Closed
1 task done

azurerm_key_vault issues creating sercret, certificate, and key #18182

ImperiumTakp opened this issue Aug 30, 2022 · 2 comments

Comments

@ImperiumTakp
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Terraform Version

3.201.18

AzureRM Provider Version

3.12.0

Affected Resource(s)/Data Source(s)

azurerm_key_vault

Terraform Configuration Files

resource "azurerm_key_vault" "main" {
  location                   = data.azurerm_resource_group.main.location
  name                       = "kv-${lower(var.projectName)}-${var.instance}-${(lower(var.environmentShort))}"
  resource_group_name        = data.azurerm_resource_group.main.name
  sku_name                   = "premium"
  tenant_id                  = data.azurerm_client_config.current.tenant_id
  enable_rbac_authorization  = true
  soft_delete_retention_days = 7
  purge_protection_enabled   = true
}

resource "azurerm_api_management_certificate" "main" {
  api_management_name = local.api_management_name
  name                = "${local.api}-certificate"
  resource_group_name = local.resource_group_name
  key_vault_secret_id = azurerm_key_vault_certificate.apim.secret_id
}

resource "azurerm_key_vault_secret" "appinsight_instrument_key" {
  key_vault_id = azurerm_key_vault.main.id
  name         = "appinsight-key"
  value        = sensitive(azurerm_application_insights.main.instrumentation_key)
}

resource "azurerm_key_vault_secret" "appinsight_id" {
  key_vault_id = azurerm_key_vault.main.id
  name         = "appinsight-id"
  value        = azurerm_application_insights.main.app_id
}

resource "azurerm_key_vault_key" "container_reg" {
  key_opts     = ["encrypt", "wrapKey", "unwrapKey"]
  key_type     = "RSA-HSM"
  key_size     = "2048"
  key_vault_id = azurerm_key_vault.main.id
  name         = "container-registry-key"
}

resource "azurerm_app_service_managed_certificate" "web_app" {
  custom_hostname_binding_id = azurerm_app_service_custom_hostname_binding.web_app.id
}

resource "azurerm_app_service_certificate_binding" "web_app" {
  certificate_id      = azurerm_app_service_managed_certificate.web_app.id
  hostname_binding_id = azurerm_app_service_custom_hostname_binding.web_app.id
  ssl_state           = "IpBasedEnabled"
}

resource "azurerm_key_vault_certificate" "web_app" {
  name         = "web-app-cert"
  key_vault_id = azurerm_key_vault.main.id

  certificate_policy {
    issuer_parameters {
      name = "Self"
    }

    key_properties {
      exportable = true
      key_size   = 2048
      key_type   = "RSA"
      reuse_key  = true
    }

    lifetime_action {
      action {
        action_type = "AutoRenew"
      }

      trigger {
        days_before_expiry = 30
      }
    }

    secret_properties {
      content_type = "application/x-pkcs12"
    }

    x509_certificate_properties {
      # Server Authentication = 1.3.6.1.5.5.7.3.1
      # Client Authentication = 1.3.6.1.5.5.7.3.2
      extended_key_usage = ["1.3.6.1.5.5.7.3.1"]

      key_usage = [
        "cRLSign",
        "dataEncipherment",
        "digitalSignature",
        "keyAgreement",
        "keyCertSign",
        "keyEncipherment",
      ]

      subject_alternative_names {
        dns_names = [data.azurerm_private_dns_zone.vnet.name]
      }

      subject            = "CN=${lower(var.projectName)}-${lower(var.environment)}"
      validity_in_months = 12
    }
  }
}

resource "azurerm_app_service_certificate" "web_app" {
  location            = data.azurerm_resource_group.main.location
  name                = "web-app-cert"
  resource_group_name = data.azurerm_resource_group.main.name
  app_service_plan_id = azurerm_service_plan.main.id
  key_vault_secret_id = azurerm_key_vault_certificate.web_app.secret_id
}

resource "azurerm_key_vault_secret" "web_app" {
  key_vault_id = azurerm_key_vault.main.id
  name         = "web-app-secret"
  value        = sensitive(random_password.web_app.result)
}

resource "random_password" "web_app" {
  length = 28
}

Debug Output/Panic Output

╷
│ Error: Provider produced inconsistent result after apply
│ 
│ When applying changes to azurerm_key_vault_key.container_reg, provider
│ "provider[\"registry.terraform.io/hashicorp/azurerm\"]" produced an
│ unexpected new value: Root resource was present, but now absent.
│ 
│ This is a bug in the provider, which should be reported in the provider's
│ own issue tracker.


│ Error: Provider produced inconsistent result after apply

│ When applying changes to azurerm_key_vault_secret.appinsight_id, provider
│ "provider[\"registry.terraform.io/hashicorp/azurerm\"]" produced an
│ unexpected new value: Root resource was present, but now absent.

│ This is a bug in the provider, which should be reported in the provider's
│ own issue tracker.
╵
╷
│ Error: Provider produced inconsistent result after apply
│ 
│ When applying changes to
│ module.web_app_apim.azurerm_key_vault_secret.apim_sub, provider
│ "provider[\"registry.terraform.io/hashicorp/azurerm\"]" produced an
│ unexpected new value: Root resource was present, but now absent.
│ 
│ This is a bug in the provider, which should be reported in the provider's
│ own issue tracker.


│ Error: Provider produced inconsistent result after apply

│ When applying changes to
│ azurerm_key_vault_secret.appinsight_instrument_key, provider
│ "provider[\"registry.terraform.io/hashicorp/azurerm\"]" produced an
│ unexpected new value: Root resource was present, but now absent.

│ This is a bug in the provider, which should be reported in the provider's
│ own issue tracker.
╵
╷
│ Error: Provider produced inconsistent result after apply
│ 
│ When applying changes to azurerm_key_vault_secret.web_app, provider
│ "provider[\"registry.terraform.io/hashicorp/azurerm\"]" produced an
│ unexpected new value: Root resource was present, but now absent.
│ 
│ This is a bug in the provider, which should be reported in the provider's
│ own issue tracker.



│ Error: Provider produced inconsistent result after apply

│ When applying changes to
│ module.web_app_apim.azurerm_key_vault_certificate.apim, provider
│ "provider[\"registry.terraform.io/hashicorp/azurerm\"]" produced an
│ unexpected new value: Root resource was present, but now absent.

│ This is a bug in the provider, which should be reported in the provider's
│ own issue tracker.
╵
╷
│ Error: Provider produced inconsistent result after apply
│ 
│ When applying changes to azurerm_key_vault_certificate.web_app, provider
│ "provider[\"registry.terraform.io/hashicorp/azurerm\"]" produced an
│ unexpected new value: Root resource was present, but now absent.
│ 
│ This is a bug in the provider, which should be reported in the provider's
│ own issue tracker.

Expected Behaviour

Expect it to create the certificates, secrets and keys

Actual Behaviour

It did not create the resources in the keyvault

Steps to Reproduce

rerunning the terraform, will prompt that you need to import the resources into the statefile

Important Factoids

No response

References

No response

@magodo
Copy link
Collaborator

magodo commented Aug 31, 2022

@ImperiumTakp Thank you for submitting this! There is an existing issue #11059 for tracking this, please subscribe it for any progress.

@magodo magodo closed this as completed Aug 31, 2022
@github-actions
Copy link

github-actions bot commented Oct 1, 2022

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 have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 1, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants