Introduction
When on-premises web applications are migrated to cloud, the web solutions hosted in IIS are needed to be deployed to Azure App Service instance. There are multiple ways to manage resources in Azure like using Azure portal i.e., GUI, Azure ARM, Azure CLI, Terraform. In this article I will explain how to create & manage with Terraform code, then I will use the basic .NET Core Web API project template & deploy API solution to Web App instance.

Create App Service instance with Terraform :
Terraform is a Infrastructure as Code (IaC) tool that helps to build, change & manage infrastructure. It provides multi cloud support, reusable & easy to use. Infrastructure can be planned & created with running terraform scripts.
When creating a Web App instance, App Service Plan is needed first. It is the computing service container for App Service. It represents the physical sources to host apps, It controls the
Pricing tier
CPU power
Operating System
Size, Scaling
Below TF script automates the App Service Plan creation.
provider "azurerm" {
features {}
}
resource "azurerm_service_plan" "asp" {
name = "${var.app_name}-asp"
location = var.location
resource_group_name = var.resource_group_name
os_type = "Linux"
sku_name = "B1"
}
resource "azurerm_linux_web_app" "webapp" {
name = var.app_name
location = var.location
resource_group_name = var.resource_group_name
service_plan_id = azurerm_service_plan.asp.id
site_config {
application_stack {
dotnet_version = "9.0"
}
}
app_settings = {
"WEBSITES_PORT" = "5000"
}
}For this demo I have chosen Linux OS, Basic SKU, As I am going to deploy .NET 9.0 solution so application stack is dotnet_version 9.0 & app communication is enabled on port 5000. Now next step is to execute this script.
terraform init : Initialize terraform instance in working directory.

terraform validate : Syntax check & validation

terraform plan : Provides a infrastructure preview.

terraform apply : Execute the plan & commissions the infrastructure











Join the conversation! Your thoughts help the community grow.