Terraform - Provisioning an Azure App Service

April 17, 2021

In my previous post on Getting started with Terraform I covered a very quick, and vague explanation of what Terraform is, and what it does. In this post, I’m going to cover the explanation of what the various syntax looks like; I’m also going to provision some infrastructure in the form of an App Service.

Before we get into the what we’ll need to create an app service, let’s first analyse the config that we used in the previous post:



# Configure the Azure provider
terraform {
  required\_providers {
    azurerm = {
      source = "hashicorp/azurerm"
      version = ">= 2.26"
    }
  }
}

provider "azurerm" {
  features {}
}

resource "azurerm\_resource\_group" "rg" {
  name     = "myTFResourceGroup"
  location = "ukwest"
}

Let’s breakdown exactly what we’re seeing here for the resource:

terraform 2 1

Now that we’ve broken that down, it makes sense that, if we want to deploy an App Service, that we simply need to know what the correct type of the app service is. There’s probably a list of these somewhere.

Let’s have a look at the config for the App Service:



# App Service
resource "azurerm\_app\_service\_plan" "app-service-plan" {
  name                = "pcm-app-service-plan"
  location            = azurerm\_resource\_group.rg.location
  resource\_group\_name = azurerm\_resource\_group.rg.name
  sku {
    tier = "Standard"
    size = "S1"
  }
}
resource "azurerm\_app\_service" "app-service" {
  name                = "pcm-app-service"
  location            = azurerm\_resource\_group.rg.location
  resource\_group\_name = azurerm\_resource\_group.rg.name
  app\_service\_plan\_id = azurerm\_app\_service\_plan.app-service-plan.id
}

Again, let’s break this down - starting with the plan:

terraform 2 2

Finally, let’s have a look at the app service itself - there’s not too much difference here:

terraform 2 3

If we now run



terraform.exe plan

Then we’ll see that it intends to create an app service plan and app service within that plan; running:



terraform.exe apply

Will execute that and generate our new resources.



Profile picture

A blog about one man's journey through code… and some pictures of the Peak District
Twitter

© Paul Michaels 2024