-
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
Updating azurerm_key_vault_certificate fails when soft delete is enabled for Key Vault #10658
Comments
Used |
@katbyte what is the status on this ? It's been reported for a year and a half that the keyvault certificate recover feature of the provider doesn't actually work which completely thwart the use of keyvault certificates with terraform if you don't have purge rights, which is the case for most users, while certificates are very much ubiquitous and at the center of online infrastructure. @jibinpb Could you give some detail on your workaround solution ? I can't figure out how to keep the resource in the terraform declaration while allowing to |
Create the azurerm_key_vault_certificate as you would normally, ensure that: lifecycle {
ignore_changes = [
certificate
]
} Is on the resource. Then export the certificate using resource "local_file" "b64cert" {
content_base64 = acme_certificate.primary.certificate_p12
filename = "${path.module}/yourCertificateName.pfx"
} And then finally, use az cli to do the update against the keyvault; resource "null_resource" "azCommandUpdateCertificate" {
provisioner "local-exec" {
command = "az keyvault certificate import --vault-name ${azurerm_key_vault.yourVault.name} --name ${azurerm_key_vault_certificate.yourCertificate.name} --file ${path.module}/yourCertificateName.pfx --password ${sensitive(azurerm_key_vault_secret.yourPassphrase .value)}"
}
}
Do not omit the "sensitive" function or you'll output your pfx passphrase to logs. |
@jibinpb how'd you go about omitting the --password parameter? I've got sensitive() on it but it looks like there's a bug, in that when it errors, it outputs the password to cli. |
Thanks all! |
I had to make one adjustment to @jdelforno 's workaround for it to work, otherwise it would try running the null_resource before the local_file existed:
|
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. |
Community Note
Terraform (and AzureRM Provider) Version
Terraform v0.14.7
azurerm v2.48.0
Affected Resource(s)
azurerm_key_vault_certificate
(resource
)Terraform Configuration Files
I have also created a sample repository that can be used to reproduce the issue.
Debug Output
Expected Behaviour
Changing the certificate should upload a new version of the certificate. If the certificate is in a
deleted
state, it should be recovered so that a new version can be uploaded.Actual Behaviour
The certificate gets left in a deleted state and does not get recovered.
terraform apply
fails because there is a conflict.azurerm_key_vault_secret
is therefore unusable with a Key Vault withsoft_delete_enabled
.Steps to Reproduce
terraform init
example.pfx
terraform apply
example.pfx
terraform apply
Important Factoids
For secrets, this mechanism works fine. In fact, there is a workaround that recovers the secret before a new one gets created.
For certificates, the same workaround has been implemented but doesn't seem to work.
References
2.41.0
but still not working for certificates)The text was updated successfully, but these errors were encountered: