Custom domain for Linux webapp deployment slot

Trying to map a custom domain to a Linux webapp deployment slot using

  • azurerm_app_service_slot_custom_hostname_binding

Production slot custom domains mapped ok, but trying to get custom subdomains mapped to the slot and getting the following error:

resource "azurerm_app_service_slot_custom_hostname_binding" "xxx_staging" {
  count               = terraform.workspace == "prod" ? 1 : 0
  app_service_slot_id = azurerm_linux_web_app_slot.staging[0].id
  hostname            = "prod.${local.xxx_apex_domain}"
  depends_on          = [azurerm_dns_txt_record.appservice_xxx_domain_verification_id]

  lifecycle {
    ignore_changes = [ssl_state, thumbprint]
  }
}
``
 
> Error: creating App Service Slot Custom Hostname Binding: (Host Name Binding Name "prod.xxx.xxx.xxx.xx" / Slot Name "staging" / Site Name "xxxxx" / Resource Group "xxxx"): web.AppsClient#CreateOrUpdateHostNameBindingSlot: Failure sending request: StatusCode=409 -- Original Error: autorest/azure: Service returned an error. Status=nil nil

Hello,
I’m on the same case and I’m looking for a solution for this issue.
What I understood I can’t create at the same time more of one custom hostname binding on the slots. So to fix that I disabled the parrallelism on terraform apply (TF_CLI_ARGS_apply=“-parallelism=1” )

resource "azurerm_app_service_slot_custom_hostname_binding" "custom_domain_bindings2" {
  for_each            = {for hostnameval in local.slots_custom_hostnames_list: "${hostnameval.key}" => hostnameval}        
  hostname            = each.value.host
  app_service_slot_id = azurerm_app_service_slot.my_app_service_slots[each.value.slot].id
  thumbprint          = data.azurerm_key_vault_certificate.my_certificate.thumbprint
  ssl_state           = "SniEnabled"
}
> Error: creating App Service Slot Custom Hostname Binding: (Host Name Binding Name "xxxxxxxx.xxxx.xxxxxx.com" / Slot Name "dit" / Site Name "xxxxxxxxxxxxxxx" / Resource Group "xxxxxxxxxxxxx"): web.AppsClient#CreateOrUpdateHostNameBindingSlot: Failure sending request: StatusCode=409 -- Original Error: autorest/azure: Service returned an error. Status=<nil> <nil>