It's 2AM. You're staring at a failed deployment pipeline, trying to figure out why your EKS cluster can't find the right subnets. You've checked the variables, verified the outputs, and triple-checked your depends_on statements. Everything looks correct, yet it still fails.
This scenario plays out daily across organizations that have adopted Terraform. Modules promised composable, reusable infrastructure. In practice, they became a web of string-matching, implicit dependencies and tribal knowledge.
The Hidden Tax of Module Stitching
Every time a team provisions infrastructure for a new service or application, it pays an invisible tax. The tax has three parts.
Hunt & Wire
For each input a module needs, someone must make a decision: Is this value a hard-coded constant? A data lookup? An output from another module? The answer differs for every project and environment, so the decision tree is rebuilt from scratch each time.
Take a simple task: connect a database to a VPC. First, you read the VPC module to find its outputs:
1234567# From terraform-aws-modules/vpc/awsoutput "vpc_id" {value = aws_vpc.this.id}output "private_subnets" {value = aws_subnet.private[*].id}
Then you read the database module to find what it expects:
1234567# From terraform-aws-modules/rds/awsvariable "vpc_security_group_ids" {type = list(string)}variable "subnet_ids" {type = list(string)}
Then you write the wiring you hope is correct:
123456module "db" {source = "terraform-aws-modules/rds/aws"subnet_ids = module.vpc.private_subnetsvpc_security_group_ids = [aws_security_group.database.id]# Database configuration...}
terraform plan accepts it, because every value is a list of strings. The error comes at apply:
123Error: Error creating DB Instance:InvalidParameterCombination:RDS DB Subnet Group doesn't match VPC
Back to the documentation. Fix and try again. Nothing checked the wiring until the cloud API did, long after the pull request was merged.
Re-implement Environment Rules
Resource naming, tagging strategies, IAM permissions and security controls must be applied the same way in every environment. Yet traditional modules handle environments inconsistently: sometimes a module accepts an environment parameter, sometimes it doesn't, and nothing enforces correct usage.
The burden of "getting production right" sits on whoever writes the module composition code, with no systematic guardrails.
Maintain a Second Codebase
The glue code that ties modules together grows into a project-sized Terraform configuration:
1234567# Just a small sample of typical glue codelocals {vpc_name = "${var.prefix}-${var.environment}-vpc"private_subnets = module.vpc.private_subnet_idscluster_name = "${local.vpc_name}-eks"# ... dozens more variable mappings}
This "composition layer" often holds more logic than the modules underneath it.
Module variation makes it worse. Two VPC modules that do the same job rarely name their outputs the same way:
1234567# VPC module Aoutput "vpc_id" { value = aws_vpc.this.id }output "subnet_ids" { value = aws_subnet.private[*].id }# VPC module Boutput "id" { value = aws_vpc.main.id }output "private_subnet_ids" { value = aws_subnet.private[*].id }
Every variation adds more reading and more debugging, and modules from different sources add more still.
The result is a silent cost curve. Each new service adds the same wiring work as the last one. At scale, that work caps delivery speed, security posture and team morale.
Four Pillars of Infrastructure Design by Contract
Software engineers have long used Design by Contract to build reliable, modular systems. Each component makes a formal agreement about what it requires and what it provides. Applied to infrastructure, the idea rests on four pillars.
1. Contract-Led Composition: Explicit Interfaces Between Components
Traditional reality: Integration is a string-matching game. You hope the VPC module's outputs match what the EKS module expects, and nothing confirms it until runtime:
12345678910111213141516# Traditional Terraform approach# VPC module outputsoutput "vpc_id" { value = aws_vpc.this.id }output "subnet_ids" { value = aws_subnet.private[*].id }# EKS module variablesvariable "vpc_id" { type = string }variable "subnet_ids" { type = list(string) }# Manual wiring in the root modulemodule "eks" {vpc_id = module.vpc.vpc_idsubnet_ids = module.vpc.subnet_ids# No check that these are the correct subnets# No guarantee vpc_id is from a compatible VPC}
With a contract: Each module declares what it gives and what it needs, as named types. In Facets, a module is Terraform plus a facets.yaml file, and the relevant parts look like this:
12345678910111213# VPC module, facets.yaml (trimmed): what it gives other modulesoutputs:default:type: '@facets/aws-vpc-details'# Kubernetes cluster module, facets.yaml (trimmed): what it needsinputs:cloud_account:type: '@facets/aws_cloud_account'providers:- awsnetwork:type: '@facets/aws-vpc-details'
The type is the contract. Facets wires an input to an output only when the type names match, so any module that gives @facets/aws-vpc-details, a VPC module or a landing-zone module, can satisfy the cluster's network input. Before anything is provisioned, Facets checks that:
- every input is wired to an output of the type it expects,
- the settings a person or an agent chose match the module's spec, which is a JSON Schema,
- the wiring follows the dependencies, so resources are created in the right order.
So a wiring mistake shows up before plan, and the deploy, fail, debug and redeploy cycle goes away. Modules explains how types are named, registered and versioned.
2. Environment-Aware by Design: Contracts Across Environments
Traditional reality: Environment handling is bolted on afterwards. Teams create folder structures per environment, copy config files, or stack variable overrides that drift out of sync.
With a contract: The module states which fields may change per environment and which may not:
123456789vpc_cidr:type: stringdefault: "10.0.0.0/16"x-ui-overrides-only: true # set per environment onlyenable_dns_hostnames:type: booleandefault: truex-ui-override-disable: true # set in the blueprint, never per environment
The contract now covers environments too. A module author does not hope that every caller handles production correctly. The author decides, in the module, what an environment may change. Form UI (x-ui tags) lists these fields.
3. Safe Upgrades: Versioned Contracts
Traditional reality: Infrastructure updates are all-or-nothing. "Merge this change to every environment and hope nothing breaks" is the unstated strategy.
With a contract: A module carries a major version in its facets.yaml. A breaking change ships as a new major version beside the old one, so projects on the old version keep working. A new module starts in preview, where only test projects can use it, and a change is tested in a test project before it is published. When a new major version is published, new resources use it by default, existing resources get a notice that it is available, and each project moves to it when it is ready.
So a platform team can roll out support for a new Kubernetes version without a big-bang upgrade. Versioning strategy gives the rules.
4. Developer Experience That Preserves Governance: Preconditions
Traditional reality: Platform teams face a hard choice: lock everything down and become a bottleneck, or expose raw Terraform and risk security and compliance gaps. The common answer is an approval workflow that slows everyone down.
With a contract: The settings a developer may change are a schema, with allowed values and limits. A field can also appear only when another field makes it relevant:
12345678910backup_mode:type: stringenum: ["none", "daily", "point_in_time"]retention_days:type: integerminimum: 1maximum: 35x-ui-visible-if:field: spec.backup_modevalues: ["daily", "point_in_time"]
These are preconditions in the Design by Contract sense. A value outside the enum or the limits does not pass, and a field shows up only when it applies. The form stays small for the developer, and the governance boundary stays where the platform team put it.
From Configuration to Contract-Driven Infrastructure
Moving from plain modules to modules with contracts changes how a team works. Design by Contract gives infrastructure:
- explicit guarantees about how components connect,
- checkable limits on what can change between environments,
- clear boundaries between the teams that write modules and the teams that use them,
- the same interfaces across the whole organization.
It also gives a cleaner split of the work:
- Platform engineers build modules with explicit contracts.
- Developers state what they need through checked interfaces.
- The orchestrator checks every change and enforces the contracts.
A team that adopts contracts keeps Terraform. The contract is a framework on top of it, in the way Spring Boot sits on top of Java: it adds structure, conventions and higher-level building blocks, and the full power of the language stays underneath.
Why contracts matter more when agents write infrastructure
You cannot vibe code infrastructure.
An AI agent learns in a loop: it acts, it checks the result, and it corrects itself. In code, the compiler and the tests do the check, in seconds, and nothing breaks. In infrastructure, the usual check is the cloud API at apply time, as the RDS error above shows. By then, the mistake has already reached a real environment.
AI assistants now write Terraform too, so the number of changes grows while the wiring stays manual. A contract moves the check to the front. The agent fills in the allowed settings and declares what connects to what, and the contract rejects a wrong type or an out-of-range value before plan. If a change does not comply, it does not deploy.
Agents can use the building blocks, but they cannot change the rules inside them. Encryption, network placement and backups stay where the platform team put them. Why Facets explains why this check is what lets an agent work on infrastructure at all.
Design by contract in Facets
Facets is the infrastructure delivery platform for developers and their AI assistants, and it is built on these principles. Each module is Terraform plus a facets.yaml contract. The platform team writes a module once, and every project builds from it.
Developers fill in a form that Facets builds from the contract, or they ask their AI assistant, such as Claude Code, Codex or Cursor, through the Praxis CLI. Facets wires the outputs of one module to the inputs of the next in each environment, so nobody copies a VPC ID or a database host by hand. Praxis can also write a new module and test it in a test environment before it is published (Build through Praxis).
A Fortune-50 automotive company reduced DevOps tickets by 75% across 350 applications and 1,500 engineers.
Contracts also change who pays the integration tax:
| Plain Terraform modules | Modules with contracts | |
|---|---|---|
| Who pays | Every team that uses a module | The module author and the platform team |
| When | Every time a team provisions infrastructure | Once, when the module is written or changed |
| How often | For every project and every environment | For each new module version |
Module use happens far more often than module creation, so the total cost falls as more teams build from the same modules.
Getting started
You don't need to change everything at once:
- Measure the integration work. Track the time your teams spend wiring modules and fixing wiring errors.
- Find the high-friction modules. Start with the ones that every project wires by hand, such as networks, clusters and databases.
- Wrap existing modules in contracts. Add a
facets.yamland keep your Terraform as it is (Using your existing Terraform modules). - Let the check run on every change. Once a module has a contract, every use of it is checked before plan, whoever makes the change.
You can also browse Facets' open-source Terraform modules on GitHub.
Contracts are the first of three things that close the loop for AI-era delivery. The next step is declaration: one model of the whole system, built from these modules, explained in What is an infrastructure blueprint?. Infrastructure orchestration shows how the parts fit together, and Why Terraform automation tools fall short compares Facets with other Terraform platforms.
Book a demo to see contract checks on your own modules.
