This page collects common Terraform workflows using current CLI conventions.
mkdir -p ~/iac/demo
cd ~/iac/demo
cat > versions.tf <<'HCL'
terraform {
required_version = ">= 1.5.0"
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 5.0"
}
}
}
HCL
terraform init
terraform fmt -recursive
terraform validate
terraform plan
terraform plan -out=tfplan
terraform apply tfplan
cat > terraform.tfvars <<'HCL'
region = "us-east-1"
env = "dev"
HCL
terraform plan -var-file=terraform.tfvars
terraform {
backend "s3" {
bucket = "my-terraform-state"
key = "network/prod/terraform.tfstate"
region = "us-east-1"
dynamodb_table = "terraform-locks"
encrypt = true
}
}
After editing backend config:
terraform init -reconfigure
terraform init -upgrade
terraform providers
git diff terraform.lock.hcl
terraform plan -destroy
terraform destroy