Skip to content

Commit e72c2e0

Browse files
rajbosCopilot
andcommitted
fix: replace azurerm_container_app_custom_domain with az rest PATCH for cert binding
azurerm_container_app_custom_domain rejects managedCertificate IDs at plan time (expects .../certificates/... but managed certs use .../managedCertificates/...). This is a known AzureRM provider limitation. Replace with a null_resource that PATCHes the container app ingress directly via az rest. The PATCH reads the current ingress config (GET), updates customDomains to SniEnabled with the managed cert ID, and writes it back. This bypasses the provider's ID-format validation entirely. Execution order: 1. null_resource.hostname_registration - az hostname add (Disabled) 2. azurerm_...managed_certificate - cert provisioned 3. null_resource.cert_binding - az rest PATCH to SniEnabled Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 88380ab commit e72c2e0

1 file changed

Lines changed: 32 additions & 6 deletions

File tree

sharing-server/infra/main.tf

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -221,12 +221,38 @@ resource "azurerm_container_app_environment_managed_certificate" "this" {
221221
}
222222
}
223223

224-
resource "azurerm_container_app_custom_domain" "this" {
225-
count = var.custom_domain != "" ? 1 : 0
226-
name = var.custom_domain
227-
container_app_id = azurerm_container_app.this.id
228-
container_app_environment_certificate_id = azurerm_container_app_environment_managed_certificate.this[0].id
229-
certificate_binding_type = "SniEnabled"
224+
# azurerm_container_app_custom_domain cannot be used here because it only accepts
225+
# staticCertificate IDs (.../certificates/...) and rejects managedCertificate IDs
226+
# (.../managedCertificates/...) at plan time. Instead, bind the cert by PATCHing
227+
# the container app's ingress directly via az rest, which accepts the raw ARM ID.
228+
resource "null_resource" "cert_binding" {
229+
count = var.custom_domain != "" ? 1 : 0
230+
231+
triggers = {
232+
cert_id = azurerm_container_app_environment_managed_certificate.this[0].id
233+
app_id = azurerm_container_app.this.id
234+
hostname = var.custom_domain
235+
}
236+
237+
provisioner "local-exec" {
238+
environment = {
239+
CERT_ID = azurerm_container_app_environment_managed_certificate.this[0].id
240+
APP_NAME = azurerm_container_app.this.name
241+
APP_RG = var.resource_group_name
242+
HOSTNAME = var.custom_domain
243+
APP_ID = azurerm_container_app.this.id
244+
}
245+
command = <<-EOT
246+
INGRESS=$(az containerapp show --name "$APP_NAME" --resource-group "$APP_RG" --query "properties.configuration.ingress" -o json)
247+
PATCH=$(jq -n --argjson ing "$INGRESS" --arg h "$HOSTNAME" --arg c "$CERT_ID" \
248+
'$ing | .customDomains = [{"name": $h, "bindingType": "SniEnabled", "certificateId": $c}] | {properties: {configuration: {ingress: .}}}')
249+
az rest --method PATCH \
250+
--url "https://management.azure.com${APP_ID}?api-version=2024-03-01" \
251+
--body "$PATCH" \
252+
--output none
253+
echo "Cert $CERT_ID bound to $HOSTNAME (SniEnabled)."
254+
EOT
255+
}
230256

231257
depends_on = [azurerm_container_app_environment_managed_certificate.this]
232258
}

0 commit comments

Comments
 (0)