Infrastructure as Code is a god send for system admins and devops teams around the world. With Terraform it’s a walk in the park.

Installing Terraform

Follow the instructions based on the your operating system.


Visit Terraform’s downloads page & Windows. Select the architecture and download zip file to your windows pc.

Once downloaded, extract the archive file and copy the terraform.exe to safe location, something like C:/tools/ and set the path to environment variables.


curl -fsSL | sudo apt-key add -
sudo apt-add-repository "deb [arch=amd64] $(lsb_release -cs) main"
sudo apt-get update && sudo apt-get install terraform


sudo yum install -y yum-utils
sudo yum-config-manager --add-repo
sudo yum -y install terraform


brew tap hashicorp/tap
brew install hashicorp/tap/terraform

open terminal and test it with

terraform version

you should see something like this.

Terraform v1.1.7
on windows_amd64

Azure Shell install

To run on azure, terraform use default Azure login stored in .azure directory on user home. To login, Azure CLI needs to be installed. Download the CLI from Microsoft. Once download completed, installed the Azure CLI and Open the Powershell or Windows Terminal.

To login, run

az login

It should show something similar to this

 az login
A web browser has been opened at Please continue the login in the web browser. If no web browser is available or if the web browser fails to open, use device code flow with `az login --use-device-code`.

It’ll open the default browser of you system and prompts for microsoft account login. Continue login in the browser.

Once the login completed, it’ll output the subscription details

    "cloudName": "AzureCloud",
    "homeTenantId": "",
    "id": "",
    "isDefault": true,
    "managedByTenants": [],
    "name": "",
    "state": "Enabled",
    "tenantId": "",
    "user": {
      "name": "[email protected]",
      "type": "user"

You can check the this details in the future with

az account show

To view the output as a table

az account show -o table


Create a directory where you want to store the terraform configuration files. Create a file named Thi i where we store all the configs.

First add azure plugin details in the

terraform {
  required_providers {
    azurerm = {
      source  = "hashicorp/azurerm"
      version = "2.99.0"

provider "azurerm" {
  # Configuration options
  features {}

To create a resource group to add any resources on azure,

resource "azurerm_resource_group" "south1" {
  name     = "region-southindia"
  location = "southindia"
  tags = {
    "environment" = "dev"
    "source"      = "terraform"

Here, resource type i azurerm_resource_group and resource name is south1 which we can define as want.

Tags can be used to with "key" = "Value" as many as you want.

You should see some thing like this in

terraform {
  required_providers {
    azurerm = {
      source  = "hashicorp/azurerm"
      version = "2.99.0"

provider "azurerm" {
  # Configuration options
  features {}

resource "azurerm_resource_group" "south1" {
  name     = "region-southindia"
  location = "southindia"
  tags = {
    "environment" = "dev"
    "source"      = "terraform"


To Initialize the terraform and install the azure plugin, you should run

terraform init

output should be something similar

$ terraform init

Initializing the backend...

Initializing provider plugins...
- Finding hashicorp/azurerm versions matching "2.99.0"...
- Installing hashicorp/azurerm v2.99.0...
- Installed hashicorp/azurerm v2.99.0 (signed by HashiCorp)

Terraform has created a lock file .terraform.lock.hcl to record the provider
selections it made above. Include this file in your version control repository
so that Terraform can guarantee to make the same selections by default when
you run "terraform init" in the future.

Terraform has been successfully initialized!

You may now begin working with Terraform. Try running "terraform plan" to see
any changes that are required for your infrastructure. All Terraform commands
should now work.

If you ever set or change modules or backend configuration for Terraform,
rerun this command to reinitialize your working directory. If you forget, other
commands will detect it and remind you to do so if necessary.


To format all the config properly run

terraform fmt


Before running the config, you should validate it to check everything is sound.

terraform validate

Output should looks like this

$ terraform validate
Success! The configuration is valid.

Plan and Apply

To check modification and what’s actually change on live infrastructure, run

terraform plan
$ terraform.exe plan

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the
following symbols:
  + create

Terraform will perform the following actions:

  # azurerm_resource_group.south1 will be created
  + resource "azurerm_resource_group" "south1" {
      + id       = (known after apply)
      + location = "southindia"
      + name     = "region-southindia"
      + tags     = {
          + "environment" = "dev"
          + "source"      = "terraform"

Plan: 1 to add, 0 to change, 0 to destroy.

Here + means create.

To make changes run

terraform apply

And terraform will prompt from confirmation and only accepts yes to apply changes.

Do you want to perform these actions?
Terraform will perform the actions described above.
Only 'yes' will be accepted to approve.

Enter a value: yes

Enter yes to continue.

azurerm_resource_group.south1: Creating...
azurerm_resource_group.south1: Creation complete after 2s [id=/subscriptions/id/resourceGroups/region-southindia]

To check wether the changes made here are working or not, login to azure dashboard and check resource groups.

Delete the resources

To delete the resource created, run

terraform destroy

Enter yes to approve the changes.


With Terraform, sky is the limit for managing infrastructure. Check the azure documentation here. Feel free to comment here or drop an email. Au Revoir.