skills/devops-sre/terraform/SKILL.md
Tool for defining, provisioning, and managing infrastructure as code using declarative HCL configuration files.
npx skillsauth add alphaonedev/openclaw-graph terraformInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Terraform is a command-line tool for defining and provisioning infrastructure as code using declarative HCL (HashiCorp Configuration Language) files. It enables users to create, update, and destroy cloud resources in a repeatable, version-controlled manner.
Use Terraform for managing multi-cloud environments, automating infrastructure deployments, or when you need version-controlled IaC for resources like VMs, networks, or databases. Apply it in scenarios involving AWS, Azure, or GCP provisioning, especially for dynamic scaling, disaster recovery setups, or CI/CD pipelines to ensure consistency.
resource "aws_instance" "example" { ami = "ami-123456" instance_type = "t2.micro" }.provider "aws" { region = "us-west-2" }.module "vpc" { source = "./modules/vpc" }.count for loops or templatefile for dynamic configs.To use Terraform, start by writing an HCL file (e.g., main.tf) defining resources and providers. Initialize the workspace with terraform init, review changes via terraform plan, and apply them with terraform apply. For automation, wrap commands in scripts and use environment variables for secrets. Always version control your .tf files in Git. For multi-environment setups, use workspaces: terraform workspace new dev then switch with terraform workspace select dev.
Run Terraform via CLI; key commands include:
terraform init: Download providers and modules; use -upgrade to update dependencies.terraform plan -out=plan.tfplan -var="instance_type=t2.medium": Generate an execution plan; specify variables via flags or files.terraform apply plan.tfplan: Apply the plan; add -auto-approve for non-interactive runs.terraform destroy -target=aws_instance.example: Destroy specific resources; use -force cautiously.
For API integration, use Terraform's remote backend or the Terraform Cloud API (e.g., POST to https://app.terraform.io/api/v2/runs for runs), but require authentication via $TERRAFORM_TOKEN. Set provider credentials as env vars, e.g., export AWS_ACCESS_KEY_ID=$AWS_API_KEY and export AWS_SECRET_ACCESS_KEY=$AWS_SECRET_KEY.Integrate Terraform with CI/CD tools like GitHub Actions or Jenkins by adding steps in your workflow YAML, e.g.:
- name: Terraform Init
run: terraform init
- name: Terraform Apply
run: terraform apply -auto-approve
Use remote state backends for collaboration, e.g., configure in main.tf with terraform { backend "s3" { bucket = "my-terraform-state" key = "path/to/state" region = "us-west-2" } }. For secrets, inject via env vars (e.g., $AWS_ACCESS_KEY_ID) or tools like Vault. Ensure provider versions are pinned in .tf files, like terraform { required_providers { aws = { source = "hashicorp/aws" version = "~> 4.0" } } }, to avoid breaking changes.
Handle errors by running terraform validate first to check HCL syntax; fix issues like missing brackets or invalid attributes. For provider errors, verify credentials (e.g., check $AWS_ACCESS_KEY_ID is set) and use terraform plan -detailed-exitcode to get specific codes (e.g., 2 for errors). Common patterns: wrap commands in try-catch blocks in scripts, e.g.:
try {
terraform apply
} catch {
echo "Error: Apply failed; check logs for details"
}
Debug with TF_LOG=DEBUG terraform apply to log provider interactions, and use terraform state pull to inspect state files for inconsistencies.
resource "aws_instance" "web" { ami = "ami-0c55b159cbfafe1f0" instance_type = "t2.micro" tags = { Name = "web-server" } }. Then run terraform init, followed by terraform apply -auto-approve to provision it.resource "aws_vpc" "main" { cidr_block = "10.0.0.0/16" } and resource "aws_subnet" "subnet1" { vpc_id = aws_vpc.main.id cidr_block = "10.0.1.0/24" }. Execute terraform plan to review, then terraform apply for deployment.tools
Root web development: project structure, tooling selection, deployment decisions
development
WebAssembly: Rust/Go/C to WASM, wasm-bindgen, Emscripten, WASM Component Model
development
Vue 3: Composition API script setup, Pinia, Vue Router 4, SFCs, Vite, Nuxt 3
tools
Tailwind CSS 4: utility classes, config, JIT, arbitrary values, darkMode, plugins, shadcn/ui