๐ŸŒ Terraform Complete Commands Reference

๐Ÿš€ Initialize & Setup

terraform init                      # Initialize directory with Terraform config
terraform init -upgrade            # Upgrade modules/plugins
terraform init -backend-config=dev.hcl

๐Ÿง  Planning Infrastructure

terraform plan                     # Show execution plan
terraform plan -out=tfplan        # Save plan to file
terraform show tfplan             # View saved plan
terraform graph | dot -Tsvg > plan.svg

๐Ÿ› ๏ธ Apply Infrastructure

terraform apply                   # Apply changes
terraform apply tfplan           # Apply saved plan
terraform apply -auto-approve    # Skip interactive approval

๐Ÿ’ฃ Destroy Infrastructure

terraform destroy                # Destroy everything
terraform destroy -auto-approve

๐Ÿ“ฆ State Management

terraform state list                         # List resources
terraform state show aws_instance.example   # Show details
terraform state mv old.name new.name        # Rename resource
terraform state rm aws_s3_bucket.mybucket   # Remove from state

๐Ÿ—‚๏ธ Workspaces

terraform workspace list
terraform workspace new dev
terraform workspace select dev
terraform workspace delete dev

๐Ÿ“ Modules

# Structure your Terraform configs
module "vpc" {
  source = "./modules/vpc"
  cidr_block = "10.0.0.0/16"
}

๐Ÿงน Format, Validate, and Output

terraform fmt                     # Format code
terraform validate               # Validate configuration
terraform output                 # Show outputs
terraform output variable_name

๐ŸŒ Providers

# Define provider in main.tf
provider "aws" {
  region = "us-east-1"
}

๐Ÿงช KodeKloud Labs Examples

# Sample tasks from Terraform labs
terraform init
terraform plan
terraform apply

# Variables
terraform apply -var="instance_type=t2.micro"

# Use .tfvars
terraform apply -var-file="dev.tfvars"

โœ… This complete Terraform reference includes all essential commands and KodeKloud lab-style usage. Master these to manage cloud infrastructure efficiently.