'Terraform Azure and custom domains for linux webapp deployment slot

Trying to get TF to map custom domains to my deployment slot and not working.

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]
  }
}

Throwing the following error:

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



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source