- Home
- Skills
- DevOps & Cloud
- Terraform and OpenTofu Module Design
Terraform and OpenTofu Module Design
Designs Terraform or OpenTofu modules: interfaces, providers, state boundaries, environments and safe planned changes.
$5
Works with the AI tools you already use
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
| Criterion | Why it matters here | Weight | Source of the weight |
|---|---|---|---|
| Blast Radius & State Isolation | Modifying subnet routing or firewall rules must not trigger destructive recreation of database subnets. | 0.35 | Alex Mercer (Platform Guild) |
| Non-Destructive Refactoring | Upgrading from v1.x to v2.0 must preserve existing AWS resource IDs without downtime or rebuilds. | 0.30 | Marcus Vance (Infra SRE) |
| Multi-Environment Adaptability | Support cost-optimized single NAT in staging while enforcing 3-AZ high availability in production. | 0.20 | Cloud Platform requirement |
| Dual-Engine Tooling Support | Module code must remain interoperable across OpenTofu 1.8 and Terraform 1.9. | 0.15 | Architecture Board mandate |
Comparison
| Architecture Dimension | Proposal A (Monolithic In-line) | Proposal B (Chosen Contract) | Justification |
|---|---|---|---|
| CIDR Allocation | Hardcoded 10.0.0.0/16 defaults | Parameterized with validation | Hardcoded CIDRs prevent peering and multi-region transit gateway expansion. |
| Security Group Placement | In-line aws_security_group resources | Decomposed outside VPC module | Decouples network route lifecycle from application port rules. |
| State Migration Path | Manual terraform state mv scripts | Declarative moved blocks | Declarative moved blocks eliminate error-prone manual CLI state edits in CI/CD. |
| NAT Topology Control | Hardcoded 3 NAT Gateways | Variable enable_nat_per_az = bool | Saves 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_tieraws_subnet.private→aws_subnet.application_tieraws_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
| Claim | Classification | Source | Freshness |
|---|---|---|---|
3-tier VPC across 3 AZs in us-east-1 | provided | Intake specification | Current |
| OpenTofu 1.8 & Terraform 1.9 compatibility | provided | Intake specification | Current |
AWS Provider ~> 5.50 | decided | Platform Guild Standard | 2026-09-15 |
| Single NAT Gateway for non-prod | provided | Request rule | Current |
| Rejection of hardcoded CIDRs | decided | Alex Mercer & Marcus Vance | 2026-09-15 |
Non-destructive migration via moved blocks | decided | Architectural invariant INV-TF-01 | 2026-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.50and documented tooling compatibility. - Validation Guard: PASS. Variable
vpc_cidrvalidates IPv4 CIDR and enforces the/20boundary. - Refactoring Safety: PASS. Declarative
movedmappings 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
- Alex Mercer and Platform team run
tofu testandterraform testin an ephemeral sandbox AWS account. - Verify the v1-to-v2 upgrade plan against a clone of staging state to validate zero resource destruction.
- Publish
terraform-aws-network v2.0.0release tag to the internal private module registry.
terraform-and-opentofu-module-design.tsx
TSX · React component
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
About this skill
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
- Check Terraform/OpenTofu state management is required.
- Define root and child module boundaries.
- Pin provider source addresses and versions.
- Establish remote state backend and locking.
- Formulate resource identity and iteration.
- 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.
- 1
Download the ZIP
Free skills download straight away. Paid skills unlock right after purchase.
- 2
Unzip into your skills folder
Every agent reads skills from one folder on your machine. Drop the unzipped folder in there.
- 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