-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
key vault soft-delete causing failure when updating secrets or certificates #5659
Comments
I'm seeing exactly the same issue. The new https://www.terraform.io/docs/providers/azurerm/index.html#purge_soft_delete_on_destroy |
Hi guys, I have a client that requires soft delete to be enabled on their Key Vaults. This limits the existing AzureRM provider's usefulness due to a lack of handling around deleted but not purged secrets with the same name. In the case where the secret needs to be deleted and recreated using Terraform, the apply will fail due to the secret being in a recoverable state. There are also some interesting timing challenges around the delete --> purge --> recover that the API presents if you script this use AZ CLI as the secret enters a transition state between each of these major states. Would love to see support for this in the provider. |
@garethmorris78 have you tried adding to your keyvault attributes: soft_delete_enabled = true |
We also have this problem. Now that Azure will remove opt-out of soft-delete on all Key Vaults by the end of year, this presents a major problem. Side note / question: Is it a bug that a azurerm_key_vault_certificate must be re-created and is not updated in-place? The certificate resource does support versioning, but maybe the underlying API does not? |
Hi, As said just above by @jvassbo , that will be an issue when Azure will force Soft delete on all KV until this end of year, and good remark about update certificate and not destroy/create (versionning must me used here). This is espacially annoying when we used automatic ACME certificate, and it's not impossible to automatic renew certificates now. As workaround, i use a random ressource for the naming the key vault certificate, and in CICD task, i terraform taint this random name for force renew with a new certificate name. but I've to schedule it, and renew is not based on expiration days left. It could be nice to have an option to update actual certificate with new one, without destroy previous one. Regards |
I've started looking into this and it appears that there is an overlap in how the The The In a specific case to As some have already highlighted both in this issue and others, this is becoming more of a concern now that soft-delete will be enforced across all keyvaults later this year and no longer be optional. In situations where terraform is managing its own secrets (creation/updates/deletion), one would expect that a destroy operation can provide the option to "purge" the secret. That said, one question is: would we use the existing provider-level feature This could be implemented with something like this:
Feedback is appreciated. Happy to raise a PR if needed based on what the wider group comes back with. |
@tombuildsstuff Would you be able to provide feedback on this or perhaps suggest someone who can help us move this forward? |
Definitely seems like a big problem waiting to happen. From my observations with certificates
|
@hbuckle I noticed the same behaviour. What happens if you then run another round of terraform plan & apply? Does it update the key vault objects to the latest values? |
I haven't tried but I assume it would try and remove and re-create it again and therefore fail. TBH I am currently going through and ripping out the azurerm_key_vault_certificate resource and replacing it with a script provisioner to create new versions, as I can't afford for this to stop working |
@thomasbrueggemann If you re-run the apply, terraform will find that the (recovered) does not match what it expects in state and will then force the update, creating a new version of the secret. Recovery on apply may well be the right option in certain situations where the secret may have been deleted outside of terraform. It seems like the most pressing concern is that if terraform destroys the secret, we need to be able to specify whether it should be purged or not (perhaps using the features This behavior is specifically for secrets. I haven't tested keys or certificates. |
Bumping this so developers see this. Does anyone have a working fix that doesn't require The az cli module allows specific methods and detects existing configurations without being destructive. It must be possible for Terraform to tap into these same API calls. Below is a workaround. The Workaround example: # Create .pfx file locally
resource "local_file" "b64cert" {
content_base64 = acme_certificate.certificate.certificate_p12
filename = "${filename}.pfx"
}
# Import certificate to Azure Key Vault - Workaround
resource "null_resource" "AzCommand" {
provisioner "local-exec" {
command = "az keyvault certificate import --vault-name ${data.azurerm_key_vault.vault.name} -n ${var.certificatename} -f ${filename}.pfx"
}
} |
This has been released in version 2.41.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.41.0"
}
# ... other configuration ... |
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 👉 [email protected]. Thanks! |
key vault soft-delete causing failure when updating secrets and certificates
instead of creating a new version of the secret of the certificate, terraform apply fails
The text was updated successfully, but these errors were encountered: