# Terraform

> Use for Terraform and HCL infrastructure-as-code work. Covers writing and reviewing HCL to HashiCorp's style guide (file layout, naming, variables and outputs, for_each vs count, version pinning), writing and running tests with .tftest.hcl (run and assert blocks, mock providers, CI wiring), refactoring monolithic configs into reusable modules (interface design, moved-block state migration), and authoring Terraform Stacks (.tfcomponent.hcl and .tfdeploy.hcl components, deployments, linked Stacks). Read the matching reference before writing or reviewing Terraform.

- Skill: `jylhis/terraform` (Agent Skill, multi-file: 15 files)
- Install (CLI): `npx skillmds@latest add jylhis/terraform`
- Raw SKILL.md: https://api.skillmd.com/api/skills/jylhis/terraform/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: DevOps & Infra
- Author: Jylhis (https://skillmd.com/u/jylhis)
- Updated: 2026-09-17
- Page: https://skillmd.com/skills/jylhis/terraform

---


# Terraform

Opinionated Terraform guidance, split by task. This file routes; the detail
lives in `references/`. Load only the reference for the task at hand.

| Task | Read |
|------|------|
| Writing or reviewing HCL (style, layout, naming, variables, outputs, `for_each`, version pinning) | `references/style-guide.md` (plus `references/security.md`) |
| Writing or running module tests (`.tftest.hcl`, run/assert blocks, mock providers, CI) | `references/test.md` (plus `references/test/`) |
| Refactoring monolithic config into reusable modules (interfaces, `moved` state migration) | `references/refactor-module.md` |
| Authoring Terraform Stacks (`.tfcomponent.hcl`, `.tfdeploy.hcl`, deployments, linked Stacks) | `references/stacks.md` (plus `references/stacks/`) |

## Conventions

- Format and validate before every commit: `terraform fmt -recursive` then `terraform validate`.
- Prefer `for_each` over `count` for multiple resources; reserve `count` for conditional creation.
- Every variable and output carries a `type` (variables) and a `description`; mark secrets `sensitive = true`.
- Pin `required_version` and provider versions; commit `.terraform.lock.hcl`, never state files or `.terraform/`.

Attribution: the reference bodies are adapted from HashiCorp agent-skills
(`hashicorp/agent-skills`, MPL-2.0; portions Copyright IBM Corp. 2026).

