App Service created in App service environment Version 3 fails

294 Views Asked by At

I have created a new App Service Environment Version 3 and a App service using Terraform:

resource "azurerm_app_service_environment_v3" "example" {
  name                = "example-asev3"
  resource_group_name = azurerm_resource_group.example.name
  subnet_id           = azurerm_subnet.example.id

  internal_load_balancing_mode = "Web, Publishing"

  cluster_setting {
    name  = "DisableTls1.0"
    value = "1"
  }

  cluster_setting {
    name  = "InternalEncryption"
    value = "true"
  }

  cluster_setting {
    name  = "FrontEndSSLCipherSuiteOrder"
    value = "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256"
  }

  tags = {
    env         = "production"
    terraformed = "true"
  }
}

resource "azurerm_service_plan" "example" {
  name                       = "example"
  resource_group_name        = azurerm_resource_group.example.name
  location                   = azurerm_resource_group.example.location
  os_type                    = "Linux"
  sku_name                   = "I1v2"
  app_service_environment_id = azurerm_app_service_environment_v3.example.id
}
resource "azurerm_application_insights" "example" {
  name                = "tf-test-appinsights"
  location            = azurerm_resource_group.example.location
  resource_group_name = azurerm_resource_group.example.name
  application_type    = "web"
}
resource "azurerm_app_service" "example" {
  name                = "example-app-service"
  location            = azurerm_resource_group.example.location
  resource_group_name = azurerm_resource_group.example.name
  app_service_plan_id = azurerm_app_service_plan.example.id
   site_config {
    linux_fx_version = "DOTNETCORE:6.0"
    always_on = true
  }
}

I have created a sample visual studio app using visual studio and directly deployed to it. It is throwing Error when I try to access the app service portal.

enter image description here

When I access the application from local host after deploying, its working fine. Not sure what configuration is wrong in App Service.

1

There are 1 best solutions below

1
Vince On

Did you create the private dns zones and its records?

resource "azurerm_private_dns_zone" "app_service_plan_isolated_private_dns_zone" {
  name                = "${azurerm_app_service_environment_v3.app_service_plan_isolated.name}.appserviceenvironment.net"
  resource_group_name = data.azurerm_resource_group.rg.name
}

resource "azurerm_private_dns_zone_virtual_network_link" "app_service_plan_isolated_vnet_link" {
  name                  = "${azurerm_app_service_environment_v3.app_service_plan_isolated.name}-vnetLink"
  resource_group_name   = data.azurerm_resource_group.rg.name
  private_dns_zone_name = azurerm_private_dns_zone.app_service_plan_isolated_private_dns_zone.id
  #virtual_network_id    = data.azurerm_virtual_network.existing_vnet.id
  virtual_network_id = azurerm_virtual_network.example.id
}

resource "azurerm_private_dns_a_record" "app_service_plan_isolated_private_dns_zone_record" {
  name                = "*"
  zone_name           = azurerm_private_dns_zone.app_service_plan_isolated_private_dns_zone.name
  resource_group_name = data.azurerm_resource_group.rg.name
  ttl                 = 3600
  records             = azurerm_app_service_environment_v3.app_service_plan_isolated.internal_inbound_ip_addresses
}

resource "azurerm_private_dns_a_record" "app_service_plan_isolated_private_dns_zone_record_scm" {
  name                = "*.scm"
  zone_name           = azurerm_private_dns_zone.app_service_plan_isolated_private_dns_zone.name
  resource_group_name = data.azurerm_resource_group.rg.name
  ttl                 = 3600
  records             = azurerm_app_service_environment_v3.app_service_plan_isolated.internal_inbound_ip_addresses
}

resource "azurerm_private_dns_a_record" "app_service_plan_isolated_private_dns_zone_record2" {
  name                = "@"
  zone_name           = azurerm_private_dns_zone.app_service_plan_isolated_private_dns_zone.name
  resource_group_name = data.azurerm_resource_group.rg.name
  ttl                 = 3600
  records             = azurerm_app_service_environment_v3.app_service_plan_isolated.internal_inbound_ip_addresses
}


resource "azurerm_virtual_network" "example" {
  name                = "example-vnet"
  location            = data.azurerm_resource_group.rg.location
  resource_group_name = data.azurerm_resource_group.rg.name
  address_space       = ["10.0.0.0/16"]
}

resource "azurerm_subnet" "example" {
  name                 = "example-subnet"
  resource_group_name  = data.azurerm_resource_group.rg.name
  virtual_network_name = azurerm_virtual_network.example.name
  address_prefixes     = ["10.0.2.0/24"]

  delegation {
    name = "Microsoft.Web.hostingEnvironments"
    service_delegation {
      name    = "Microsoft.Web/hostingEnvironments"
      actions = ["Microsoft.Network/virtualNetworks/subnets/action"]
    }
  }
}