Skip to content

Latest commit

 

History

History
129 lines (93 loc) · 6.5 KB

File metadata and controls

129 lines (93 loc) · 6.5 KB
title Quickstart: Create and deploy Azure Functions resources from Terraform
description In this quickstart article, you create a function app in a Flex Consumption plan, along with the resource group, storage account, and blob storage container required by the app.
ms.topic quickstart
ms.date 07/22/2025
ms.custom devx-track-terraform
ms.service azure-functions
content_well_notification
AI-contribution
zone_pivot_groups programming-languages-set-functions

Quickstart: Create and deploy Azure Functions resources from Terraform

In this quickstart, you use Terraform to create a function app in a Flex Consumption plan in Azure Functions, along with other required Azure resources. The Flex Consumption plan provides serverless hosting that lets you run your code on demand without explicitly provisioning or managing infrastructure. The function app runs on Linux and is configured to use Azure Blob storage for code deployments.

[!INCLUDE About Terraform]

[!div class="checklist"]

  • Create an Azure resource group with a unique name.
  • Generate a random string of 13 lowercase letters to name resources.
  • Create a storage account in Azure.
  • Create a blob storage container in the storage account.
  • Create a Flex Consumption plan in Azure Functions.
  • Create a function app with a Flex Consumption plan in Azure.
  • Output the names of the resource group, storage account, service plan, function app, and Azure Functions Flex Consumption plan.

Prerequisites

Implement the Terraform code

The sample code for this article is located in the Azure Terraform GitHub repo. You can view the log file containing the test results from current and previous versions of Terraform. See more articles and sample code showing how to use Terraform to manage Azure resources.

  1. Create a directory in which to test and run the sample Terraform code, and make it the current directory.

  2. Create a file named main.tf, and insert the following code: :::code language="Terraform" source="~/terraform_samples/quickstart/101-azure-functions/main.tf":::

  3. Create a file named outputs.tf, and insert the following code: :::code language="Terraform" source="~/terraform_samples/quickstart/101-azure-functions/outputs.tf":::

  4. Create a file named providers.tf, and insert the following code: :::code language="Terraform" source="~/terraform_samples/quickstart/101-azure-functions/providers.tf":::

  5. Create a file named variables.tf, and insert the following code: :::code language="Terraform" source="~/terraform_samples/quickstart/101-azure-functions/variables.tf":::

  6. Use this Azure CLI command to set the ARM_SUBSCRIPTION_ID environment variable to the ID of your current subscription:

    export ARM_SUBSCRIPTION_ID=$(az account show --query "id" --output tsv)
    

    You must have this variable set for Terraform to be able to authenticate to your Azure subscription.

Initialize Terraform

[!INCLUDE terraform-init.md]

Create a Terraform execution plan

Run terraform plan to create an execution plan.

::: zone pivot="programming-language-csharp"

terraform plan -out main.tfplan -var="runtime_name=dotnet-isolated" -var="runtime_version=8"

::: zone-end
::: zone pivot="programming-language-powershell"

terraform plan -out main.tfplan -var="runtime_name=powershell" -var="runtime_version=7.4"

::: zone-end ::: zone pivot="programming-language-python"

terraform plan -out main.tfplan -var="runtime_name=python" -var="runtime_version=3.12"

::: zone-end ::: zone pivot="programming-language-java"

terraform plan -out main.tfplan -var="runtime_name=java" -var="runtime_version=21"

::: zone-end
::: zone pivot="programming-language-javascript,programming-language-typescript"

terraform plan -out main.tfplan -var="runtime_name=node" -var="runtime_version=20"

::: zone-end

Make sure that runtime_version matches the language stack version you verified locally. Select your preferred language stack at the top of the article.

[!INCLUDE terraform-plan-notes.md]

Apply a Terraform execution plan

[!INCLUDE terraform-apply-plan.md]

Verify the results

The outputs.tf file returns these values for your new function app:

Value Description
resource_group_name The name of the resource group you created.
sa_name The name of the Azure storage account required by the Functions host.
asp_name The name of the Flex Consumption plan that hosts your new app.
fa_name The name of your new function app.
fa_url The URL of your new function app endpoint.

Open a browser and browse to the URL location in fa_url. You can also use the terraform output command to review these values at a later time.

:::image type="content" source="media/functions-create-first-function-terraform/function-app-terraform.png" alt-text="Screenshot of Azure Functions app 'Welcome page'." border="false":::

Clean up resources

[!INCLUDE terraform-plan-destroy.md]

Troubleshoot Terraform on Azure

Troubleshoot common problems when using Terraform on Azure.

Next steps

[!INCLUDE functions-quickstarts-infra-next-steps]