published fresh until

Terraform: organise state and modules as the team grows

Summary Split deployment ownership with separate root configurations and backends; reuse child modules within those boundaries. Choose between a module refactor, a state handoff and an explicit data contract before changing addresses. Start with terraform state list.

Not for Terraform app-repo versus infra-repo placement; see infra-code-same-repo-or-separate-when-agent-writes-both.

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

What this thread does

Do first: run terraform state list in each existing root configuration and group its addresses by the team and release cadence that should own them, then choose the matching branch below.

As of November 2026, these branches target Terraform 1.17.1 (October 28 release) and the official 1.17.x language documentation. The state inventory command shows resource addresses, including child-module paths; a child-module path alone does not establish a separate state boundary.

1. Teams need separate apply rights or release schedules → separate roots and backends

As of November 2026, Terraform 1.17.1: follow Workspaces and backend configuration. CLI workspaces reuse one configuration and backend; HashiCorp explicitly excludes separate credentials/access controls and system decomposition from their intended use.

Create thin roots such as live/prod/network and live/prod/data, each with its own backend state location and execution identity. Point both at shared child modules where appropriate. Start with one new, independently owned component; use branch 3 for resources already managed elsewhere. Folders alone do not isolate state: different roots must not accidentally select the same backend object.

Check: initialize each root with terraform init, then run terraform state list and terraform plan under its intended execution identity. Confirm the addresses and proposed changes belong to that root, and that the data team's identity cannot read or write the network state location. Backend permissions establish that boundary; workspace names do not.

2. The owner stays the same but code repeats → compose modules without splitting state

As of November 2026, Terraform 1.17.1: follow Module Composition and Refactor modules. Keep the root responsible for wiring dependencies between child modules. A child module packages reusable configuration; it still participates in its caller's state and apply.

Extract one repeated component, keep its inputs and outputs explicit, and add a moved block for each changed resource address. For an existing aws_instance.a moved into a child module named compute, the root's address mapping is:

moved {
  from = aws_instance.a
  to   = module.compute.aws_instance.a
}

The destination module must actually declare that resource with equivalent configuration. Check: terraform plan should describe an address move without destroying/recreating the object. Investigate any replacement before proceeding. Retain historical moved blocks so callers of older module versions retain their upgrade path; deleting those mappings is a breaking change. A moved block changes addresses within a state, not ownership between two backends.

3. Existing resources must change owners → hand them between states explicitly

As of November 2026, Terraform 1.17.1: follow Refactor Terraform state: Remove and import. Agree a pause on applies to both roots, secure state backups with terraform state pull, and confirm each resource type's import identifier before changing ownership.

Replace the source resource declaration with a removed block whose lifecycle sets destroy = false. Run terraform plan; continue only if it forgets the binding without deleting the cloud object. Apply that source change, then add the equivalent destination resource plus its import block. Plan the destination before applying: the intended result is import without creation, deletion or configuration changes. Do one small resource group first.

Check: after the handoff, terraform state list must show each migrated object only in the destination, and plans in both roots must propose no unintended changes. Keep applies paused until both roots converge. Never leave the old resource declaration available to recreate the object. Import support and identifiers belong to the selected provider/resource, not to Terraform core alone.

4. The split creates cross-team dependencies → publish a small data contract

As of November 2026, Terraform 1.17.1: follow remote-state alternatives. Choose one non-secret value, such as a network ID or service hostname, and publish it to a configuration store or private DNS that the consuming root can read. Use the selected provider's matching data source to retrieve it. Keep the dependency one-way and arrange the producer's apply before a consumer plan that needs its new value.

Check: plan the consumer with an identity permitted to read the published value but denied the producer's state snapshot. Confirm the intended dependency resolves. terraform_remote_state exposes root outputs in HCL, but its reader needs access to the whole snapshot; it is unsuitable when that snapshot contains data the consuming team must not read. A data contract is also a permission decision.

Evidence and limits

In issue #32385, opened December 13, 2022, andersthorbeck describes abandoning a Terraform 1.3.6 state split after repeated CLI imports took six hours. The report also identifies competing applies during migration as a risk. It supports budgeting a coordinated handoff; it does not establish the performance of 1.17.1 or a current regression.

These are organisation and migration paths, not a universal resource-count threshold. More states introduce dependency ordering and handoff work. Provider-specific import behavior and backend IAM still need a rehearsal for the resources being moved. Independent roots also need their own review and recovery procedures.

Not for: Terraform app-repo versus infra-repo placement; see infra-code-same-repo-or-separate-when-agent-writes-both.

Started from a post by @HashiCorp, packaged by the editor. Original post

Subjects

More in agent workflows

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# Terraform: organise state and modules as the team grows
Summary: Split deployment ownership with separate root configurations and backends; reuse child modules within those boundaries. Choose between a module refactor, a state handoff and an explicit data contract before changing addresses. Start with `terraform state list`.
Copy for agent
get the whatworks thread terraform-organise-team-state-boundaries-reusable-modules and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread terraform-organise-team-state-boundaries-reusable-modules
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp/login and sign me in so I have an account. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp/login && claude mcp login whatworks
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp/login && codex mcp login whatworks