Billy L.
Billy L.

Reputation: 41

Getting a 503 when creating a function app slot in terraform

Here are the infrastructure setup. I have a virtual network with a subnet and some network security rule applied to it. In the subnet I deployed a App Service Environment v3, and an I1v2 App service plan. I then try to create a function app using the following terraform

resource "azurerm_resource_group" "iac_poc_rg" {
    name = "iac_poc_rg"
    location = "eastus"
}

data "azurerm_service_plan" "asp" {
  name = "test-asp"
  resource_group_name = "test-asp-rg"
}

resource "azurerm_storage_account" "poc_sa" {
  name = "pocsa"
  resource_group_name      = azurerm_resource_group.iac_poc_rg.name
  location                 = azurerm_resource_group.iac_poc_rg.location
  account_tier             = "Standard"
  account_replication_type = "LRS"
}

resource "azurerm_windows_function_app" "poc_fa" {
  name = "poc-fa"
  resource_group_name      = azurerm_resource_group.iac_poc_rg.name
  location                 = azurerm_resource_group.iac_poc_rg.location
  storage_account_name = azurerm_storage_account.poc_sa.name
  storage_account_access_key = azurerm_storage_account.poc_sa.primary_access_key
  service_plan_id = data.azurerm_service_plan.asp.id

  site_config {}
}

resource "azurerm_windows_function_app_slot" "poc_fas" {
  name                 = "poc-fa-slot"
  function_app_id      = azurerm_windows_function_app.poc_fa.id
  storage_account_name = azurerm_storage_account.poc_sa.name
  storage_account_access_key = azurerm_storage_account.poc_sa.primary_access_key

  site_config {}
}

When I do a terraform apply, it stuck on creating the function app slot. After 10 minutes, it timed out. Here are the first error in the log file:

[DEBUG] provider.terraform-provider-azurerm_v3.12.0_x5.exe: AzureRM Response for https://management.azure.com/subscriptions/<my-subscription>/resourceGroups/<resource group name>/providers/Microsoft.Web/sites/<Function app name>/slots/<slot name>/config/backup/list?api-version=2021-02-01: 
HTTP/2.0 404 Not Found

After that it throws a 503 with this message

Backup configuration not found for site '<my function app name>' with slot '<my slot name>'

Here is the call

provider.terraform-provider-azurerm_v3.12.0_x5.exe: AzureRM Response for https://management.azure.com/subscriptions/<my-subscription>/resourceGroups/<resource group name>/providers/Microsoft.Web/sites/<Function app name>/slots/<slot name>/config/logs?api-version=2021-02-01: 
HTTP/2.0 503 Service Unavailable

All the resources are created correctly in the portal, including the function app slot. When I try to run terraform plan again. the function app slot stuck on refreshing state, and the log consists the same error as above.

I am not sure what I did wrong. Could it be my network security rules? Is there something I need to set for my app service environment v3?

I am using Terraform version 1.1.7 and Azurerm provider 3.12.0.

Thanks in advance

Upvotes: 0

Views: 646

Answers (1)

AjayKumarGhose
AjayKumarGhose

Reputation: 4893

We have tried same in our environment with new app service plan creating in the same resource group and location and it works fine at our end.

Please check the below workaround we followed :

  • Here is our modified code:-

main.tf

provider "azurerm" {
  features {}
}

resource "azurerm_resource_group" "iac_poc_rg" {
    name = "iac_poc_rg"
    location = "eastus"
}

resource "azurerm_storage_account" "poc_sa" {
  name = "pocsomeone"
  resource_group_name      = azurerm_resource_group.iac_poc_rg.name
  location                 = azurerm_resource_group.iac_poc_rg.location
  account_tier             = "Standard"
  account_replication_type = "LRS"
}

resource "azurerm_service_plan" "example" {
  name                = "example-app-service-plan"
  resource_group_name = azurerm_resource_group.iac_poc_rg.name
  location            = azurerm_resource_group.iac_poc_rg.location
  os_type             = "Windows"
  sku_name            = "Y1"
}

resource "azurerm_windows_function_app" "poc_fa" {
  name = "pocajte"
  resource_group_name      = azurerm_resource_group.iac_poc_rg.name
  location                 = azurerm_resource_group.iac_poc_rg.location
  storage_account_name = azurerm_storage_account.poc_sa.name
  storage_account_access_key = azurerm_storage_account.poc_sa.primary_access_key
  service_plan_id = azurerm_service_plan.example.id

  site_config {}
}

resource "azurerm_windows_function_app_slot" "poc_fas" {
  name                 = "my-fa-slot"
  function_app_id      = azurerm_windows_function_app.poc_fa.id
  storage_account_name = azurerm_storage_account.poc_sa.name
  storage_account_access_key = azurerm_storage_account.poc_sa.primary_access_key

  site_config {}
}

We have the following Version in our environment:- enter image description here enter image description here

OUTPUT RESULT OF PLAN AND APPLY:- enter image description here

enter image description here enter image description here

Created Successfully:-

enter image description here

NOTE:- *As we have not tested with existing app service plan Make sure that the App service plan you are using is in the same region and resource group. For details please check this

MICROSOFT DOCUMENTATION|Move an app to another App Service plan ,it may be the caused .

For more information please refer this Blog By HashiCorp Terraform|azurerm_function_app_slot.

Upvotes: 1

Related Questions