Splitting state and limiting blast radius

Advanced · 25 min

Cut Terraform state by rate of change, ownership, access and cost of a mistake, pass values between layers, and stop before the cuts get too small.

Before thisTerragrunt and keeping config DRYRemote backends: S3, GCS and azurerm

HashiCorp, an IBM Company · 25 min

Splitting state and limiting blast radius

The player loads from youtube-nocookie.com when you press play. Nothing reaches YouTube before that.

Taught by HashiCorp, an IBM CompanyReport a problem with this video
Not started
Set this lesson's status

What you'll learn

  • Blast radius is what one plan or apply can read, change or break; one big state makes it everything.
  • Cut along rate of change, ownership, who may touch it, and cost of a mistake; layers such as network, data, platform and app are the usual result.
  • terraform_remote_state needs read access to the whole other state, while a data source lookup avoids that coupling but needs a tagging convention.
  • Cross-state order is not known to Terraform: use a script, Terragrunt or a platform, and treat published outputs as an API.

The plan that touched everything

Picture a team that put its network, database, cluster and application into a single root module. It is convenient: one apply, one state, every reference in one place. Then someone edits a security group rule and runs a plan. Terraform refreshes every resource the module owns before it shows a one-line diff, and the plan sits at “Refreshing state…” for as long as the cloud API takes to answer a few hundred times. This is a composite, not a story from one team. The same state is also one wrong terraform destroy -target away from the production database.

That is the whole argument for splitting state. A blast radius is what one run can change or break. One state means every plan reads everything and every apply can write anything. Smaller states mean smaller plans, smaller credentials and mistakes that stop at the edge of the component.

How big is “one thing”

I looked at a real module to get a sense of scale. The registry API reports that terraform-aws-modules/vpc/aws version 6.9.0, published 25 November 2026, declares 79 resource blocks, and the EKS module 21.30.2 declares 25 plus seven submodules. A resource block can create many instances through count and for_each, so 79 declarations in a real VPC can be hundreds of objects. I fetched these numbers with curl from registry.terraform.io/v1/modules/....

Nobody has a rule of thumb that holds everywhere, but the questions that decide a cut are well known.

Where to cut

Cut along things that differ in one of four ways:

  1. Rate of change. The VPC changes twice a year. The application’s task definition changes ten times a day. Putting them in one state means the daily change always carries the VPC along.
  2. Who owns it. If the platform team owns the network and an app team owns its service, they should not share a state and a lock.
  3. Who may touch it. A role that can modify IAM and the production database should not be the credential CI uses to roll out a new container image.
  4. Cost of a mistake. Stateful and hard-to-recreate things (databases, DNS zones, state buckets) in a state of their own, with prevent_destroy, lifecycle rules and few people allowed to apply.

A common result is layers, applied from the bottom up:

envs/prod/
  00-bootstrap/     # state bucket, CI role     (rarely)
  10-network/       # VPC, subnets, routes      (rarely)
  20-data/          # databases, queues         (carefully)
  30-platform/      # cluster, shared services  (weekly)
  40-app/           # services, task defs       (daily)

The numbered prefix is a convention, not a feature. It records the dependency order for humans.

How the pieces talk to each other

Split states still need to share values: the app needs the subnet IDs the network created. There are two ways to pass them.

terraform_remote_state. The app reads the network’s state as a data source:

data "terraform_remote_state" "network" {
  backend = "s3"
  config = {
    bucket = "acme-tf-state"
    key    = "prod/network/terraform.tfstate"
    region = "eu-west-1"
  }
}

# data.terraform_remote_state.network.outputs.private_subnet_ids

It is simple, and it has a cost the docs call out: to read outputs, the reader needs permission to read the entire state of the other component, secrets included. It also couples the reader to the other state’s backend and key.

Look it up at plan time. The app queries the cloud for what it needs, with a data source that finds the VPC by tag, or reads a value from a parameter store the network wrote. There is no direct state coupling. The cost is a tag convention you now have to keep.

I wrote the HCL above from the documentation and did not run it. Neither approach is free: a layer that publishes outputs is an interface, and changing an output name is a breaking change for every consumer. Treat outputs like an API, and use them sparingly.

The order problem

The layers form a dependency graph, and Terraform does not know about it across states. If 40-app reads 10-network’s output and someone destroys the network first, the app’s next plan fails or, worse, succeeds against stale data. Something has to run the layers in order. Options are a Makefile or CI job that lists directories in order, Terragrunt, which reads dependency blocks, or a platform with stacks. Pick one early. A hand-run order held in someone’s memory is how split states go wrong.

When splitting goes too far

Cutting too small has its own costs: a change that spans two layers is two pull requests, two applies and a window where they disagree. Every output you publish is a contract. If you are constantly editing three directories for one feature, the cut is in the wrong place. Moving a resource from one state to another afterwards is possible, using the state commands and moved blocks, but it is a careful operation, so cut where you will not need to move things often.

About the video

The embed is HashiCorp’s “Reducing blast radius using Terraform”, 25 minutes 5 seconds, from October 2022. Its description says Terraform can be split into folders to reduce blast radius and improve readability using remote states and data sources, and names the speaker as Leon Nunes. That matches the two mechanisms in this lesson. It is from 2022, so any S3 backend it shows will likely use DynamoDB locking, now deprecated in favour of use_lockfile, and I did not watch it to check. English was judged from the title, description, channel and its English auto-caption track. Karl Schriek’s video in deeper, from August 2026, is about splitting a monolithic state with a tool called demonolith, which I did not run.

Where this fits

That finishes the structure group: layout, workspaces, environment directories, Terragrunt and the cuts between states. The next group is about proving the code works before it reaches any of them, starting with formatting, validation and tflint.

Check yourself

  1. 01Give two reasons to put the network and the application in different states?

    They change at very different rates, and they may have different owners or credentials, so one apply should not carry the other.

  2. 02What does terraform_remote_state require of the reader?

    Permission to read the other component's whole state, which can include secrets, and knowledge of its backend and key.

  3. 03What goes wrong if you split states too finely?

    One feature becomes several pull requests and applies, outputs become breaking contracts, and a window opens where the layers disagree.

Go deeper

Notes

Private to you

Esc
↑↓ navigate↵ open? shortcuts

Keyboard shortcuts

Press Esc to close

Anywhere

⌘K
Search and commands
/
Search
?
This sheet
Esc
Close

Reading a lesson

J
Next lesson
K
Previous lesson
B
Bookmark