It's Thursday, a little after six. A teammate's pull request is waiting for you:
Activity feed: sort items by creation time
6 files changed, +214 −9
Most of it is what you'd expect: a new Lambda function, a queue, an IAM policy, some outputs. Somewhere in the middle, in tables.tf, is this:
resource "aws_dynamodb_table" "items" { name = "demo-items" hash_key = "pk" - range_key = "sk" + range_key = "created_at" CI is green. You open the plan step's log, scroll past the provider downloads, and read the summary at the bottom: Plan: 16 to add, 9 to change, 2 to destroy. A new feature, a few new resources; it looks about right. You approve, and go home.
The next morning, the demo-items table is empty, and the Lambda function that reads its stream has stopped getting events.
Nothing was hidden. Terraform said exactly what it would do:
# aws_dynamodb_table.items must be replaced -/+ resource "aws_dynamodb_table" "items" { ~ arn = "arn:aws:dynamodb:...:table/demo-items" -> (known after apply) ~ id = "demo-items" -> (known after apply) name = "demo-items" ~ range_key = "sk" -> "created_at" # forces replacement ~ stream_arn = "arn:aws:dynamodb:...:table/demo-items/stream/..." -> (known after apply) # (8 unchanged attributes hidden) } DynamoDB can't change a table's keys, so the only way Terraform can get there is to delete the table and create a new, empty one with the same name. The stream gets a new ARN too, so the stream worker's event source mapping is replaced as well. That's two blocks among twenty-five, and they look like the other twenty-three.
This post is about that gap. A plan tells you everything that will change, sorted by resource address. It doesn't tell you which of those changes can hurt you. Below are five changes that get approved on a lot of teams, what each one really does, how to catch it by hand, and the small open-source tool I built so that catching them doesn't depend on how tired the reviewer is.
Why plans are hard to review
It isn't carelessness. A plan is built to be complete, not to be read under time pressure:
- It's long. A small feature touches 20 or 30 resources. A module upgrade touches hundreds.
- It's flat. A replaced database and a changed tag look the same: a block with a symbol in front of it. The only summary counts actions, not risk.
- The danger is in ordinary words.
will be createdsounds safe. So doesupdate in-place. Whether either is dangerous depends on what is created or updated, and the plan doesn't say. - Reviewers read the code, not the plan. The
.tfdiff is in the pull request. The plan is in a CI log, if it's anywhere. - It says nothing about what depends on a resource. Replacing a key that twelve things use looks the same as replacing one that nothing uses.
Here are the five.
1. A one-line key change that empties the table
That's the story above, and it isn't specific to DynamoDB. The AWS provider marks some attributes as impossible to change in place, and changing any of them means destroy and recreate. A few that catch people:
| Resource | Changing this replaces it |
|---|---|
aws_dynamodb_table | hash_key, range_key, a local secondary index |
aws_db_instance | kms_key_id, storage_encrypted, availability_zone |
aws_s3_bucket | bucket (the name) |
aws_efs_file_system | encrypted, kms_key_id, performance_mode |
aws_kinesis_stream | name |
How to catch it by hand
- Search every plan for
must be replacedandforces replacement. For each hit, ask one question: does this resource hold data? - Protect the ones that do.
lifecycle { prevent_destroy = true }makes the plan fail if it would destroy the resource. For DynamoDB,deletion_protection_enabled = truemakes AWS refuse the delete, so the apply stops before anything is lost. - Turn on point-in-time recovery for the tables you can't lose. It doesn't stop a delete, but it gives you a way back.
2. Four lines that give your API admin access
This one usually arrives with a good reason. A Lambda function is getting AccessDenied in staging, the demo is tomorrow, and someone attaches the biggest policy there is, "to unblock it, we'll scope it down later":
resource "aws_iam_role_policy_attachment" "api_admin" { role = aws_iam_role.api.name policy_arn = "arn:aws:iam::aws:policy/AdministratorAccess" } In the plan, it's the friendliest kind of change there is:
# aws_iam_role_policy_attachment.api_admin will be created + resource "aws_iam_role_policy_attachment" "api_admin" { + id = (known after apply) + policy_arn = "arn:aws:iam::aws:policy/AdministratorAccess" + role = "demo-api-role" } Nothing in that block says that AdministratorAccess means every action on every resource in the account. Nothing says who gets it. In this stack, two Lambda functions run as demo-api-role: the API and the stream worker. Anyone who finds a hole in either of them, such as a server-side request forgery or a compromised dependency, now has the whole account. And "later" rarely comes.
How to catch it by hand
- Give every
aws_iam_*change a second, slower look, especially*_policy_attachmentand inline policies with"Action": "*"or"Resource": "*". - For each role that changes, find what runs as it (Lambda functions, ECS tasks, instance profiles) and who can assume it (its trust policy). That's who gets the new permissions.
- Put guardrails where review can't be skipped: permissions boundaries on roles your pipelines create, and service control policies on the accounts.
3. A console change that your next apply quietly undoes
Drift cuts both ways, and both ways hurt.
The security version. During an incident, someone opens SSH to 0.0.0.0/0 on the load balancer's security group from the AWS console, with the description "debug", and forgets about it. If the group's rules are defined in Terraform, the next apply removes the rule. That sounds like a happy ending, but nobody ever asks who opened it, why, or what happened while it was open.
The outage version. During a traffic spike, someone raises a Lambda function's reserved concurrency in the console. It works; everyone goes to bed. Two days later, an unrelated pull request is applied, Terraform sets the value back to what the code says, and the incident comes back. The person who applied it has no idea why.
Terraform does notice. It prints this above the plan:
Note: Objects have changed outside of Terraform Terraform detected the following changes made outside of Terraform since the last "terraform apply" which may have affected this plan: # aws_security_group.alb has changed ... Unless you have made equivalent changes to your configuration, or ignored the relevant attributes using ignore_changes, the following plan may include actions to undo or respond to these changes. Most people scroll straight past it to the part that starts with Terraform will perform the following actions.
How to catch it by hand
- Read the "Objects have changed outside of Terraform" note every time. If it's there, someone should know why before anything is applied.
- Run
terraform plan -refresh-onlyon a schedule, so you find drift on a quiet Tuesday rather than in the middle of somebody else's change. - When a console change was right, put it in the code the same day.
4. A four-line resource that twelve others depend on
resource "aws_kms_key" "data" { description = "Encrypts the app's data" enable_key_rotation = true } Shared resources look small in code: a KMS key, a VPC, a subnet, a role, a security group. In this stack, twelve resources depend on this key, six of them directly: the DynamoDB table, the Postgres database, the API's log group, its Lambda function and IAM policy, and the key's alias. Behind those are the API Gateway integration, the stream mapping and the rest.
If a change replaces the key, Terraform schedules the old key for deletion and creates a new one. Everything that references it has to move to the new key, and some resources can't do that in place: an RDS instance can't switch keys, so it's replaced too, which brings back footgun number 1. And once the old key's waiting period (7 to 30 days) ends, anything still encrypted with it can't be read.
How to catch it by hand
- Before you change a shared resource, find what references it: search the code for its address, or look at
terraform graph. - In the plan, check whether any of those dependents is also changing, and why.
- Keep foundational resources (keys, networks, shared roles) in their own state, so a feature pull request can't touch them by accident.
5. A refactor that deletes what it meant to move
Refactoring Terraform is good practice. You move a queue into a module so three services can share the pattern:
-resource "aws_sqs_queue" "orders" { - name = "orders" -} +module "orders" { + source = "./modules/queue" + name = "orders" +} The infrastructure is meant to stay exactly the same. But Terraform tracks resources by address, and aws_sqs_queue.orders and module.orders.aws_sqs_queue.this are different addresses. Unless you tell Terraform they're the same thing, the plan is:
# aws_sqs_queue.orders will be destroyed # (because aws_sqs_queue.orders is not in configuration) - resource "aws_sqs_queue" "orders" { ... } # module.orders.aws_sqs_queue.this will be created + resource "aws_sqs_queue" "this" { ... } "1 to add, 1 to destroy" reads like a wash, and the two blocks may be screens apart. In reality the queue is deleted with every message still in it, and the create runs in the same apply, against a name SQS won't let you reuse for 60 seconds after a delete.
How to catch it by hand
- In a refactoring pull request, the plan should say
No changes. Anything else needs an explanation. - Use a
movedblock (Terraform 1.1 and later) to tell Terraform the old address is now the new one:
moved { from = aws_sqs_queue.orders to = module.orders.aws_sqs_queue.this } Catching them every time, not just when you're paying attention
Everything above works when the reviewer is careful, has time, and knows the provider well. But reviews happen on Thursday at six, too.
So I built Infraglass. It reads the plan Terraform already produces (terraform show -json) and puts the changes that can hurt you first, each with the reason:
| Severity | What it flags |
|---|---|
| High | A resource that holds data being replaced or deleted: tables, databases, buckets, volumes, file systems, caches, queues, streams, keys, secrets, log groups and similar, with the attribute that forces the replacement |
| High | A failed precondition, postcondition, check block or variable validation |
| High | A change that brings in a high-severity access finding, such as an admin policy attached to a role |
| Medium | A resource that others depend on being replaced or deleted, with how many |
| Medium | Drift: a resource changed outside Terraform, and which attributes |
| Low | A check Terraform can only evaluate during the apply |
Mapped to the five above: 1 and 5 are high (a table and a queue hold data), 2 is high (admin access), 3 is medium (drift), and 4 is both: high because a key holds the only way to read your data, and medium with "Replacing it affects 12 resources that depend on it (6 directly)". For every resource, it also works out the blast radius: what depends on it directly, what depends on those, and which of them this plan is already changing.
It's read-only: it never runs apply, makes no cloud API calls of its own, needs no account, and has no telemetry. It's one Go binary, Apache 2.0, and works with any provider and with OpenTofu (the access, network and DynamoDB explorers are AWS-only).
What it looks like on a pull request
Here's the top of the comment it posts on the sample pull request behind this article's clips, with the gates set to stateful-change,failed-check,high-finding:
3 to add, 2 to change, 2 to destroy (2 replaced)
❌ Gates failed: stateful-change, high-finding
| Review first | Resource | Why |
|---|---|---|
| high | aws_dynamodb_table.items | Replacing aws_dynamodb_table destroys the data it holds |
| high | aws_iam_role_policy_attachment.api_admin | This create brings in a risky policy: AWS-managed AdministratorAccess (every action on every resource) is attached |
| medium | aws_dynamodb_table.items | Replacing it affects 8 resources that depend on it (4 directly) |
| medium | aws_security_group.alb | Changed outside Terraform since the last apply; this plan will put it back as configured |
Below that, the comment lists every change with the attributes that force each replacement, the drift attribute by attribute, and the access findings. The check exits with status 3, so the pull request gets a red check, and the reviewer's first screen is this table, not 400 lines of log.
How teams use it
1. Reviewing a pull request on your laptop. Before you approve, open the plan as a review instead of a log:
terraform plan -out=tfplan infraglass serve --plan-file tfplan A browser tab opens with the risky changes first. Click one to see the attribute diff, the attribute that forces a replacement, and the blast radius on the graph.
2. A gate on every pull request. This is the one I'd start with. One step after terraform plan in GitHub Actions:
- run: terraform plan -input=false -out=tfplan - uses: ityashag/infraglass@a986fa72abbd3a3458944d9b17784c7d07a1a492 # v0.2.3 with: plan-file: tfplan version: v0.2.3 fail-on: stateful-change,failed-check,high-finding stateful-change fails when a data store is replaced or deleted, failed-check when a precondition, postcondition or check fails, and high-finding on high-severity access findings. One thing to know: high-finding counts every high finding in the result, including ones already in your state. On an older stack, start without fail-on (comments and reports only), clean up what it shows you, then turn the gates on. The same infraglass check command works in GitLab CI, Jenkins or anything that can run a binary, and writes HTML, Markdown and JSON reports.
3. Module upgrades and big refactors. A major version bump of terraform-aws-vpc, or splitting one state into two, produces plans with hundreds of lines. The question isn't "what changes?" but "is anything that holds data being replaced, and what depends on it?". That's the list Infraglass puts first, and it's where footgun 5 usually hides.
4. A nightly drift check. Run terraform plan on a schedule with infraglass check --fail-on drift, and you find console changes the morning after, not in the middle of someone's unrelated deploy.
5. Understanding a stack you've inherited. Run infraglass serve with no plan and it shows the current state as a graph, with explorers for the network (which subnets are public, and why), IAM (who can assume each role, and what it can reach) and DynamoDB tables. It's the quickest way I know to build a mental model of someone else's Terraform.
6. Watching an apply, and keeping a record. terraform apply -json tfplan | infraglass record shows each resource being built as it happens, with searchable logs. infraglass export writes a single HTML file you can attach to a change ticket or an incident review.
How it fits with the tools you already have
It doesn't replace them:
- Checkov, Trivy (formerly tfsec) and similar scanners check your configuration against rules: "is this bucket encrypted?". Infraglass looks at the change: "this plan deletes a bucket, and four things depend on it". Run both.
- OPA, Conftest and Sentinel let you write any policy you like against the plan JSON. Infraglass is the set of checks you'd otherwise write first, built in, with a visual review on top.
- HCP Terraform, Spacelift, env0 and Atlantis run your plans and applies. Infraglass doesn't run Terraform at all, so it can sit inside any of them as one more step.
- Rover and InfraMap draw your infrastructure. Infraglass draws it too, but the point is the ranked review, the blast radius and the CI gate.
Why I built it
I started with a different idea: something like the Jenkins dashboard, but for Terraform, a page where I could see everything a project had built. Once I had a plan on screen as a graph, it was obvious the picture wasn't the valuable part. The valuable part was answering one question quickly: of these 40 changes, which ones do I actually need to read? So that's what it became.
It's young, and I'd rather you know its limits up front:
- The access analysis reads policy text. It doesn't evaluate conditions, Deny statements, boundaries or SCPs, so treat a finding as "look here", not as a verdict.
- The access, network and DynamoDB explorers are AWS-only. Plan review, blast radius and the CI gate work with any provider.
- When I ran it on 16 examples from the most used AWS modules (terraform-aws-modules, on LocalStack), it got 16 things wrong, from database subnets shown as private to a blast radius inflated to 1,021 links. They're all fixed, each with a test, and every one is published.
Try it in a minute
- No install: click through the live demo. It's the sample pull request from this article. Press Guide for a short tour.
- On your own plan:
go install github.com/ityashag/infraglass/cmd/infraglass@latest terraform plan -out=tfplan && infraglass serve --plan-file tfplan - With Docker (runs the demo):
docker run --rm -p 127.0.0.1:7788:7788 ghcr.io/ityashag/infraglass - Release binaries for macOS, Linux and Windows, with checksums and signed build provenance: releases
- Code and docs: github.com/ityashag/infraglass
If you run it on a real plan, I'd love to hear what it caught and, even more, what it missed: open an issue or start a discussion.
Which of these five has bitten your team? Or what's the sixth?






