How should Terraform state be split across environments and infrastructure layers?

0
0
Asked By MellowCedar42 On

For production Terraform setups, how do you organize state within each environment? Do you keep networking, DNS, Kubernetes clusters, and databases in one state, or split them into independent layers such as dev/01-networking, dev/02-dns, dev/03-eks, and dev/04-database, with a separate state file for each? I'm particularly interested in how you balance modularity, state-lock contention, blast radius, ownership, and operational complexity.

4 Answers

Answered By SunnyRook_56 On

Separate states per environment and stack have worked well for us. A stack should represent a coherent unit with clear ownership and a manageable change scope. This makes reviews and selective applies safer, especially when an urgent or previously unreviewed change needs to be isolated.

Answered By CobaltMango88 On

Separating layers can make plans faster and reduce state-lock contention when multiple teams work at the same time. It also helps when different parts of the platform need different execution environments—for example, public runners handling initial networking while private runners create resources inside a private cluster. Just avoid creating so many tiny states that ordinary changes become cumbersome.

Answered By QuartzHarbor7 On

A useful rule is to keep resources together when they’re provisioned and removed together. Otherwise, split state around failure domains, ownership, and how frequently components change. Networking, clusters, and databases are often good candidates for separate states so routine application changes don’t risk critical infrastructure.

Answered By BriskLynx_31 On

There isn’t one universal layout. A structure like dev/landing-zone, dev/app1, and dev/app2 can work well when each stack has clear ownership and a limited blast radius. Organizing by application or use case is often more practical than organizing strictly by resource type.

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.