Terraform Cheat Codes

Posting my most used Terraform commands and snippets here for easy reference.

Azure Provider Configuration

# Configure the Azure Provider
provider "azurerm" {  
  subscription_id = "${var.subscription_id}"
  client_id       = "${var.client_id}"
  client_secret   = "${var.client_secret}"
  tenant_id       = "${var.tenant_id}"
}

Azure State File Blob Storage Container Configuration

# Configure the Azure Blob Storage Container
TBD  

Common Commands

# Initalization
terraform init

# Upgrading
terraform init -upgrade

# Create a New Workspace
terraform workspace new <--workspace-name-->

# Change to existing Workspace
terraform workspace select <--workspace-name-->

# Plan with var file
terraform plan -var-file=<--variable-file-name-->

# Apply with var file
terraform apply -var-file=<--variable-file-name-->

# Apply with var file (auto apply)
terraform apply -var-file=<--variable-file-name--> -auto-approve


# Destroy with var file
terraform destroy -var-file=<--variable-file-name-->