Terraform Archive Provider - Create ZIP and TAR Files
Use the Terraform archive provider to create ZIP files for Lambda functions, Cloud Functions, and deployments. archive_file data source with source_dir and...
Terraform
Master the three essential Terraform commands - init, plan, and apply. Learn what each does, when to use them, and common flags for production workflows.
Every Terraform workflow revolves around three core commands: init, plan, and apply. Understanding exactly what each does and when to use them is fundamental to working with Terraform effectively.
terraform init → terraform plan → terraform apply
↓ ↓ ↓
Setup providers Preview changes Execute changes
Download modules Show diff Create/update/destroy
Configure backend Detect errors Update stateterraform init initializes a Terraform working directory. Run it first, every time.
.terraform directory and lock file# Basic initialization
terraform init
# Upgrade providers to latest compatible versions
terraform init -upgrade
# Reconfigure backend
terraform init -reconfigure
# Migrate state to new backend
terraform init -migrate-stateterraform plan creates an execution plan showing what Terraform will do.
# Basic plan
terraform plan
# Save plan to file
terraform plan -out=tfplan
# Plan with variables
terraform plan -var="environment=prod"
# Plan specific resource
terraform plan -target=aws_instance.web
# Destroy plan
terraform plan -destroy
# JSON output
terraform plan -jsonPlan: 2 to add, 1 to change, 0 to destroy.terraform apply executes the planned changes against your infrastructure.
# Interactive apply (shows plan, asks for confirmation)
terraform apply
# Apply saved plan (no confirmation)
terraform apply tfplan
# Auto-approve (skip confirmation)
terraform apply -auto-approve
# Apply with variables
terraform apply -var="instance_type=t3.large"
# Apply specific resource
terraform apply -target=aws_instance.webterraform destroy # Interactive
terraform destroy -auto-approve # No confirmation
terraform plan -destroy # Preview destructionterraform validate # Check syntax without accessing APIsterraform fmt # Format files in current directory
terraform fmt -recursive # Format all subdirectories
terraform fmt -check # Check without modifying (CI use)# 1. Initialize
terraform init
# 2. Format and validate
terraform fmt -check
terraform validate
# 3. Plan and save
terraform plan -out=tfplan
# 4. Review the plan
terraform show tfplan
# 5. Apply the saved plan
terraform apply tfplaninit, plan, and apply are the three pillars of every Terraform workflow. Master these commands and their flags to work confidently with infrastructure as code.
Use the Terraform archive provider to create ZIP files for Lambda functions, Cloud Functions, and deployments. archive_file data source with source_dir and...
Automate Terraform with Azure DevOps Pipelines. YAML pipelines, service connections, environment approvals, and Azure backend state configuration.
Automate Terraform with GitHub Actions. Plan on PR, apply on merge, OIDC authentication, environment protection, and drift detection workflows.
Automate Terraform with GitLab CI/CD. Plan on merge requests, apply on main, remote state with HTTP backend, and environment-specific pipelines.