Terraform (Infrastructure as Code)
Core loop
terraform init # download providers/modules
terraform fmt # format
terraform validate # validate
terraform plan # what will change (READ before applying)
terraform apply # apply (asks for confirmation)
terraform destroy # tear down resources
Structure
main.tf resources, variables.tf inputs, outputs.tf outputs, terraform.tfvars values.
- Resource:
resource "aws_s3_bucket" "b" { bucket = var.name }
- Variable:
variable "name" { type = string } -> var.name
- Output:
output "url" { value = aws_s3_bucket.b.website_endpoint }
- Module:
module "vpc" { source = "./modules/vpc" }
State (critical)
- The state file (
terraform.tfstate) records real infra — never commit it, it holds secrets.
- For teams use a remote backend (S3 + DynamoDB lock, Terraform Cloud).
terraform state list / terraform import to manage existing resources.
Working safely
- Always read
plan first; review the apply output.
- Separate environments with workspaces:
terraform workspace new staging.
- Pin provider versions with
required_providers.
Use this skill with your AI agent:
Open on Skill Issue to copy, download, or add to your library.
Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.