Muhammad Shafiq
Muhammad Shafiq

Reputation: 167

Issue in deploying azure function through terraform with app settings

I am Following this docs page to deploy azure function with app settings https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/function_app

My terraform file looks like :

terraform {
  required_providers {
    azurerm = {
      source  = "hashicorp/azurerm"
      version = "3.10.0"
    }
  }
}

provider "azurerm" {
}
resource "azurerm_resource_group" "example" {
  name     = "azure-functions-test-rg"
  location = "West Europe"
}

resource "azurerm_storage_account" "example" {
  name                     = "funcdemo123shafiq"
  resource_group_name      = azurerm_resource_group.example.name
  location                 = azurerm_resource_group.example.location
  account_tier             = "Standard"
  account_replication_type = "LRS"
}

resource "azurerm_app_service_plan" "example" {
  name                = "azure-functions-test-service-plan"
  location            = azurerm_resource_group.example.location
  resource_group_name = azurerm_resource_group.example.name

  sku {
    tier = "Standard"
    size = "S1"
  }
}

resource "azurerm_function_app" "example" {
  name                       = "test-azure-shafiq123"
  location                   = azurerm_resource_group.example.location
  resource_group_name        = azurerm_resource_group.example.name
  app_service_plan_id        = azurerm_app_service_plan.example.id
  storage_account_name       = azurerm_storage_account.example.name
  storage_account_access_key = azurerm_storage_account.example.primary_access_key
  os_type                    = "linux"
  version                    = "~4"

  app_settings {
    FUNCTIONS_WORKER_RUNTIME = "python"
    TESTING_KEY              = "TESTING_VALUE"
  }

  site_config {
    linux_fx_version = "python|3.9"
  }
}

When try to deploy this through terraform apply command , I am getting this error.

│ Error: Unsupported block type
│
│   on main.tf line 46, in resource "azurerm_function_app" "example":
│   46:   app_settings {
│
│ Blocks of type "app_settings" are not expected here. Did you mean to define argument "app_settings"? If so, use the equals sign to assign it a value.

Upvotes: 6

Views: 5246

Answers (1)

RahulKumarShaw
RahulKumarShaw

Reputation: 4612

app_setting is supported on specific version of Terraform AzureRM provider. There is bug fixed availble for those version. I have used 3.3.0 provider version and it is working for me as expected and also you can't configure the value of site_config.Its value will be decide automatically based on the result of applying this configuration, same you can check in the updated document of Terraform

main.tf

 terraform {
      required_providers {
        azurerm = {
          source  = "hashicorp/azurerm"
          version = "3.3.0"
        }
      }
    }
    
    provider "azurerm" {
        features{}
    }
    data "azurerm_resource_group" "example" {
      name     = "v-rXXXXXree"
      #location = "West Europe"
    }
    
    resource "azurerm_storage_account" "example" {
      name                     = "funcdemo123shafiq4535"
      resource_group_name      = data.azurerm_resource_group.example.name
      location                 = data.azurerm_resource_group.example.location
      account_tier             = "Standard"
      account_replication_type = "LRS"
    }
    
    resource "azurerm_service_plan" "example" {
      name                = "azure-functions-test-service-plan1"
      location            = data.azurerm_resource_group.example.location
      resource_group_name = data.azurerm_resource_group.example.name
      os_type             = "Linux"
      sku_name            = "Y1"
    }
    
    resource "azurerm_linux_function_app" "example" {
      name                       = "test-azure-shafi4353"
      location                   = data.azurerm_resource_group.example.location
      resource_group_name        = data.azurerm_resource_group.example.name
      service_plan_id            =  azurerm_service_plan.example.id
      storage_account_name       = azurerm_storage_account.example.name
      storage_account_access_key = azurerm_storage_account.example.primary_access_key
      #os_type                    = "linux"
      #version                    = "~3"
    
      app_settings={
        FUNCTIONS_WORKER_RUNTIME = "python"
        TESTING_KEY              = "TESTING_VALUE"
      }
    
      site_config {
        #linux_fx_version = "python|3.9"
      }
    
    }

enter image description here

enter image description here

Upvotes: 6

Related Questions