Open In App

How to Create App Service in Azure using Terraform

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:



Setup Azure App Service 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_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"
}
}
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"
}
}

Step 5: Apply The Terraform Code

terraform init

terrraform apply

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.

How to create app service in azure using terraform – FAQ’s

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.


Article Tags :