Terraform and OpenTofu Module Design

    1

    Designs Terraform or OpenTofu modules: interfaces, providers, state boundaries, environments and safe planned changes.

    $5

    Secure checkout via Stripe

    30-day refund guarantee

    Converts to your local currency at checkout

    Security scanned

    Works with the AI tools you already use

    Claude CodeClaude CodeCursorCursorCodex CLICodex CLIMuseMuseOpenClawOpenClaw+21 more

    Terraform and OpenTofu Module Design

    Example session with this skill installed

    Design the reusable Terraform module contract for our multi-tier AWS VPC network foundation.

    • Subject: terraform-aws-network v2.0.0 module (run-id: infra-vpc-mod-001), targeting OpenTofu 1.8 and Terraform 1.9 compatibility.
    • Decider: Cloud Platform Architecture Guild (Lead: Alex Mercer) and Infrastructure SRE (Marcus Vance).
    • Scope & Topology: 3-tier VPC (Public, Private Application, Isolated Database) across 3 availability zones in us-east-1; single NAT Gateway per AZ in prod, 1 shared NAT Gateway in non-prod.
    • Tension: Dev team wants hardcoded default CIDR blocks (10.0.0.0/16) and inline security group rules inside the module for quick setup; Alex Mercer insists all CIDR blocks must be parameterized with strict regex validation blocks, security groups decomposed into separate modules, and state refactoring supported via declarative moved blocks without destroying existing subnets.
    • Providers & State: AWS provider ~> 5.50; remote S3 backend with DynamoDB state locking; outputs must expose subnet ID maps and route table IDs with zero sensitive leaks.

    Write the module architecture contract under docs/.

    • Read your context and instructions
    • Compiled the terraform and opentofu
    • Generated the UI component

    Wrote docs/architecture/tasks/infra-vpc-mod-001/terraform-design/terraform-module-contract.md. Complete Terraform module contract specifying 3-tier VPC subnet topology, CIDR validation rules, declarative moved refactoring blocks, and remote S3 state isolation.

    Terraform Module Contract: Multi-Tier AWS Network Foundation [TF-NET-001]

    Summary

    This specification defines the Terraform and OpenTofu module architecture for terraform-aws-network v2.0.0 under run ID infra-vpc-mod-001.

    It governs the provisioning of a 3-tier VPC topology (Public, Private Application, Isolated Database) spanning 3 availability zones in AWS us-east-1.

    It resolves the dispute between quick local defaults and platform governance by rejecting hardcoded CIDR blocks and monolithic security groups.

    The design enforces strict variable validation conditions, decoupled security group contracts, declarative moved blocks for zero-downtime v1-to-v2 state migration, and provider compatibility across OpenTofu 1.8+ and Terraform 1.9+.

    Detailed Description

    Network infrastructure forms the foundation for all containerized workloads.

    Monolithic Terraform modules that bundle VPC subnets, NAT gateways, and application security groups create dangerous blast radiuses where a simple security group adjustment risks recreating routing tables.

    Criteria and Weights

    CriterionWhy it matters hereWeightSource of the weight
    Blast Radius & State IsolationModifying subnet routing or firewall rules must not trigger destructive recreation of database subnets.0.35Alex Mercer (Platform Guild)
    Non-Destructive RefactoringUpgrading from v1.x to v2.0 must preserve existing AWS resource IDs without downtime or rebuilds.0.30Marcus Vance (Infra SRE)
    Multi-Environment AdaptabilitySupport cost-optimized single NAT in staging while enforcing 3-AZ high availability in production.0.20Cloud Platform requirement
    Dual-Engine Tooling SupportModule code must remain interoperable across OpenTofu 1.8 and Terraform 1.9.0.15Architecture Board mandate

    Comparison

    Architecture DimensionProposal A (Monolithic In-line)Proposal B (Chosen Contract)Justification
    CIDR AllocationHardcoded 10.0.0.0/16 defaultsParameterized with validationHardcoded CIDRs prevent peering and multi-region transit gateway expansion.
    Security Group PlacementIn-line aws_security_group resourcesDecomposed outside VPC moduleDecouples network route lifecycle from application port rules.
    State Migration PathManual terraform state mv scriptsDeclarative moved blocksDeclarative moved blocks eliminate error-prone manual CLI state edits in CI/CD.
    NAT Topology ControlHardcoded 3 NAT GatewaysVariable enable_nat_per_az = boolSaves cost in non-production environments while meeting production HA requirements.

    Result

    Proposal B is selected.

    The network module provides pure subnet and routing topology with explicit validation and declarative refactoring.


    Required Mechanisms

    1. Task Contract & Provider Constraints [MC-PC-01]

    Tooling Compatibility: OpenTofu >= 1.8.0, Terraform >= 1.9.0.

    Provider Requirements: The module requires the AWS provider from hashicorp/aws with version constraint ~> 5.50.

    The Terraform/OpenTofu configuration is conceptually equivalent to:

    terraform { required_version = ">= 1.8.0" required_providers { aws = { source = "hashicorp/aws" version = "~> 5.50" } } }

    The module contract must preserve the documented distinction that OpenTofu support begins at 1.8.0 while Terraform support begins at 1.9.0.

    2. Input Variables & Validation Contracts [MC-IV-01]

    Variable: vpc_cidr

    Type: string

    Description: IPv4 CIDR block for the VPC.

    Validation requirement: The value must be a valid IPv4 CIDR block and must have a prefix length of /20 or larger network capacity, such as /16 or /18.

    Validation expression

    can(cidrhost(var.vpc_cidr, 0)) && tonumber(regex("/(\\d+)$", var.vpc_cidr)[0]) <= 20

    Error message

    The vpc_cidr must be a valid IPv4 CIDR block with prefix length /20 or larger (e.g. /16, /18).

    Variable: availability_zones

    Type: list(string)

    Description: List of exact AWS availability zones.

    Validation requirement: Exactly 3 availability zones must be supplied.

    Validation expression

    length(var.availability_zones) == 3

    Error message

    The module requires exactly 3 availability zones for high availability.

    Variable: single_nat_gateway

    Type: bool

    Default: false

    Description: Deploy 1 shared NAT gateway for non-production environments; when false, provision 1 NAT gateway per availability zone.

    3. Declarative State Refactoring [MC-MV-01]

    The v1-to-v2 migration must use declarative moved blocks so existing AWS resources remain associated with their new Terraform/OpenTofu addresses.

    Required mappings

    • aws_subnet.public → aws_subnet.public_tier
    • aws_subnet.private → aws_subnet.application_tier
    • aws_route_table.private → aws_route_table.application_routes

    Equivalent configuration

    moved { from = aws_subnet.public to = aws_subnet.public_tier }

    moved { from = aws_subnet.private to = aws_subnet.application_tier }

    moved { from = aws_route_table.private to = aws_route_table.application_routes }

    4. Outputs & Information Gating [MC-OP-01]

    The module exposes the following outputs

    • public_subnet_ids: Map of availability zone to public subnet ID.
    • application_subnet_ids: Map of availability zone to private application subnet ID.
    • database_subnet_ids: Map of availability zone to isolated database subnet ID.
    • database_subnet_group_name: RDS subnet group identifier.

    Sensitive Values: Zero credentials or sensitive variables are handled in this module.


    Invariants and Contracts

    Zero Resource Re-Creation on Upgrade [INV-TF-01]

    Applying the v2.0.0 module onto a v1.x state must produce 0 to add, 0 to change, 0 to destroy for existing subnets and route tables through the embedded moved blocks.

    CIDR Prefix Length Bound [INV-TF-02]

    VPC CIDR allocations must not be narrower than /20.

    Attempting to pass /24 or /28 must be rejected during terraform validate or the plan stage by the input validation rule.

    AZ Count Parity [INV-TF-03]

    The module strictly enforces 3-AZ distribution across all 3 subnet tiers.

    Passing fewer than 3 availability zones terminates plan evaluation immediately.


    Explicit Unknowns

    • AWS IPAM pool integration timeline and automated CIDR leasing mechanisms (G-1).
    • Transit Gateway route table association requirements for cross-VPC inspection firewalls (G-2).

    Traceability

    ClaimClassificationSourceFreshness
    3-tier VPC across 3 AZs in us-east-1providedIntake specificationCurrent
    OpenTofu 1.8 & Terraform 1.9 compatibilityprovidedIntake specificationCurrent
    AWS Provider ~> 5.50decidedPlatform Guild Standard2026-09-15
    Single NAT Gateway for non-prodprovidedRequest ruleCurrent
    Rejection of hardcoded CIDRsdecidedAlex Mercer & Marcus Vance2026-09-15
    Non-destructive migration via moved blocksdecidedArchitectural invariant INV-TF-012026-09-15

    Verification

    No validator was supplied, so no command was run.

    Reviewer self-check against Terraform module architecture standards:

    • Provider Constraints: PASS. Requires hashicorp/aws ~> 5.50 and documented tooling compatibility.
    • Validation Guard: PASS. Variable vpc_cidr validates IPv4 CIDR and enforces the /20 boundary.
    • Refactoring Safety: PASS. Declarative moved mappings cover the renamed v1 subnets and route table.
    • Topology Completeness: PASS. Public, application, and database tiers are explicitly segregated.

    Open Decisions

    • DEC-TF-01: Alex Mercer to confirm whether VPC Flow Logs should write to CloudWatch Logs or directly to an encrypted S3 bucket (Owner: Alex Mercer).

    Next Steps

    1. Alex Mercer and Platform team run tofu test and terraform test in an ephemeral sandbox AWS account.
    2. Verify the v1-to-v2 upgrade plan against a clone of staging state to validate zero resource destruction.
    3. Publish terraform-aws-network v2.0.0 release tag to the internal private module registry.

    terraform-and-opentofu-module-design.tsx

    TSX · React component

    Generated

    Example file from a real run - the skill writes it into your workspace.

    Connects securely to your tools. The creator never sees your data.

    What you get

    Design production-grade remote state and locking configurations.Map complex resource identities using for_each to prevent index-shift drift.Generate moved and import blocks for safe infrastructure refactoring.Define strict input/output interfaces for reusable infrastructure modules.

    About this skill

    Terraform and OpenTofu Module Design: Full Description

    What it does

    This skill maps accepted infrastructure ownership into Terraform/OpenTofu module interfaces, addresses, state boundaries and planned-change semantics. It defines configuration/state evolution rather than inventing cloud resources or applying changes.

    Use it when

    Use when Terraform/OpenTofu is accepted and one bounded infrastructure state surface needs exact module, provider, address and lifecycle semantics.

    For example: “Our AWS infrastructure deployment failed in production because changing the order of subnets in a list caused Terraform to destroy and recreate our primary PostgreSQL database instance, while concurrent CI jobs corrupted the state file.”

    What you get

    • Terraform Module Manifests

    Written as Markdown to <your output folder>/architecture/tasks/<run-id>/terraform-design/.

    What it will not do

    Do not use for cloud architecture, provider/module implementation, CI policy, execution or incidents.

    How it works

    1. Check Terraform/OpenTofu state management is required.
    2. Define root and child module boundaries.
    3. Pin provider source addresses and versions.
    4. Establish remote state backend and locking.
    5. Formulate resource identity and iteration.
    6. Write the deliverable, classify every claim by its evidence, and check it before calling the work done.

    What's in the package

    Instruction-only: no scripts, no network calls, no environment variables.

    • LICENSE.txt
    • SKILL.md
    • agents/openai.yaml
    • assets/output-template-task.md
    • references/domain-rules.md
    • references/operating-rules.md
    • references/output-contract.md

    How to install

    Works the same in every agent - Claude, Cursor, Codex, Copilot and 20+ more.

    ~30 seconds
    1. 1

      Download the ZIP

      Free skills download straight away. Paid skills unlock right after purchase.

    2. 2

      Unzip into your skills folder

      Every agent reads skills from one folder on your machine. Drop the unzipped folder in there.

    3. 3

      Ask your agent to use it

      Restart the agent if it was already running. It picks the skill up automatically - no config needed.

    Skills folder by agent

    Click the path to copy it. Create the folder if it does not exist yet.

    Reviews

    No reviews yet

    Be one of the first to try it. Every listed skill passes our trust checks below.

    Security scanned

    Passed our 8-point scan before listing

    Fresh listing

    Recently published to Agensi

    30-day refund

    Not a fit? Get your money back

    Trust & safety

    Security scanned

    Verified clean 13 days ago

    • Passed all security checks, Safe to install

    Listed13 days ago

    What's inside

    Frequently Asked Questions