fbpx

Learn Build5Nines Forum

Find answers, ask questions, and connect with our
global community of IT professionals.

Forums HashiCorp Terraform How do you deploy an Azure Function App using Terraform that’s hosted on Linux?

  • How do you deploy an Azure Function App using Terraform that’s hosted on Linux?

    Posted by Joshua Falken on June 28, 2023 at 1:48 pm

    How do you deploy an Azure Function App using Terraform that’s hosted on a Linux-based App Service Plan?

    Chris Pietschmann replied 3 months, 1 week ago 2 Members · 1 Reply
  • 1 Reply
  • Chris Pietschmann

    Administrator
    June 28, 2023 at 1:50 pm

    First you need to deploy a Linux-based App Service Plan into Azure. This can be done as follows:

    # Create Azure App Service Plan using Consumption pricing
    resource azurerm_app_service_plan "primary" {
      name                = local.app_service_plan_name
      location            = azurerm_resource_group.primary.location
      resource_group_name = azurerm_resource_group.primary.name
      kind                = "Linux"
      reserved            = true
    
      sku {
        tier = "Dynamic"
        size = "Y1"
      }
    }

    Once the Linux-based App Service Plan is deployed, you can then deploy a Linux-based Azure Function App as follows that is hosted using the Linux-based App Service Plan:

    # Create an Azure Function App on Linux
    resource azurerm_function_app "primary" {
      name                       = local.function_app_name
      resource_group_name        = azurerm_resource_group.primary.name
      location                   = azurerm_resource_group.primary.location
    
      app_service_plan_id        = azurerm_app_service_plan.primary.id
      
      storage_account_name       = azurerm_storage_account.primary.name
      storage_account_access_key = azurerm_storage_account.primary.primary_access_key
      
      os_type                    = "linux"
      version                    = "~3"
    
      site_config {
        always_on = true
      }
    }

    For more explanation and expanded Terraform snippets for deploying an Azure Function App on Linux, please reference this link: https://build5nines.com/terraform-deploy-azure-function-app-with-consumption-plan/