Environments Required
Build every environment from the same code
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 to do it
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.
Example
# 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"
How to 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.
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.