I’m trying to upload the .cer certificate to the backend settings of the App Gw using the below code:
data "azurerm_key_vault_secret" "intdev-api-cer" {
name = "intdev-api-cer"
key_vault_id = data.azurerm_key_vault.nw-kv-ie1.id
}
data "azurerm_key_vault_certificate" "intdev-api" {
name = "intdev-api"
key_vault_id = data.azurerm_key_vault.nw-kv-ie1.id
}
resource "azurerm_application_gateway" "appgw1" {
.......
backend_address_pool {
name = "Backendpool-intdev-api"
ip_addresses = ["X.X.X.X", "X.X.X.X"]
}
backend_http_settings {
name = "Backendsettings-intdev-api"
cookie_based_affinity = "Disabled"
path = "/"
port = 443
protocol = "Https"
request_timeout = 60
host_name = "intdev-api.xxx.com"
probe_name = "Healthprobe-intdev-api"
trusted_root_certificate_names = [data.azurerm_key_vault_secret.intdev-api-cer.name]
}
ssl_certificate {
name = data.azurerm_key_vault_certificate.intdev-api.name
key_vault_secret_id = data.azurerm_key_vault_certificate.intdev-api.secret_id
}
http_listener {
name = "Listener-intdev-api"
frontend_ip_configuration_name = "xyz"
frontend_port_name = "abc"
protocol = "Https"
host_name = "intdev-api.xxx.com"
ssl_certificate_name = data.azurerm_key_vault_certificate.intdev-api.name
}
request_routing_rule {
name = "Rule-intdev-api"
rule_type = "Basic"
http_listener_name = "Listener-intdev-api"
backend_address_pool_name = "Backendpool-intdev-api"
backend_http_settings_name = "Backendsetting-intdev-api"
priority = 3
}
probe {
name = "Healthprobe-intdev-api"
protocol = "Https"
pick_host_name_from_backend_http_settings = true
path = "/"
interval = 30
timeout = 30
unhealthy_threshold = 3
}
Error: updating Application Gateway: (Name "appgw1" / Resource Group "xyzabc"): network.ApplicationGatewaysClient#CreateOrUpdate: Failure sending request: StatusCode=400 — Original Error: Code="InvalidResourceReference" Message="Resource data.azurerm_key_vault_secret.intdev-api-cer.name referenced by resource backendHttpSettingsCollection/Backendsettings-intdev-api was not found . Please make sure that the referenced resource exists, and that both resources are in the same region." Details=[]
What is it i’m doing wrong here?
2
Answers
The problem was, I was trying to upload trusted root certificate to the backend settings through key vault. I had to define the
trusted_root_certificate
block and reference it in the backend settings.The code above is about uploading .pfx certificate to the listener.
I tried to reproduce the same in my environment and below is the result
I have created Keyvault and generated new certificate and uploading it in application gateway SSL using below terraform code.
Terraform plan:
Terraform apply:
Once ran the above code resources are created successfully and certificate also uploaded to Application gateway.
Reference: Stack link by Ansuman Bal.