agentleFS
pabloirracionalpabloirracional/claude-skills/skills/writing-terraform-code/SKILL.md

writing-terraform-code

Skill0 starsChanged 4 months agoMITView on GitHub

Writes and reviews Terraform HCL code following standard style conventions, checked against a real HCL parser rather than eyeballed - resource naming, variable/output interfaces, and state safety. Use whenever the user wants to write, review, or refactor Terraform infrastructure-as-code, or mentions .tf files, modules, or provisioning cloud resources with Terraform.

The file

We split this skill into the rules it gives an agent

2 rules. About 0 are common, 0 are distinctive, and 2 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈0

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 2

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Variables and outputs are the module's interface: every variable block needs a description and type.

    line 13
  2. Very specific:

    Plan before apply, always: - never present apply as a one-step action.

    line 16

≈ “Common” is an estimate: at least 1 in 5 of the 364,980 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Writing Terraform code

Writes Terraform that's readable, safely re-runnable, and structured for reuse - checked with a real HCL parser, not just visual review.

Workflow

  1. Resource naming: descriptive, consistent names (aws_instance.web_server, not aws_instance.a) - this is what shows up in every plan/apply output and state file.
  2. Variables and outputs are the module's interface: every variable block needs a description and type; every output needs a description. See the tested validator below - this isn't optional polish, undocumented interfaces are what make a module unreusable by anyone but its author.
  3. Never hardcode values that differ per environment - these belong in .tfvars or variables, not inline in resource blocks.
  4. State safety: warn before suggesting anything that touches state directly (terraform state mv/rm) - these need the user's explicit confirmation.
  5. Plan before apply, always - never present apply as a one-step action.

Tested: HCL structure validation

scripts/example-module/main.tf is a real Terraform module (AWS instances + security group + data source), parsed and structurally checked with python-hcl2 - not just written and assumed correct.

Confirmed parse output:

Variables found: [allowed_cidr_blocks, environment, instance_count]
Resources found: [aws_instance.web_server, aws_security_group.web_server_sg]
Outputs found: [web_server_ids, security_group_id]

No style issues - every variable has description+type, every output has description.

Confirmed the check actually catches problems - ran the same validation against a deliberately incomplete file (variable and output with no description):

2 style issues found:
 - variable 'region' missing description
 - output 'instance_id' missing description

Use this check pattern (parse with python-hcl2 or terraform validate if the CLI is available, then walk variable/output blocks) before considering a module review complete - missing descriptions are easy to miss by eye across a large module and are exactly the kind of thing that makes a module frustrating for the next person.

Notes

  • This environment doesn't have network access to install the Terraform CLI itself, so terraform validate/terraform plan couldn't be run live here - the HCL parsing and structural checks above are real, but full provider-level validation (does this AWS resource configuration actually apply) needs the real CLI against real provider credentials.
  • For repeated resource patterns (e.g. the same config used across environments), suggest extracting a module rather than copy-pasting the block with minor edits.
  • count-based resources (like aws_instance.web_server above) produce a list output (aws_instance.web_server[*].id) - remind the user this becomes a set-like structure that doesn't guarantee element order across applies if the count source changes; for_each with stable keys is safer when identity matters.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.