Multi-Cloud & IaC Reference

Azure, GCP & Terraform IaC Quick Reference

Stop clicking through cloud portals. Define servers, networks, and storage in declarative Terraform HCL, and manage Microsoft Azure & Google Cloud (GCP) from your terminal.

โฑ๏ธ 8 min scan๐ŸŸข Beginner Friendly๐Ÿ“… Updated: 2026
โš™๏ธ The Terraform Infrastructure-as-Code (IaC) Loop
1. HCL Code main.tf Desired Infrastructure 2. Dry Run terraform plan Preview + Add / ~ Mod / - Del 3. Provision terraform apply Calls AWS / Azure / GCP APIs 4. Cloud State terraform.tfstate Live Reality Map Compares Desired (.tf) vs Actual (.tfstate)

1 Terraform Core Workflow

Terraform uses a predictable lifecycle. You write .tf files, initialize providers, preview changes with plan, and execute with apply.

terraform init
Initialize Working Directory
Downloads cloud provider plugins (AWS/Azure/GCP) & sets up backend.
terraform fmt -recursive
Format HCL Code
Auto-indents and cleans up all .tf files in the project.
terraform validate
Validate Syntax & Types
Checks for typos, missing variables, or invalid blocks offline.
terraform plan -out=tfplan
Preview Changes (Dry Run)
Shows exact creates (+), updates (~), and destroys (-).
terraform apply tfplan
Apply Saved Plan
Executes the exact plan you reviewedโ€”no surprises.
terraform state list
Inspect Tracked Resources
Lists every resource currently managed inside terraform.tfstate.
terraform destroy
Tear Down Infrastructure
Deletes all resources in state. Prompts for yes confirmation.
๐Ÿง  Memory Trick: I Found Valid Plans Apply Destructive State

Remember the golden order: Init โ†’ Fmt โ†’ Validate โ†’ Plan โ†’ Apply โ†’ (Destroy) โ†’ State. Never run apply without reading the plan output first!

2 HCL Block Anatomy & State File

Terraform files use HCL (HashiCorp Configuration Language). Almost every configuration is built from five core block types plus the terraform.tfstate tracking file.

resource "azurerm_resource_group" "web_rg" { name = var.rg_name }
Block Type resource Creates & manages infra
Resource Type "azurerm_resource_group" Provider + resource kind
Local Name "web_rg" Your internal nickname
Arguments name = var.rg_name Settings & variable refs

๐Ÿ”Œ provider

Configures the cloud plugin (e.g., provider "azurerm" or provider "google") with region/project settings.

๐Ÿงฑ resource

Declares a real cloud object to create and own (VMs, buckets, VPCs, databases).

๐Ÿ” data

Read-only lookup of an existing resource you did not create in this config (e.g., latest Ubuntu AMI).

๐Ÿ“ฅ variable

Input parameters (var.env) so you can reuse the same code for dev, staging, and prod.

๐Ÿ“ค output

Prints useful values after apply (e.g., the VM's public IP or load balancer DNS).

๐Ÿ—บ๏ธ terraform.tfstate

JSON map linking your HCL names to real cloud IDs. Store remotely (S3 / Azure Blob / GCS) in teams!

main.tf โ€” Minimal Multi-Block Example
variable "location" {
  default = "eastus"
}

resource "azurerm_resource_group" "app" {
  name     = "rg-shekharit-dev"
  location = var.location
}

output "rg_id" {
  value = azurerm_resource_group.app.id
}

3 Azure CLI & Resource Hierarchy

Azure organizes everything in a strict 4-level tree. Every resource must live inside a Resource Group, which lives inside a Subscription.

๐Ÿข Entra ID Tenant โ†’ ๐Ÿ’ณ Subscription โ†’ ๐Ÿ“ Resource Group โ†’ โš™๏ธ Resource (VM / Storage)
az login
Sign In to Azure
Opens browser authentication and caches your Entra ID token.
az account list --output table
List Subscriptions
Shows all Azure subscriptions and highlights the active default.
az group create --name rg-lab --location eastus
Create a Resource Group
Creates a logical container for your lab VMs, networks, and disks.
az vm create -g rg-lab -n web01 --image Ubuntu2204 --generate-ssh-keys
Launch an Ubuntu VM
Creates VM, VNet, Subnet, Public IP, and NSG in one command.
az storage account list --output table
List Storage Accounts
Displays Azure Blob/File storage accounts across your subscription.
az group delete --name rg-lab --yes --no-wait
Clean Up Entire Lab
Deletes the Resource Group and every resource inside it asynchronously.

4 GCP gcloud CLI Essentials

Google Cloud Platform uses the hierarchy Organization โ†’ Folder โ†’ Project โ†’ Resource. Almost every gcloud command operates inside your active Project.

gcloud auth login
Authenticate gcloud CLI
Logs you into your Google Cloud account via OAuth in the browser.
gcloud config set project my-gcp-project-id
Set Active GCP Project
Sets the default project ID so you don't repeat --project.
gcloud compute instances list
List Compute Engine VMs
Shows VM names, zones, machine types, internal/external IPs, and status.
gcloud storage ls gs://my-gcs-bucket/
List Cloud Storage Objects
Modern replacement for gsutil ls to browse GCS buckets.
gcloud storage cp ./app.zip gs://my-gcs-bucket/releases/
Upload File to GCS Bucket
Copies a local archive to Google Cloud Storage (fast parallel upload).

5 Danger Zone: IaC & Multi-Cloud Traps

โš ๏ธ State, Secret & Destruction Hazards
1. Committing terraform.tfstate or .tfvars Secrets to Git

terraform.tfstate stores database passwords, API keys, and private IPs in plaintext JSON. Always add *.tfstate* and *.tfvars (except example files) to .gitignore, and use an encrypted remote backend.

2. Running terraform destroy Without Review or -target

terraform destroy tears down every resource in your state fileโ€”including production databases. If you only need to remove one resource, use terraform plan -destroy -target=aws_instance.test first, or remove the block from HCL and run terraform apply.

3. Manual "ClickOps" Edits Causing State Drift

Changing firewall rules or VM sizes in the AWS/Azure/GCP console after Terraform created them causes state drift. Next time someone runs terraform apply, Terraform may overwrite or destroy your manual fix.

4. Deleting the Wrong Azure Resource Group

az group delete is an atomic nukeโ€”it deletes every VM, disk, database, and storage account inside that group. Double-check az account show and the Resource Group name before confirming.