Create a new version of key vault secret using Terraform

Total
1
Shares

I am trying to create a new version of key vault secret which already exists. But it always gives me error while using the below code when the secret already exist. Is there any way to create new version of secret.

resource "azurerm_key_vault_secret" "example" {
 name         = "test"
 value        =  random_password.password.result
 key_vault_id = data.azurerm_key_vault.keyvault.id
}

I always get this error
│ Error: A resource with the ID "https://dev-kv.vault.azure.net/secrets/test/9d2108c9695a366" already exists - to be managed via Terraform this resource needs to be imported into the State. Please see the resource documentation for "azurerm_key_vault_secret" for more information.


Solution

Terraform is using state file, unfortunately it does not support upsert. So you have 3 options here.

  • Delete your secret "test" from keyvault and run terraform
  • import resource to terraform state file with test secret
  • just choose different name
Leave a Reply

Your email address will not be published. Required fields are marked *