I would like to have an Ingress in my k8s cluster point to a service and pod on my k8s cluster which will serve a tls cert signed from a CA which is not well-known. To do this, I am trying to add a trusted_root_certificate block to my already existing azurerm_application_gateway terraform resource.
However, I get the following error
Error: waiting for update of Application Gateway: (Name "@@@" / Resource Group "@@@"): Code="ApplicationGatewayKeyVaultSecretException" Message="Problem occured while accessing and validating KeyVault Secrets associated with Application Gateway '/subscriptions/@@@/resourceGroups/@@@/providers/Microsoft.Network/applicationGateways/@@@'. See details below:" Details=[{"code":"ApplicationGatewayTrustedRootCertificateInvalidData","message":"Data for certificate /subscriptions/@@@/resourceGroups/@@@/providers/Microsoft.Network/applicationGateways/@@@/trustedRootCertificates/@@@ is invalid."}]
I have tried using a referenced key vault certificate in both PEM (private key with certificate chain) and PFX (manually converted PEM to PFX using openssl).
Below is the terraform with omissions for brevity.
locals {
ca_name = "myca"
}
data "azurerm_key_vault_certificate" "ca" {
name = local.ca_name
key_vault_id = data.azurerm_key_vault.myvault.id
}
resource "azurerm_application_gateway" "http_ingress" {
sku {
name = "WAF_v2"
}
backend_http_settings {
name = "https"
cookie_based_affinity = "Disabled"
port = 443
protocol = "Https"
pick_host_name_from_backend_address = true
trusted_root_certificate_names = ["${local.ca_name}"]
}
trusted_root_certificate {
name = local.ca_name
key_vault_secret_id = data.azurerm_key_vault_certificate.ca.versionless_secret_id
}
}
azurerm provider
...
azurerm = {
source = "hashicorp/azurerm"
version = "~> 3.78.0"
}
In the Azure Portal, the following error is displayed for the application gateway:
Last configuration update operation on this Application Gateway failed. This will not impact the functioning of the Application Gateway and it will continue to serve your application traffic. If you intend to change the configuration of the Application Gateway, please try doing the configuration update again.
However, another interesting piece is that even though the terraform apply fails, the trusted root certificate does get added to the application gateway and backend setting.
terraform -v
Terraform v1.4.5
on darwin_arm64
Any ideas?
The above error is indicating that data for the certificate is invalid. The
key_vault_secret_idattribute should point to a key vault secret, not a certificate, in thetrusted_root_certificateblock. Using theversionless_secret_idof theazurerm_key_vault_certificatedata source, which retrieves a certificate, may be causing the issue.I used below code to create
Application Gatewaywithtrusted_root_certificatemoduleThe
Keyvault Certificateis displayed and accessible whenTerraform applyis executed.Refer Application gateway SSL Profile & Application Gateway module in Terraform