---
title: "Split state by environment and layer · Agent Wranglers"
url: https://agentwranglers.se/playbook/infrastructure/infrastructure-as-code/split-state
updated: 2026-10-20
licence: "All rights reserved"
---

# Split state by environment and layer

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

- Level: Recommended
- Chapter: [Infrastructure as code](https://agentwranglers.se/playbook/infrastructure/infrastructure-as-code)
- Rule: Give each environment and each layer its own state, such as network, data and app. One mistake then touches only one of them.
- How: 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.
- 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.

Example:

```text
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
```

**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`.

- Previous: [Pin the tool and provider versions](https://agentwranglers.se/playbook/infrastructure/infrastructure-as-code/pinned-provider-versions)
- Next: [Reuse versioned modules](https://agentwranglers.se/playbook/infrastructure/infrastructure-as-code/versioned-modules)
- [Infrastructure as code](https://agentwranglers.se/playbook/infrastructure/infrastructure-as-code)
