terraform init # Initialize directory with Terraform config
terraform init -upgrade # Upgrade modules/plugins
terraform init -backend-config=dev.hcl
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
terraform apply # Apply changes
terraform apply tfplan # Apply saved plan
terraform apply -auto-approve # Skip interactive approval
terraform destroy # Destroy everything
terraform destroy -auto-approve
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
terraform workspace list
terraform workspace new dev
terraform workspace select dev
terraform workspace delete dev
# Structure your Terraform configs
module "vpc" {
source = "./modules/vpc"
cidr_block = "10.0.0.0/16"
}
terraform fmt # Format code
terraform validate # Validate configuration
terraform output # Show outputs
terraform output variable_name
# Define provider in main.tf
provider "aws" {
region = "us-east-1"
}
# 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.