agentleFS
RoninForgeRoninForge/roninforge-terraform/skills/terraform-new-module/SKILL.md

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

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
  1. Distinctive:

    When creating a new reusable module (e.g.

    line 10
  2. Distinctive:

    Create the directory layout:

    line 16
  3. Very specific:

    Write variables.tf with type, description, and validation on every input:

    line 47
  4. Very specific:

    Write main.tf with for_each over count, explicit tagging, no hardcoded values:

    line 66
  5. Very specific:

    Write outputs.tf with curated, named outputs:

    line 82
  6. Very specific:

    Add a simple example under examples/simple/:

    line 93
  7. Very specific:

    Add a *.tftest.hcl file under tests/:

    line 105
  8. Distinctive:

    Commit and tag a release:

    line 130
  9. Very specific:

    Never count = length(var.things) for stable collections - use for_each = toset(var.things).

    line 139
  10. Very specific:

    Never embed 0.0.0.0/0 in module defaults (validate it out at the variable).

    line 140
  11. Very specific:

    Never declare provider "aws" inside the module - the caller configures the provider.

    line 141
  12. Distinctive:

    Never output the raw resource object - curate the public surface.

    line 142
  13. Very specific:

    Never ~> pin the engine inside a module - use >= and let root modules pin.

    line 143
  14. Very specific:

    Never accept variable "extra" { type = any } as an escape hatch - design real inputs.

    line 144

≈ “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.

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

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

  1. Decide the module name and primary resource. Use a single-noun name: vpc, rds, ecs-service. Avoid aws-vpc-network-module.
  2. 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.hcl
  3. Write versions.tf:

    terraform {
      required_version = ">= 1.5"
      required_providers {
        aws = {
          source  = "hashicorp/aws"
          version = ">= 5.0"
        }
      }
    }
  4. Write variables.tf with type, description, and validation on 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     = {}
    }
  5. Write main.tf with for_each over count, 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 })
    }
  6. Write outputs.tf with 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.

  7. Add a simple example under examples/simple/:

    # examples/simple/main.tf
    provider "aws" { region = "eu-central-1" }
    
    module "thing" {
      source = "../../"
      name   = "demo"
    }
  8. Add a *.tftest.hcl file under tests/:

    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"
      }
    }
  9. Generate the README with terraform-docs:

    terraform-docs markdown table --output-file README.md --output-mode inject .
  10. 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 - use for_each = toset(var.things).
  • Never embed 0.0.0.0/0 in 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.

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.