How to Create App Service in Azure using Terraform
Last Updated :
26 Apr, 2024
Azure App Service is a service that provides a managed platform for deploying applications in the Azure cloud. It supports multiple language applications. App service allows building, deploying and scaling of applications in Azure. Setting up an app service is a complicated process. let's see how we can set up an app service in Azure using Terraform.
Understanding Of Primary Terminologies
The following are the primary components of Azure App Service related to Terraform:
- Terraform: It is Infrastructure as an infrastructure-as-a-service tool that allows the deployment of resources to multiple cloud providers through code.
- Azure App Service: App Service is a managed platform as a service for building, deploying and scaling applications in Azure.
- IaaC: Infrastructure as a Code allows to representation of cloud infrastructure in the form of code.
Setup Azure App Service Using Terraform: A Step-By-Step Guide
Step 1: Set Up Terraform
- Download the Terraform zip from the installation page of the Terraform website.
- Extract and paste the terraform folder to the required location and add the path to runnable in environment variables.
- On MacOS download Terraform using brew command.
Step 2: Set Up Azure CLI
- Download the Azure CLI setup from the official website.
- Run the installer and follow the steps to install.
.png)
- For MacOS install CLI using below brew command.
brew update && brew install azure-cli
Step 3: Configure Azure CLI
- Open terminal and run below command.
az login
- A browser window will open for login. Login with your azure credentials. Once it is done you will see output as below.
.jpg)
Step 4: Create Terraform Code
- Goto your project folder and create main.tf file.
- Add terraform block to code with azure as required provider with latest version. You can find the latest version at hashicorp registry.
- Terraform block should look like below. You can add required version to avoid invalidation.
terraform {
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "~>3.0"
}
}
}
- Now add provider as azurerm like below. Specify other details as required.
provider "azurerm" {
features {}
}
- Add configuration for Azure App Service. First we will create app service plan described as below.
resource "azurerm_app_service_plan" "deepcodr-firstplan" {
name = "firstapp-plan"
resource_group_name = "DeepsLab"
location = "eastus"
sku {
tier = "Standard"
size = "S1"
}
}
- We have specified name for App service plan. We have specified the location and resource group where plan should be created.
- Now lets add configuration for app service. We will also specify app service plan id which was described earlier.
resource "azurerm_app_service" "deepcodr-firstapp" {
name = "deepcodr-firstapp"
resource_group_name = "DeepsLab"
location = "eastus"
app_service_plan_id = azurerm_app_service_plan.deepcodr-firstplan.id
site_config {
python_version = "3.4"
scm_type = "LocalGit"
}
}
- The complete code will look like below.
terraform {
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "~>3.0"
}
}
}
provider "azurerm" {
features {}
}
resource "azurerm_app_service_plan" "deepcodr-firstplan" {
name = "firstapp-plan"
resource_group_name = "DeepsLab"
location = "eastus"
sku {
tier = "Standard"
size = "S1"
}
}
resource "azurerm_app_service" "deepcodr-firstapp" {
name = "deepcodr-firstapp"
resource_group_name = "DeepsLab"
location = "eastus"
app_service_plan_id = azurerm_app_service_plan.deepcodr-firstplan.id
site_config {
python_version = "3.4"
scm_type = "LocalGit"
}
}
- Site config has been added to describe application language and source control type.
Step 5: Apply The Terraform Code
- Once the code is ready you can apply it.
- First init the terraform by running below command in project folder where main.tf is present.
terraform init
.png)
- After successful output of terraform apply the changes using below command.
terrraform apply
- After verifying type "yes" to confirm and apply.
- Terraform will start creating service plan and app service.

- You can also verify deployment by visiting App Service page of Azure.
.png)
Conclusion
We have successfully created an Azure App service with the help of terraform in this article. the configuration described can be further modified to make changes to site configuration and application runtime. This is how terraform allows reusable and modifiable configuration of infrastructure.
What does a basic Terraform configuration for Azure App Service look like?
A basic Terraform configuration for Azure App Service includes a resource block for defining the Azure App Service itself, specifying properties such as name, location, resource group, and app service plan.
How do I manage configuration settings for my App Service with Terraform?
Terraform allows you to manage configuration settings for your App Service using Azure App Service Configuration resources. You can define settings such as connection strings, environment variables, and app settings directly in your Terraform configuration.
Can I deploy my application code using Terraform?
While Terraform is primarily focused on provisioning infrastructure, you can use additional tools or scripts (such as Azure DevOps pipelines or custom scripts) to automate the deployment of your application code alongside Terraform.
Is there a way to destroy the Azure App Service provisioned with Terraform?
Yes, you can destroy resources provisioned with Terraform using the terraform destroy
command. This command will remove all resources defined in your Terraform configuration from your Azure subscription, so use it with caution.
How do I apply changes to my Azure App Service using Terraform?
After making changes to your Terraform configuration files, you can apply those changes by running the terraform apply
command. Terraform will compare the desired state defined in your configuration with the current state in Azure and make the necessary changes to bring the infrastructure into the desired state.
Similar Reads
How to Create Vnet in Azure using Terraform ?
Azure Vnet also called Azure Virtual Network is a network that provides various network-related services in Azure. It connects groups of resources and isolates them from outside access in azure cloud. In this article let's see how we can set up Azure Virtual Network using Terraform. Understanding Of
4 min read
How To Create Azure Storage Account Using Terraform ?
Cloud development has drastically altered the previously known reality of data storage and access, presently providing organizations of all sizes with scalable and cost-effective solutions. Microsoft Azure, one of the cloud computing platform's leading services, provides data storage, which is Azure
11 min read
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
5 min read
How To Create AKS Cluster In Azure Using Terraform ?
Azure AKS also called as Azure Kubernetes Service is service that provides Kubernetes implementation in the Azure cloud. Azure Kubernetes service is a managed service that allows deployment of containerized applications in azure cloud. Setting up a Kubernetes cluster in azure is tedious task so lets
4 min read
How to create Azure Alerts using Terraform
Azure Monitoring helps you monitor the data in your Azure cloud environment. If you set alerts, it will help you proactively respond to any issue that arises within their Azure resources. Azure Monitoring data platform is made up of Logs and metrics. Each feature of Azure Monitoring collects various
4 min read
How To Create Azure Resource Group Using Terraform ?
As more organizations adopt multi-cloud strategies and deploy applications in diverse regions and instances, managing this stack has grown much more intricate. By way of solving problems manually, the provisioning process might take a lot of time, may be incorrect sometimes, or pave the way to incon
11 min read
How to Create Windows VM in Azure Using Terraform
In this article, we will cover the whole process of creating Windows VM in Azure using Terraform. When you have to create multiple VMs, perhaps even identical ones, or machines with nearly identical configurations, it can be repetitive and time-consuming to go through the manual setup process each t
10 min read
How To Create AWS IAM Roles Using Terraform?
Terraform is an IAAC tool which is used provision infrastructure . Here in this guide i will first discuss what is terraform . Then i will discuss what is IAM Role and in which scenarios we should use IAM Role . Then i will walk you through the different steps to create an IAM Role for an EC2 servic
5 min read
How to Create Multiple VM in Azure using Terraform Github
Cloud administrations have become progressively famous as organizations and designers look for adaptable and productive answers for their framework needs. Microsoft Azure, one of the main cloud platforms also one of them which offers a robust platform for sending and managing virtual machines (VMs).
7 min read
How To Create AWS S3 Bucker Using Terraform ?
S3 stands for Simple Storage Service. S3 buckets are cloud storage services by Amazon Web Service. It is used to store objects, It consists of data in any format like documents, images, videos, and application code. These are highly scalable. Prerequisite: AWS AccountTerraform InstallationAWS CLISte
3 min read