terraform-new-module
Skill0 starsChanged 7 months agoMITView on GitHub
Scaffold a reusable Terraform / OpenTofu module: versions.tf with required_version + required_providers, variables.tf with typed + validated inputs, outputs.tf with curated outputs, main.tf with for_each + tagging, README + examples/ + tests/.
- Commits and pushes
In this repository3 other files it gives its agents.
The file
Show its rules and text
We split this skill into the rules it gives an agent
14 rules. About 0 are common, 4 are distinctive, and 10 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈4
Distinctive · estimate
This author's own choices. Worth a look.
10
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 10
When creating a new reusable module (e.g.
- Distinctive: line 16
Create the directory layout:
- Very specific: line 47
Write variables.tf with type, description, and validation on every input:
- Very specific: line 66
Write main.tf with for_each over count, explicit tagging, no hardcoded values:
- Very specific: line 82
Write outputs.tf with curated, named outputs:
- Very specific: line 93
Add a simple example under examples/simple/:
- Very specific: line 105
Add a *.tftest.hcl file under tests/:
- Distinctive: line 130
Commit and tag a release:
- Very specific: line 139
Never count = length(var.things) for stable collections - use for_each = toset(var.things).
- Very specific: line 140
Never embed 0.0.0.0/0 in module defaults (validate it out at the variable).
- Very specific: line 141
Never declare provider "aws" inside the module - the caller configures the provider.
- Distinctive: line 142
Never output the raw resource object - curate the public surface.
- Very specific: line 143
Never ~> pin the engine inside a module - use >= and let root modules pin.
- Very specific: line 144
Never accept variable "extra" { type = any } as an escape hatch - design real inputs.
≈ “Common” is an estimate: at least 1 in 5 of the 213,897 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.
Files
Scaffold Terraform Module
When to Use
When creating a new reusable module (e.g. VPC, RDS, ECS service) that will be consumed by multiple root modules.
Instructions
- Decide the module name and primary resource. Use a single-noun name:
vpc,rds,ecs-service. Avoidaws-vpc-network-module. Create the directory layout:
modules/<name>/ ├── README.md ├── versions.tf ├── variables.tf ├── main.tf ├── outputs.tf ├── examples/ │ └── simple/ │ ├── main.tf │ └── README.md └── tests/ └── <name>.tftest.hclWrite
versions.tf:terraform { required_version = ">= 1.5" required_providers { aws = { source = "hashicorp/aws" version = ">= 5.0" } } }Write
variables.tfwithtype,description, andvalidationon every input:variable "name" { description = "Logical name (used as a tag prefix and identifier)" type = string validation { condition = can(regex("^[a-z][a-z0-9-]{1,30}$", var.name)) error_message = "name must be lowercase + hyphen, 2-31 chars" } } variable "tags" { description = "Tags merged onto every resource the module manages" type = map(string) default = {} }Write
main.tfwithfor_eachovercount, explicit tagging, no hardcoded values:locals { module_tags = merge( var.tags, { Module = "<name>", ManagedBy = "Terraform" }, ) } resource "aws_<thing>" "this" { # ... per-resource args tags = merge(local.module_tags, { Name = var.name }) }Write
outputs.tfwith curated, named outputs:output "id" { description = "ID of the created <thing>" value = aws_<thing>.this.id }Mark anything secret-bearing
sensitive = true. Better: do not output secrets at all.Add a simple example under
examples/simple/:# examples/simple/main.tf provider "aws" { region = "eu-central-1" } module "thing" { source = "../../" name = "demo" }Add a
*.tftest.hclfile undertests/:run "rejects_invalid_name" { command = plan variables { name = "Invalid Name With Spaces" } expect_failures = [var.name] } run "plans_cleanly_with_valid_inputs" { command = plan variables { name = "test" } assert { condition = aws_<thing>.this.tags["Name"] == "test" error_message = "Name tag did not propagate" } }Generate the README with
terraform-docs:terraform-docs markdown table --output-file README.md --output-mode inject .Commit and tag a release:
git tag v0.1.0 git push origin v0.1.0
Anti-patterns to avoid
- Never
count = length(var.things)for stable collections - usefor_each = toset(var.things). - Never embed
0.0.0.0/0in module defaults (validate it out at the variable). - Never declare
provider "aws"inside the module - the caller configures the provider. - Never output the raw resource object - curate the public surface.
- Never
~>pin the engine inside a module - use>=and let root modules pin. - Never accept
variable "extra" { type = any }as an escape hatch - design real inputs.
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
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.

