This skill activates when the user is designing, implementing, or troubleshooting
infrastructure-as-code patterns. This includes Terraform/OpenTofu module design,
Pulumi program structure, state management strategy, drift detection workflows,
plan/apply pipelines, workspace isolation for multi-environment deployments, and
general IaC best practices for declarative infrastructure provisioning.
Mandatory actions
Before
Identify the IaC tool in use (Terraform, OpenTofu, Pulumi, CloudFormation, Bicep).
Determine the target cloud provider(s) and existing state backend configuration.
Assess current module structure and versioning strategy.
Check for existing CI/CD pipeline integration (plan on PR, apply on merge).
Always prefer declarative resource definitions over procedural scripts.
Express desired end-state; let the provider handle ordering and dependencies.
Use depends_on only when implicit dependency detection fails.
State Management:
Remote backends are mandatory for team environments (S3+DynamoDB locking, Terraform Cloud, GCS+locking).
Never commit .tfstate files to version control.
Enable state encryption at rest.
Use state locking to prevent concurrent modifications.
Implement state backup/versioning via backend configuration.
Module Design:
Single responsibility: one module = one logical resource group.
Version all modules with semantic versioning (pin in consumers).
Define clear input/output contracts via variables.tf and outputs.tf.
Use composition (modules calling modules) over monolithic configurations.
Document module interfaces with descriptions on every variable and output.
Plan/Apply Workflow:
ALWAYS run plan first and review the diff before applying.
Automate plan output on pull requests (comment the diff).
Require human approval gate before apply in production.
Use -target sparingly — it creates state drift risk.
Save plan files (-out=plan.tfplan) for deterministic applies.
Drift Detection:
Schedule periodic plan-only runs to detect configuration drift.
Alert on any detected drift (resources modified outside IaC).
Reconcile drift by either importing changes or reverting manual modifications.
Use terraform refresh cautiously — it updates state but not code.
Workspace Isolation:
Separate state files per environment (dev/staging/prod).
Use Terraform workspaces OR separate root modules per environment.
Prefer separate root modules for production isolation (stronger blast radius containment).
Environment-specific variables via .tfvars files or workspace-aware variable lookups.
Secrets Handling:
NEVER store secrets in state files or variable defaults.
Use data sources to fetch secrets from Vault/SOPS at plan time.
Mark sensitive outputs with sensitive = true.
Encrypt state backend at rest and in transit.
Testing:
Use Terratest or terraform validate + terraform plan in CI.
Write integration tests that provision real infrastructure in ephemeral accounts.
Validate plan output against policy (OPA/Sentinel/Conftest).
Test module interfaces with example configurations.
After
Verify terraform plan shows expected changes (no surprises).
Confirm state backend is accessible and lock is released.
Validate outputs match expected resource identifiers.
Run compliance/policy checks against the final plan.
Document any manual steps required outside IaC scope.
Self-check before task completion
All infrastructure is defined declaratively (no imperative scripts for provisioning).
State is stored remotely with locking and encryption enabled.
Modules follow single responsibility and are versioned.
Plan/apply workflow is enforced (no direct applies without review).
Secrets are not hardcoded in configurations or state.
Drift detection mechanism is in place or recommended.
Workspace isolation separates environments with independent state.
Testing strategy covers plan validation and policy compliance.
1---2name: infrastructure-as-code3description: Infrastructure as Code4---56# Infrastructure as Code78## When this skill activates910This skill activates when the user is designing, implementing, or troubleshooting11infrastructure-as-code patterns. This includes Terraform/OpenTofu module design,12Pulumi program structure, state management strategy, drift detection workflows,13plan/apply pipelines, workspace isolation for multi-environment deployments, and14general IaC best practices for declarative infrastructure provisioning.1516## Mandatory actions1718### Before19201. Identify the IaC tool in use (Terraform, OpenTofu, Pulumi, CloudFormation, Bicep).212. Determine the target cloud provider(s) and existing state backend configuration.223. Assess current module structure and versioning strategy.234. Check for existing CI/CD pipeline integration (plan on PR, apply on merge).245. Identify secrets management approach (Vault, SOPS, AWS Secrets Manager).2526### During2728**Declarative over Imperative:**29- Always prefer declarative resource definitions over procedural scripts.30- Express desired end-state; let the provider handle ordering and dependencies.31- Use `depends_on` only when implicit dependency detection fails.3233**State Management:**34- Remote backends are mandatory for team environments (S3+DynamoDB locking, Terraform Cloud, GCS+locking).35- Never commit `.tfstate` files to version control.36- Enable state encryption at rest.37- Use state locking to prevent concurrent modifications.38- Implement state backup/versioning via backend configuration.3940**Module Design:**41- Single responsibility: one module = one logical resource group.42- Version all modules with semantic versioning (pin in consumers).43- Define clear input/output contracts via `variables.tf` and `outputs.tf`.44- Use composition (modules calling modules) over monolithic configurations.45- Document module interfaces with descriptions on every variable and output.4647**Plan/Apply Workflow:**48- ALWAYS run `plan` first and review the diff before applying.49- Automate plan output on pull requests (comment the diff).50- Require human approval gate before `apply` in production.51- Use `-target` sparingly — it creates state drift risk.52- Save plan files (`-out=plan.tfplan`) for deterministic applies.5354**Drift Detection:**55- Schedule periodic plan-only runs to detect configuration drift.56- Alert on any detected drift (resources modified outside IaC).57- Reconcile drift by either importing changes or reverting manual modifications.58- Use `terraform refresh` cautiously — it updates state but not code.5960**Workspace Isolation:**61- Separate state files per environment (dev/staging/prod).62- Use Terraform workspaces OR separate root modules per environment.63- Prefer separate root modules for production isolation (stronger blast radius containment).64- Environment-specific variables via `.tfvars` files or workspace-aware variable lookups.6566**Secrets Handling:**67- NEVER store secrets in state files or variable defaults.68- Use data sources to fetch secrets from Vault/SOPS at plan time.69- Mark sensitive outputs with `sensitive = true`.70- Encrypt state backend at rest and in transit.7172**Testing:**73- Use Terratest or `terraform validate` + `terraform plan` in CI.74- Write integration tests that provision real infrastructure in ephemeral accounts.75- Validate plan output against policy (OPA/Sentinel/Conftest).76- Test module interfaces with example configurations.7778### After79801. Verify `terraform plan` shows expected changes (no surprises).812. Confirm state backend is accessible and lock is released.823. Validate outputs match expected resource identifiers.834. Run compliance/policy checks against the final plan.845. Document any manual steps required outside IaC scope.8586## Self-check before task completion8788- [ ] All infrastructure is defined declaratively (no imperative scripts for provisioning).89- [ ] State is stored remotely with locking and encryption enabled.90- [ ] Modules follow single responsibility and are versioned.91- [ ] Plan/apply workflow is enforced (no direct applies without review).92- [ ] Secrets are not hardcoded in configurations or state.93- [ ] Drift detection mechanism is in place or recommended.94- [ ] Workspace isolation separates environments with independent state.95- [ ] Testing strategy covers plan validation and policy compliance.
Run npx skillmds@latest add sairam0424/infrastructure-as-code in your terminal (requires Node.js), paste this page's agent-chat prompt into Claude, Cursor, or any MCP-connected agent, or download the SKILL.md file and copy it into your agent's skills directory.
Infrastructure as Code It is listed under Coding & Dev Tools on SkillMD.
This skill has not completed SkillMD's automated safety review yet. SkillMD never runs a skill's scripts for you; review the SKILL.md before installing.
This skill is tagged as working with Claude Code, Claude.ai, OpenAI Codex. SKILL.md is an open format, so most agents that read a skills directory can load it too.
Yes. Installing skills from SkillMD is free, and the skill stays under its author's original license.
sairam0424 (@sairam0424) published this skill. Their other Agent Skills are listed on their SkillMD profile.