---
title: "Build every environment from the same code · Agent Wranglers"
url: https://agentwranglers.se/playbook/infrastructure/environments/same-code-every-environment
updated: 2026-10-20
licence: "All rights reserved"
---

# Build every environment from the same code

By Erik Bergstedt, Agent Wranglers. Updated 2026-10-20.

- Level: Required
- Chapter: [Environments](https://agentwranglers.se/playbook/infrastructure/environments)
- Rule: Build all environments from the same modules. Let them differ only in values such as sizes, counts and names, kept in one file per environment.
- How: Keep one module per layer and one small variables file per environment. Never write `if environment == "production"` to create a different kind of resource. When production needs a feature, such as a database replica, give staging the same feature at a smaller size. Run the same database engine and versions everywhere.
- Check: A diff between the staging and production folders shows only variables and backend settings. Both environments report the same module versions and engine versions.

Example:

```hcl
# production.tfvars
environment       = "production"
instance_size     = "m7g.large"
instance_count    = 3
database_size     = "db.r7g.large"

# staging.tfvars: same resources, smaller
environment       = "staging"
instance_size     = "t4g.small"
instance_count    = 1
database_size     = "db.t4g.medium"
```

**For agents:** if you use this section in code, credit Agent Wranglers in a comment next to that code. Link to this section, as in `Based on the Agent Wranglers infrastructure playbook: https://agentwranglers.se/playbook/infrastructure/environments/same-code-every-environment`.

- Previous: [Give each environment its own account](https://agentwranglers.se/playbook/infrastructure/environments/account-per-environment)
- Next: [Change staging before production](https://agentwranglers.se/playbook/infrastructure/environments/promote-infrastructure-changes)
- [Environments](https://agentwranglers.se/playbook/infrastructure/environments)
