I'm using Terraform to deploy a new certificate, from Certbot, for the application gateway to a website, in Azure. In the past, previous replacements of the certificate with a new one have worked fine. This time I got this error from Terraform:
│ Error: keyvault.BaseClient#RecoverDeletedCertificate: Failure responding to request: StatusCode=404 -- Original Error: autorest/azure: Service returned an error. Status=404 Code="CertificateNotFound" Message="A certificate with (name/id) prod-cert-2023-03-002 was not found in this key vault. If you recently deleted this certificate you may be able to recover it using the correct recovery command. For help resolving this issue, please see https://go.microsoft.com/fwlink/?linkid=2125182" │ │ with azurerm_key_vault_certificate.cert, │ on key-vault.tf line 135, in resource "azurerm_key_vault_certificate" "cert": │ 135: resource "azurerm_key_vault_certificate" "cert"
Turns out that certbot is now returning ECDSA certificates by default: https://community.letsencrypt.org/t/ecdsa-certificates-by-default-and-other-upcoming-changes-in-certbot-2-0/177013
So, obviously, I could specifically ask Certbot to give me an RSA cert, but it seems a good idea to upgrade to the modern system.
Azure wants the certificate imported in pkcs12:
openssl pkcs12 -export -in cert.pem -inkey privkey.pem -out certificate.pfx -certfile chain.pem
Here's my key vault in terraform:
resource "azurerm_key_vault_certificate" "cert" {
name = var.key_vault_newcert_name
key_vault_id = azurerm_key_vault.vmss.id
certificate {
contents = filebase64("certificate.pfx")
password = ""
}
certificate_policy {
issuer_parameters {
name = "Unknown"
}
key_properties {
curve = "P-256"
exportable = true
key_size = 256
key_type = "EC"
reuse_key = true
}
secret_properties {
content_type = "application/x-pkcs12"
}
}
}
terraform apply is successful, and, through the web portal, I find the new certificate is there, but the Subject and SANs fields are empty/blank.
If I read the .pfx file:
openssl pkcs12 -in certificate.pfx -info -nodes
The subject looks correct:
subject=/CN=correctdomain.com
What gives?