Open In App

How to Create Azure Function App using Terraform ?

Azure function app is a serverless implementation that provides execution of code without worrying about underlying infrastructure in Azure. It allows to writing of code in small functions called Azure functions which can be triggered using events in the Azure cloud. In this article let’s see how we can create a Azure function app using Terraform.

Understanding Of Primary Terminologies

The following are the primary components of Azure Vnet related to Terraform:



Setup Azure Function App Using Terraform: A Step-By-Step Guide

Step 1: Set Up Terraform

Step 2: Set Up Azure CLI

brew update && brew install azure-cli

Step 3: Configure Azure CLI

az login



Step 4: Create Terraform Code

terraform {
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "~>3.0"
}
}
}
provider "azurerm" {
features {}
}
resource "azurerm_storage_account" "deepslabteststorageacc" {
name = "deepslabteststorageacc"
resource_group_name = "DeepsLab"
location = "eastus"
account_tier = "Standard"
account_replication_type = "LRS"
}
resource "azurerm_service_plan" "deepslabserviceplan" {
name = "deepslabserviceplan"
resource_group_name = "DeepsLab"
location = "eastus"
os_type = "Linux"
sku_name = "Y1"
}
resource "azurerm_linux_function_app" "deepslabtestfunctionapp" {
name = "deepslabtestfunctionapp"
resource_group_name = "DeepsLab"
location = "eastus"
storage_account_name = azurerm_storage_account.deepslabteststorageacc.name
storage_account_access_key = azurerm_storage_account.deepslabteststorageacc.primary_access_key
service_plan_id = azurerm_service_plan.deepslabserviceplan.id
depends_on = [ azurerm_service_plan.deepslabserviceplan , azurerm_storage_account.deepslabteststorageacc ]
site_config {}
}
terraform {
required_providers {
azurerm={
source = "hashicorp/azurerm"
version = "~>3.0"
}
}
}

provider "azurerm" {
features {}
}

resource "azurerm_storage_account" "deepslabteststorageacc" {
name = "deepslabteststorageacc"
resource_group_name = "DeepsLab"
location = "eastus"
account_tier = "Standard"
account_replication_type = "LRS"
}

resource "azurerm_service_plan" "deepslabserviceplan" {
name = "deepslabserviceplan"
resource_group_name = "DeepsLab"
location = "eastus"
os_type = "Linux"
sku_name = "Y1"
}

resource "azurerm_linux_function_app" "deepslabtestfunctionapp" {
name = "deepslabtestfunctionapp"
resource_group_name = "DeepsLab"
location = "eastus"
storage_account_name = azurerm_storage_account.deepslabteststorageacc.name
storage_account_access_key = azurerm_storage_account.deepslabteststorageacc.primary_access_key
service_plan_id = azurerm_service_plan.deepslabserviceplan.id
depends_on = [ azurerm_service_plan.deepslabserviceplan , azurerm_storage_account.deepslabteststorageacc ]
site_config {}
}

Step 5: Apply The Terraform Code

terraform init

terrraform apply

Conclusion

We have successfully created Azure Function app with the help of terraform in this article. the configuration described can be further modified to make changes to OS type and function runtime in azure. This is how terraform allows reusable and modifiable configuration of infrastructure.

how to create azure function app using terraform – FAQ’s

Q. Can Terraform automatically manage the lifecycle of my Azure Function App?

Yes, Terraform can manage the lifecycle of your Azure Function App, including provisioning, updating, and destroying resources. This means you can easily make changes to your Function App configuration and apply them with Terraform, ensuring consistency and reliability.

Q. Can I manage multiple Azure Function Apps with Terraform?

Yes, Terraform supports managing multiple Azure Function Apps within the same configuration file. You can define multiple function app resources with different configurations, and Terraform will manage them accordingly.

Q. Can I customize my Azure Function App’s configuration using Terraform?

Yes, Terraform allows you to define various parameters such as runtime, trigger type, storage settings, and scaling options for your Function App, giving you full control over its configuration.

Q. What advantages does Terraform offer for managing Azure Function Apps?

Terraform enables infrastructure as code practices, ensuring consistent deployment and management of Function Apps. It simplifies provisioning, updates, and scaling, enhancing efficiency and reliability.

Q. Does Terraform support rollback and versioning for Function App deployments?

Terraform maintains state files that track infrastructure changes, allowing for easy rollback to previous versions if needed. Additionally, version control systems like Git can be used to manage Terraform configurations for versioning.


Article Tags :