Starting with Terraform and Azure

Gareth Erskine-Jones
May 13 · 7 min read
Photo by Lorenzo Cafaro from Pexels

Why Terraform?

Installing the pre-requisites

> terraform --version
Terraform v0.12.1
> az --version
azure-cli 2.0.62
(lots more output)

Creating the configuration file

provider "azurerm" {}

Creating our first resource

resource “azurerm_resource_group” “my-group” {
name = “my-resource-group”
location = “westus”
}
> terraform plan
An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
+ create
Terraform will perform the following actions:
+ azurerm_resource_group.my-group
id: <computed>
location: “westus”
name: “my-resource-group”
tags.%: <computed>
Plan: 1 to add, 0 to change, 0 to destroy.
* provider.azurerm: Error building AzureRM Client: Error retrieving the Profile from the Azure CLI: No Subscription was Marked as Default in the Azure Profile. Please re-authenticate using `az login`.
> terraform apply

State file

Creating a website

resource "azurerm_app_service_plan" "appserviceplan" {
name = "my-service-plan"
location = "westus"
resource_group_name = azurerm_resource_group.my-group.name
reserved = true # Mandatory for Linux plans
kind = "Linux"
sku {
tier = "Basic"
size = "B1"
}
}
resource "azurerm_app_service" "web" {
name = "my-site"
location = "westus"
resource_group_name = azurerm_resource_group.my-group.name
app_service_plan_id = azurerm_app_service_plan.appserviceplan.id
# Configure Docker Image to load on start site_config {
linux_fx_version = "DOCKER|nginx"
}
}
> terraform destroy

Faun

The Must-Read Publication for Aspiring Developers & DevOps Enthusiasts

Gareth Erskine-Jones

Written by

Faun

Faun

The Must-Read Publication for Aspiring Developers & DevOps Enthusiasts