terraform.tfstate version 4

Terraform State Viewer

Open a Terraform state file to browse resources by module and type, read attributes with sensitive values masked, see what depends on what, count the secrets sitting in the file and compare it with another state. Values stay masked in every export.

State file

Drop terraform.tfstate

JSON up to 120.0 MB. Get one with terraform state pull.

Open a state file or load the example. The file is read in this tab only.

Terraform State Viewer

Operator: Abdulla Al Fahad. How tools are built and checked

terraform.tfstate is the file that says what Terraform believes exists, and it is also where the database password, the access key secret and the private key sit in plain text. Opening it in an editor is tedious (every resource is a nested JSON object) and a little dangerous (values are right there on screen), so this viewer shows the resources as a list, masks anything sensitive, and counts how many secrets the file holds.

Key features

  • Resource instances listed by address, with module, type, provider, index and tainted status, and a filter by type or text
  • Attributes flattened into paths such as tags.Name or rule[0].cidr_blocks[0]; values Terraform marked sensitive are masked, and unmarked secrets are caught by attribute name (password, passphrase, secret, token, private key, including numeric ones) or by value (private key blocks, AWS access key IDs, GitHub and Slack tokens, JWTs, and URLs that carry a user:password pair)
  • A dependency view built from each instance's recorded dependencies, with layers, loop count and a Graphviz DOT export
  • Comparison with a second state file: added, removed and changed instances attribute by attribute, plus changed outputs

How instances, attributes and sensitive paths are read from a state

A version 4 state, the format written since Terraform 0.12, has top-level version, terraform_version, serial, lineage, outputs and resources. Each resource has a mode (managed or data), type, name, provider, an optional module and an array of instances; each instance has an optional index_key, its attributes, a list of sensitive_attributes paths and the addresses it depends on. The page builds addresses the way Terraform prints them: module.net.aws_subnet.private[0], data.aws_ami.ubuntu, or a string key as aws_s3_bucket.logs["eu"].

Terraform lists each sensitive value as a path of steps, and a key inside a map (the DATABASE_URL in a Lambda's environment variables, the entries of a Kubernetes secret's data, a sensitive tag) arrives as an index step. The page writes those steps in the same notation as the attribute walk, so environment[0].variables.DATABASE_URL and a key that needs quoting, such as variables["odd key"], both match their sensitive path. When the id attribute itself is sensitive or looks like a credential, the ID column of the resources CSV, the table search and the screen show a mask instead of it.

Older formats (version 3 and below) and the output of terraform show -json are rejected with a message explaining what they are, because their structure differs.

How it works

Each instance's attributes are walked into path and value pairs with a depth limit of 40, a limit of 4,000 values per instance and a budget of three million values for the whole file; empty lists and objects count against those limits too. A sensitive_attributes entry is converted to the same path notation, and any value at or below that path is masked.

The dependency layer of an instance is the length of the longest chain below it: nothing it depends on gives layer 0. Layers and loops are computed with an iterative walk, so a damaged state with a cycle is counted and reported without hanging the page.

In a comparison, each address present in both states has its attribute paths compared; a changed sensitive value is shown as a change with both sides masked. The instance status, such as tainted, counts as an attribute.

When this helps

  • A new platform engineer inherits an S3 backend and wants to know how many credentials are sitting in the state before tightening the bucket policy; the Secrets tab lists every masked path and why it was masked.
  • After an incident, an engineer pulls serial 311 and serial 318 of a production state and sees that 3 of 140 instances changed. One shows (instance status) going from tainted to ok, which explains why the next apply did not rebuild the host.
  • A team lead asks for an inventory of everything under module.net before a refactor; the resource list, filtered by that module, goes out as a CSV with the ID and type of each instance.
  • A consultant who may look at structure but not at secrets exports the attributes CSV. A Lambda's DATABASE_URL, a Kubernetes secret's data keys and a sensitive id appear as masked cells, with the reason in the last column.

Opening a file

  1. Drop terraform.tfstate (terraform state pull > terraform.tfstate gets one from a remote backend), or use the Load example button for the built-in pair of states.
  2. Filter the Resources tab by type or search for an id, then select a resource to see its attributes, what it depends on and what uses it.
  3. Open Secrets to see how many values are marked sensitive and how many only look secret.
  4. Drop a second state on Compare to see what changed between two serials.

Example

The built-in state with 7 instances (serial 41), compared with a second state (serial 42)

aws_db_instance.primary: password, marked sensitive; allocated_storage 50
aws_iam_access_key.ci: secret wJalrXUt..., not marked; id AKIAIOSFODNN7EXAMPLE
next state: allocated_storage 100; aws_instance.web is no longer tainted and its instance_type changes from t3.small to t3.medium

Secret counts, dependency layers and differences

2 values marked sensitive (the database password and the db_password output); 2 look secret but are not marked (the access key's secret by its name, its id by its value, so that id is masked in the resources CSV as well)
5 dependency edges in 4 layers, no loops
Compare: 2 changed, 5 unchanged, 0 added, 0 removed; allocated_storage 50 to 100, instance_type t3.small to t3.medium, instance status tainted to ok

Tips for best results

  • Use the dependency layers to find a safe destroy order: instances in a high layer must go before the ones in the layers below.
  • Search by the cloud id (i-0123..., vpc-...) to find the Terraform address of something you spotted in a console.
  • In Compare, load the older state first and the newer second, so added means "new in the later file".

Limits

A state file holds every value in clear text, including those Terraform masks in plan output. Marking an attribute sensitive hides it from the terminal only, so the file itself still needs an encrypted backend and restricted access.

The name and value checks are heuristics. They miss secrets that look like ordinary strings and can flag harmless ones, such as a field called token_endpoint that holds a URL.

Dependencies are what Terraform recorded at the last apply. Resources that depend on each other through data lookups or provider configuration may show no edge.

Common errors and how to fix them

"This state uses format version 3, written by Terraform 0.11 or earlier."
Run terraform apply or terraform init -upgrade with Terraform 0.12 or newer so the backend rewrites the state as version 4, then pull it again. A state of version 5 or higher is newer than this page reads.
"This is the output of terraform show -json, not a state file."
terraform show -json describes values in a different shape, with format_version and a values tree. Open the real terraform.tfstate, or run terraform state pull > terraform.tfstate.
"The two files have different lineage IDs" on the Compare tab
Each state history gets a lineage ID when it is created. Different IDs mean the files came from different backends or from a state that was recreated, so added and removed instances may be a rename, not a change.

Best practices

  • Compare states that share a lineage; the page warns when the lineage IDs differ, which means the two files are not versions of one state history.
  • Pull the state again with terraform state pull before opening a file attached to a ticket, so you read what the backend holds now and not a stale copy.

What the masking covers and what it does not

Three things decide that a value is masked: the path is in the instance's sensitive_attributes (Terraform's own mark), the value looks like a credential, or the attribute name does. The value patterns are a PEM private key block, an AWS access key ID (AKIA followed by 16 characters), a GitHub token (ghp_, gho_, ghu_, ghs_ or ghr_), a Slack token (xox), a JWT, a Stripe secret key (sk_live_ or sk_test_) and any URL with a user:password pair before the host. The name pattern covers password, passphrase, secret, token, private key, access key, API key, client secret, connection string, credential and a few more, and applies to numbers as well as strings, so a numeric auth_token is masked while a token_ttl of 3600 is not.

The checks cannot know that a field called notes holds a password, or that a list called backup_codes holds recovery codes. Anything the page does not mask is printed as stored, so read the attributes CSV before sending it to someone who must not see secrets.

Frequently asked questions

Can I use this instead of terraform show?

For inspection, yes, and for a state you cannot run Terraform against, it is the only option here. A plan is a different thing, since it describes changes that have not happened yet; a state is the record of what exists now with every attribute, which suits inventory, secret checks and comparing two points in time.

Why do exports stay masked when I tick the reveal box?

A CSV or Markdown file gets copied, attached to tickets and checked into repositories. Revealing a value on your own screen is a deliberate act; writing it into a file you may forget about is not, so exports never include it.

Does the page change anything in the state or contact the backend?

No. It reads the file you open and writes nothing back; use terraform state pull to get the file, and do not edit a live state by hand.