Errors creating traffic manager and app services - App Service needs to be globally unique

I am having issues setting up resources with Terraform on my azure account.
There are 2 scenarios.

Common setup for both scenarios:
I am using
Terraform v1.1.7
on windows_386
provider Terraform Registry v2.99.0

terraform {
  required_version = ">=0.12"
  
  required_providers {
    azurerm = {
      source = "hashicorp/azurerm"
      version = "~>2.0"
    }
  }
}
provider "azurerm" {
  features {}
}
data "azurerm_client_config" "current" {}

(an identical version of app service is created for wus)

resource "azurerm_app_service" "web-site-abc-eus" {
  name                = "web-abc-eus"
  location            = azurerm_resource_group.rg-abc-eus.location
  resource_group_name = azurerm_resource_group.rg-abc-eus.name
  app_service_plan_id = azurerm_app_service_plan.serverfarms-sfarm-abc-eus.id
  
  site_config {
    dotnet_framework_version = "v4.0"
    scm_type                 = "None"
    always_on                = true
    use_32_bit_worker_process = true
    php_version              = "5.6"
    default_documents        = [
      "Default.htm",
      "Default.html",
      "Default.asp",
      "index.htm",
      "index.html",
      "iisstart.htm",
      "default.aspx",
      "index.php",
      "hostingstart.html"
    ]
  }
  client_affinity_enabled    = true
}

I know these sound like an issue already fixed, but I am still having problems:
https://github.com/hashicorp/terraform-provider-azurerm/issues/3003

scenario 1 uses “standard” tier:

resource "azurerm_app_service_plan" "serverfarms-abc-eus" {
  name                = "sfarm-abc-eus"
  location            = azurerm_resource_group.rg-abc-eus.location
  resource_group_name = azurerm_resource_group.rg-abc-eus.name
  kind                = "app"
  is_xenon            = false
  maximum_elastic_worker_count = var.maxElasticWorkerCount
  sku {
    tier = "Standard"
    size = "S1"
    capacity = 1
  }
}
resource "azurerm_app_service_plan" "serverfarms-abc-wus" {
  name                = "sfarm-abc-wus"
  location            = azurerm_resource_group.rg-abc-wus.location
  resource_group_name = azurerm_resource_group.rg-abc-wus.name
  kind                = "app"
  is_xenon            = false
  
  maximum_elastic_worker_count = var.maxElasticWorkerCount
  sku {
    tier = "Standard"
    size = "S1"
    capacity = 1
  }
}

Errors:

│ Error: creating Traffic Manager Profile (Subscription: “”
│ Resource Group Name: “rg-abc-eus”
│ Profile Name: “trf-abc-global”): profiles.ProfilesClient#CreateOrUpdate: Failure sending request: StatusCode=409 – Original Error: autorest/azure: Service returned an error. Status=
│
│ with azurerm_traffic_manager_profile.trf-abc,
│ on trafficManager.tf line 1, in resource “azurerm_traffic_manager_profile” “trf-abc”:
│ 1: resource “azurerm_traffic_manager_profile” “trf-abc” {
│
â•”
╷
│ Error: The name “web-abc-eus” used for the App Service needs to be globally unique and isn’t available: Hostname ‘web-abc-eus’ already exists. Please select a different name.
│
│ with azurerm_app_service.web-site-abc-eus,
│ on web.tf line 2, in resource “azurerm_app_service” “web-site-abc-eus”:
│ 2: resource “azurerm_app_service” “web-site-abc-eus” {
│
â•”
╷
│ Error: The name “web-abc-wus” used for the App Service needs to be globally unique and isn’t available: Hostname ‘web-abc-wus’ already exists. Please select a different name.
│
│ with azurerm_app_service.web-site-abc-wus,
│ on web.tf line 31, in resource “azurerm_app_service” “web-site-abc-wus”:
│ 31: resource “azurerm_app_service” “web-site-abc-wus” {

scenario 2, uses isolated tier:
from what I read, I got the impression that maybe the service plan has to be “isolated” to not have the “already exist” error. Recieved new error instead.

resource "azurerm_app_service_plan" "serverfarms-abc-eus" {
  name                = "sfarm-abc-eus"
  location            = azurerm_resource_group.rg-abc-eus.location
  resource_group_name = azurerm_resource_group.rg-abc-eus.name
  kind                = "app"
  is_xenon            = false
  maximum_elastic_worker_count = var.maxElasticWorkerCount
  sku {
    tier = "Isolated"
    size = "I1"
    capacity = 1
  }
}
resource "azurerm_app_service_plan" "serverfarms-abc-wus" {
  name                = "sfarm-abc-wus"
  location            = azurerm_resource_group.rg-abc-wus.location
  resource_group_name = azurerm_resource_group.rg-abc-wus.name
  kind                = "app"
  is_xenon            = false
  
  maximum_elastic_worker_count = var.maxElasticWorkerCount
  sku {
    tier = "Isolated"
    size = "I1"
    capacity = 1
  }
}

Errors:
│ Error: creating/updating App Service Plan: (Serverfarm Name “sfarm-abc-eus” / Resource Group “rg-abc-eus”): web.AppServicePlansClient#CreateOrUpdate: Failure sending request: StatusCode=0 – Original Error: autorest/azure: Service returned an error. Status=
│
│ with azurerm_app_service_plan.serverfarms-sfarm-abc-eus,
│ on sfarm.tf line 1, in resource “azurerm_app_service_plan” “serverfarms-sfarm-abc-eus”:
│ 1: resource “azurerm_app_service_plan” “serverfarms-sfarm-abc-eus” {
│
â•”
╷
│ Error: creating/updating App Service Plan: (Serverfarm Name “sfarm-abc-wus” / Resource Group “rg-abc-wus”): web.AppServicePlansClient#CreateOrUpdate: Failure sending request: StatusCode=0 – Original Error: autorest/azure: Service returned an error. Status=
│
│ with azurerm_app_service_plan.serverfarms-sfarm-abc-wus,
│ on sfarm.tf line 16, in resource “azurerm_app_service_plan” “serverfarms-sfarm-abc-wus”:
│ 16: resource “azurerm_app_service_plan” “serverfarms-sfarm-abc-wus” {
│
â•”
╷
│ Error: creating Traffic Manager Profile (Subscription: “”
│ Resource Group Name: “rg-abc-eus”
│ Profile Name: “trf-abc-global”): profiles.ProfilesClient#CreateOrUpdate: Failure sending request: StatusCode=409 – Original Error: autorest/azure: Service returned an error. Status=
│
│ with azurerm_traffic_manager_profile.trf-abc,
│ on trafficManager.tf line 1, in resource “azurerm_traffic_manager_profile” “trf-abc”:
│ 1: resource “azurerm_traffic_manager_profile” "trf-abc {

Problem was, in fact, found to the be an existing app service with the same name.

1 Like