Skip to content

skillDevOps and cloudterraform

Terraform Module Design

Designs reusable Terraform modules with clear inputs and outputs, a safe state layout, and a plan review before anything is applied.

npx workspacetemplates add terraform-module-design --tool claude-code

Writes 1 file to .claude/skills/terraform-module-design/

.claude/skills/terraform-module-design/SKILL.md27 lines · 1.6 KBFile
---
name: terraform-module-design
description: Designs reusable Terraform modules with clear inputs and outputs, a safe state layout, and a plan review before anything is applied.
---

# Terraform module design

A module is an interface. Design the interface before the resources.

## Steps

1. State the module's purpose in one sentence and list who calls it. If you cannot, it is two modules.
2. Define inputs: typed variables with `description`, `validation` blocks for formats and ranges, and defaults only where one is safe. Prefer a few objects over many loose strings. Leave out arguments no caller needs.
3. Define outputs for every ID, ARN or endpoint another module could need, each with a `description`. Mark credentials `sensitive = true`.
4. Structure files as `main.tf`, `variables.tf`, `outputs.tf`, `versions.tf` (with `required_version` and pinned provider ranges), and an `examples/` directory that is applied in CI.
5. Use `for_each` over a map, not `count` over a list, so removing one item does not recreate the rest. Use `moved` blocks when renaming.
6. Keep state small: one state per environment and per blast radius, in a remote backend with locking. Modules never configure a backend or a provider.
7. Run `terraform fmt -check`, `terraform validate`, and `terraform plan`. Read the plan line by line.

## Rules

- Never run `terraform apply` or `destroy` unless the user asks for it in this conversation.
- Flag every `destroy` or `replace` in the plan, with the attribute that forces it.

## Report

Module interface (inputs and outputs), state layout, and the plan summary: added, changed and destroyed counts.

What it does

A module that exposes every provider argument is just a worse version of the provider. This skill pushes the agent to decide what the module is for, expose only the choices callers should make, and return the outputs other modules will need.

It also treats state as part of the design, not an afterthought: where each module is applied, what shares a state file and what must not. The plan is read and summarized before any apply.

Example

you › Turn the three copies of our VPC code into a module

agent › Created modules/vpc with 6 inputs (cidr, azs, subnet tiers, nat mode) and 7 outputs, plus an example. Replaced the copies with module calls and added moved blocks. Plan for staging: 0 to add, 0 to destroy, 14 moved. Not applied.

Questions

Will it apply changes?
Only if you ask in the conversation. By default it stops at a reviewed plan.
Why for_each instead of count?
With count, deleting the first list item shifts every index, and Terraform plans to recreate the rest. A map keeps each resource tied to its own key.
  • CI Pipeline Speedup

    SkillDevOps and cloud

    Free
  • Deployment Strategies

    SkillDevOps and cloud

    Free