kid-sid/claude-spellbook/infrastructure-as-code
Claude Code and agent skill by kid-sid/claude-spellbook
- community
Checking that the SKILL.md file is still in the repository.
Use when writing Terraform for cloud resources, setting up remote state, structuring modules for reuse, managing multiple environments, reviewing a plan before apply, or importing and resolving state drift.
Install
npx vskill@latest install kid-sid/claude-spellbook/infrastructure-as-codeSKILL.md
Infrastructure as Code
Terraform lets you define, provision, and version cloud infrastructure as declarative HCL code, enabling repeatable and reviewable infrastructure changes.
When to Activate
- Writing Terraform for cloud resources (VPC, RDS, EKS, IAM, etc.)
- Setting up a Terraform state backend
- Creating a reusable Terraform module
- Managing multiple environments (dev/staging/prod) with Terraform
- Reviewing a
terraform planbefore applying - Dealing with state drift or importing existing resources
Core Building Blocks
State Management
Remote State Backend
State must be remote and locked — never store terraform.tfstate in git.
AWS (S3 + DynamoDB lock):
GCP (GCS):
State Commands
State file security: The state file contains sensitive values (RDS passwords, private keys). Ensure S3 bucket has:
- Versioning enabled (recover from bad apply)
- Server-side encryption
- Block public access
- Access restricted to CI role + team IAM role only
Module Structure
Module Example
Module Versioning
Environment Strategy
Directory-per-Environment (recommended)
Pros: complete isolation, different providers per env, easy to cd into. Cons: some code duplication across environments.
Workspace (alternative)
Use terraform.workspace in HCL:
Decision: Use directory-per-environment for significant infrastructure differences between envs. Use workspaces only for identical infrastructure with minor variable differences.
tfvars per Environment
Plan/Apply Workflow
CI Pipeline Integration
Common Resource Patterns
VPC Networking (AWS)
IAM Role + Policy (least privilege)
RDS Instance
Drift Detection and Import
Detect Drift
Any ~ (update) or -/+ (replace) on a resource you haven't changed = drift.
Import Existing Resources
moved Block (safe refactoring)
See also:ci-cd,containerization,security
Red Flags
- Storing `terraform.tfstate` in git — state files contain plaintext secrets (RDS passwords, private keys); use an S3+DynamoDB or GCS backend with server-side encryption from day one
- Running `terraform apply` directly without a saved plan —
terraform applywithout-out=tfplanre-plans at apply time; what was reviewed in the PR and what actually runs can differ if state changed between plan and apply - Using `terraform apply -auto-approve` in CI on the production environment — auto-approve bypasses the human gate; production applies must require explicit approval via a GitHub environment protection rule
- Module pinned to `main` or with no version constraint —
source = "git::...?ref=main"means any upstream commit silently changes your infrastructure; pin to a specific git tag or Terraform registry version - IAM policy with `"Action": "*"` or `"Resource": "*"` — wildcard actions on all resources violates least privilege; scope to the exact actions and resource ARNs the role actually needs
- `terraform state rm` used to "fix" a drift problem — removing a resource from state without destroying it creates orphaned cloud resources that accumulate cost and may introduce security gaps; use
movedblocks orterraform importinstead - Deleting a Terraform resource block to decommission a resource — removing the block from HCL causes
terraform planto show a destroy; validate intent withterraform planand addlifecycle { prevent_destroy = true }on stateful resources - Sharing a single state file across all environments — one bad apply in staging can corrupt or lock the production state; each environment must have its own state file with its own backend key
Checklist
This is the start of the file. Read the full SKILL.md on GitHub.
Security
- Security scanPassed, 100 of 100Pattern checks on the skill's files.
- Model reviewNot runA model review is scheduled for the next rescan.
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/infrastructure-as-code/skill.md
Popularity
- Repository stars
- 186
- Repository forks
- 15
- 7-day trend score
- 26
Stars and forks are for the whole GitHub repository, not this skill alone. Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/kid-sid/claude-spellbook/infrastructure-as-code)