Infrastructure as code Recommended
Split state by environment and layer
Give each environment and each layer its own state, such as network, data and app. One mistake then touches only one of them.
How to do it
Use one folder or stack per environment and layer, each with its own state key. Put slow-changing layers, such as the network and the databases, apart from the app layer that changes often. Pass values between layers through outputs or a parameter store, never by copying IDs. Keep a plan under 2 minutes. When it runs longer, split the state again.
Example
infra/
modules/ shared building blocks
staging/network/ key: staging/network.tfstate
staging/app/ key: staging/app.tfstate
production/network/ key: production/network.tfstate
production/app/ key: production/app.tfstate
How to check
Every backend key names exactly one environment. state list in any app state shows no database or network resources. Each plan finishes in under 2 minutes.
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/infrastructure-as-code/split-state.