About setting-up-terraform
A skill for structuring Terraform projects and guiding infrastructure-as-code setup across AWS, GCP, and Azure. It covers reusable modules, state handling, and a CI validation workflow.
Key features
- 01Terraform project structure
- 02Provider and variable setup
- 03Reusable infrastructure modules
- 04Remote state and locking
- 05CI checks and deployment workflow
Use cases
- 01Starting a cloud infrastructure project
- 02Separating state for dev, staging, and production
- 03Adding Terraform checks to pull requests
Install
Copy the command and run it in a terminal.
npx skills add https:/ / github.com/ revitalb-port/ skills-registry-demo --skill setting-up-terraformAfter installing, type/setting-up-terraformin Claude Code to confirm it loaded.
Details
From the project READMESetup Terraform
Use this skill when the user asks to set up Terraform, infrastructure as code, cloud provisioning, or IaC.
Steps
-
Initialize the project structure
infra/ ├── main.tf ├── variables.tf ├── outputs.tf ├── terraform.tfvars # (gitignored) ├── providers.tf └── modules/ -
Configure the provider — in
providers.tf:terraform { required_version = ">= 1.5" required_providers { aws = { source = "hashicorp/aws" version = "~> 5.0" } } backend "s3" { bucket = "my-terraform-state" key = "prod/terraform.tfstate" region = "us-east-1" } } provider "aws" { region = var.aws_region }Adapt the provider for the user's cloud (AWS, GCP, Azure).
-
Define variables — in
variables.tf, define inputs with types, descriptions, and defaults:variable "aws_region" { type = string default = "us-east-1" description = "AWS region for resources" } variable "environment" { type = string description = "Deployment environment (dev, staging, prod)" } -
Create resources — in
main.tf, define the infrastructure the user needs (VPC, RDS, ECS, S3, Lambda, etc.). Extract reusable patterns into modules undermodules/. -
Configure remote state — use an S3 bucket (AWS), GCS bucket (GCP), or Azure Storage for state. Enable state locking with DynamoDB (AWS).
-
Add to
.gitignore*.tfstate *.tfstate.* .terraform/ terraform.tfvars *.tfvars -
Add CI pipeline — create a GitHub Actions workflow that runs
terraform fmt -check,terraform validate, andterraform planon PRs, withterraform applyon merge to main (with approval gate).
Notes
- Never commit state files or
.tfvarswith secrets. - Use workspaces or separate state files for dev/staging/prod.
- Pin provider versions to avoid breaking changes.
- Run
terraform fmtbefore committing.