The Address Is Not the Cloud Resource Name
A cloakroom gives you a numbered ticket. The ticket is not the coat; it is a handle that means something only inside that cloakroom.
Terraform addresses work the same way. The P06 apply printed local_file.hello beside an identifier beginning 5b011e…: a handle inside Terraform's records, and the provider's key for the object it wrote.
Two mandatory parts. An address combines a type and a local name: resource "local_file" "hello" becomes local_file.hello. The type must exist in the schema; the name is yours and must be unique among that type in its module. Renaming the label renames the address.
Prefixes and keys extend the same string. A module path comes first and a repetition key comes last. The table below collects the shapes you will read in state and plans.
| Form | Example address | What it means |
|---|---|---|
| Root resource | local_file.hello | One object in the root module |
| Child module | module.files.local_file.hello | The same block inside a module call |
| Nested module | module.storage.module.bucket.local_file.hello | Every module level is named in the path |
| Module with a key | module.storage["logs"].local_file.hello | A module repeated by a string key |
| Counted resource | local_file.hello[0] | A numeric position in a repeated block |
| Repeated resource | local_file.hello["greeting"] | A quoted string key in a repeated block |
| Data source | data.local_file.existing | A recorded read, not a managed lifecycle |
Keys are not interchangeable. [0] and ["0"] differ, and moving a list item rewrites the index while a map key stays with its object.
An address is not an object identifier. It is not the path ./hello.txt, the object's id (a content hash for the local provider), nor an ARN, tag or DNS name. Those live inside the state record it points to.
Uniqueness stops at the state file. Two roots may both declare local_file.hello for different files, and must never manage one object.
A rename is a replace, not a move
Rename hello to greeting and Terraform proposes create and destroy, though the file never moved. The address changed, so the recorded object no longer matches the desired one. Later parts migrate the mapping; knowing which address you have comes first.
Figure 1 follows the path from configuration block to address to file.
%%{init: {'theme':'base','themeCSS':'.edgeLabel .label text, .edgeLabel text, .edgeLabel span { fill:#132440 !important; color:#132440 !important; }','themeVariables': {'primaryColor':'#16476A','primaryTextColor':'#ffffff','primaryBorderColor':'#132440','secondaryColor':'#3B9797','secondaryTextColor':'#ffffff','secondaryBorderColor':'#132440','tertiaryColor':'#c4873b','tertiaryTextColor':'#132440','tertiaryBorderColor':'#132440','lineColor':'#5a6e82','textColor':'#132440','titleColor':'#132440','mainBkg':'#16476A','nodeBorder':'#132440','clusterBkg':'#eef3f7','clusterBorder':'#132440','edgeLabelBackground':'#ffffff','actorBkg':'#16476A','actorTextColor':'#ffffff','actorBorder':'#132440','activationBkgColor':'#3B9797','activationBorderColor':'#132440','signalColor':'#5a6e82','signalTextColor':'#132440','noteBkgColor':'#c4873b','noteTextColor':'#132440','noteBorderColor':'#132440','labelBoxBkgColor':'#a8dede','labelBoxBorderColor':'#132440','labelTextColor':'#132440','loopTextColor':'#132440','altBackground':'#f8f9fa','fontFamily':'DM Sans, sans-serif'}}}%%
flowchart TD
A["HCL block: resource local_file hello"] --> B["Address: local_file.hello"]
B --> C{"Declared in a child module?"}
C -->|"no"| D["Root address: local_file.hello"]
C -->|"yes"| E["module.files.local_file.hello"]
D --> F{"How many instances?"}
E --> F
F -->|"one"| G["No key"]
F -->|"count"| H["Index in brackets: [0]"]
F -->|"for_each"| I["Key in brackets: [key]"]
G --> J["One state instance: provider, id, attributes"]
H --> J
I --> J
J --> K["Provider call using the stored id"]
K --> L["hello.txt on disk"]
M["Not the address: path, hash, ARN"] -.-> B
classDef primary fill:#132440,color:#ffffff,stroke:#0b172b;
classDef secondary fill:#16476A,color:#ffffff,stroke:#0f314a;
classDef ok fill:#3B9797,color:#ffffff,stroke:#2a6f6f;
classDef danger fill:#BF092F,color:#ffffff,stroke:#7a0420;
classDef warn fill:#c4873b,color:#132440,stroke:#8a5a1f;
class B,J primary;
class A,C,D,E,F,G,H,I,K secondary;
class L ok;
class M warn;
Only the last edge touches the world; a failed call leaves a valid address with nothing behind it.
Figure 2 opens the address into its parts beside the state record it resolves to.
Read Figure 2 left to right: a wrong module path resolves to nothing, a missing key selects a set, and a stale id chases a deleted object.
Inspect Managed Objects with Supported Commands
The state file is a database, not a document: a format version, internal cross-references, and provider-private sections opaque even to Terraform Core. Hand-editing it is editing a live database with a text editor.
Terraform ships read-only commands that parse the file, apply the current schema and print a view. They are safe to repeat and to share once you have checked for secrets.
Start with the inventory. terraform state list prints one address per instance in stable order; the -id flag adds the provider identifier, often the fastest way to confirm that address and object belong together. After the P06 apply the list holds the two lab addresses; after destroy it is empty.
An empty list deserves suspicion: it can mean the root manages nothing, but more often the wrong directory, workspace or backend.
The show command reads the snapshot, not the world. It prints one instance's recorded attributes — filename, content, permission, checksums and id — and does not refresh. If the file was deleted an hour ago, the command still describes it. Use a plan to learn what exists; use this view to learn what Terraform believes it owns.
The full snapshot includes outputs. terraform show prints the whole state; given a plan file it renders that proposal without re-planning. Both forms accept -json, a versioned machine-readable surface that is an output format for reading, not a supported way to write state.
Outputs have three narrow forms. The plain command prints the familiar list, the JSON flag returns an object, and the raw flag returns one unquoted value. The last two let pipelines consume values, and they are the forms most likely to put a secret in a log.
Here is the lab, then the read-only inspection set.
The filters are deliberately small: state JSON for address, type and name; plan JSON for each change and its actions; raw state for serial, lineage, version and output names. That last one describes a state file without printing values.
Two commands write, so they are absent
The read-only set deliberately omits state rm and state push. Both write. A command that can change state needs a backup, a named owner and a second reader. A command that cannot, you can run freely.
Access follows content. On a local backend, anyone who can read terraform.tfstate can read every attribute, including values redacted on screen. On a remote backend, storage policy is the boundary, and reading state is reading secrets.
Figure 3 lays out the read-only paths and the branches where they stop.
%%{init: {'theme':'base','themeCSS':'.edgeLabel .label text, .edgeLabel text, .edgeLabel span { fill:#132440 !important; color:#132440 !important; }','themeVariables': {'primaryColor':'#16476A','primaryTextColor':'#ffffff','primaryBorderColor':'#132440','secondaryColor':'#3B9797','secondaryTextColor':'#ffffff','secondaryBorderColor':'#132440','tertiaryColor':'#c4873b','tertiaryTextColor':'#132440','tertiaryBorderColor':'#132440','lineColor':'#5a6e82','textColor':'#132440','titleColor':'#132440','mainBkg':'#16476A','nodeBorder':'#132440','clusterBkg':'#eef3f7','clusterBorder':'#132440','edgeLabelBackground':'#ffffff','actorBkg':'#16476A','actorTextColor':'#ffffff','actorBorder':'#132440','activationBkgColor':'#3B9797','activationBorderColor':'#132440','signalColor':'#5a6e82','signalTextColor':'#132440','noteBkgColor':'#c4873b','noteTextColor':'#132440','noteBorderColor':'#132440','labelBoxBkgColor':'#a8dede','labelBoxBorderColor':'#132440','labelTextColor':'#132440','loopTextColor':'#132440','altBackground':'#f8f9fa','fontFamily':'DM Sans, sans-serif'}}}%%
flowchart TD
A["A question about ownership"] --> B{"What do you need to read?"}
B -->|"which addresses exist"| C["terraform state list"]
B -->|"one instance's attributes"| D["terraform state show ADDRESS"]
B -->|"the whole snapshot"| E["terraform show"]
B -->|"a saved plan"| F["terraform show -json tfplan"]
C --> G["Address inventory"]
D --> H["id and last observed values"]
E --> I["outputs and resource blocks"]
F --> J["resource_changes and actions"]
G --> K{"List is empty?"}
K -->|"yes"| L["Wrong directory, workspace or backend"]
K -->|"no"| M["Record the address and its object id"]
H --> M
I --> M
J --> M
M --> N{"Did the command fail?"}
N -->|"access denied"| O["Backend credentials or policy"]
N -->|"address not found"| P["Quote for_each keys, check module path"]
N -->|"lock held"| Q["Find the writer before forcing anything"]
N -->|"no"| R["Keep the evidence, change nothing"]
classDef primary fill:#132440,color:#ffffff,stroke:#0b172b;
classDef secondary fill:#16476A,color:#ffffff,stroke:#0f314a;
classDef ok fill:#3B9797,color:#ffffff,stroke:#2a6f6f;
classDef danger fill:#BF092F,color:#ffffff,stroke:#7a0420;
classDef warn fill:#c4873b,color:#132440,stroke:#8a5a1f;
class B,K,N primary;
class A,C,D,E,F,G,H,I,J,M secondary;
class R ok;
class L,O,P,Q danger;
The branches are diagnostic. "Access denied" is a credentials problem, not an empty state. "Address not found" is usually quoting, because for_each keys are strings. The lock branch matters most: a held lock means another writer, not a retry.
What State Remembers and What It Cannot Recreate
The outer shape is stable across versions. The table below names the fields you will meet at each level; the values inside change, the layout rarely does.
| Level | Fields | What they tell you |
|---|---|---|
| Root | version, terraform_version, serial, lineage, outputs, resources | The format, the writer, the snapshot identity and everything it owns |
| Resource | mode, type, name, provider address, instances | Which block this is and who services its objects |
| Instance | schema_version, attributes, sensitive_attributes, private, dependencies | The last observed values, redaction paths and provider-private data |
serial counts writes, not versions of your infrastructure. Backends use it to reject an older snapshot and to detect a lost race; it never decreases.
lineage is the identity of one state. It is assigned at creation and preserved across writes, moves and applies. The same lineage means the same state at different moments; a different lineage means a different state, which is why a push refuses a mismatch unless forced.
Outputs are stored values, not recomputed ones. The outputs map keeps root output values with sensitivity flags; the output command reads them. Change an output expression without applying and the stored value is still the old one.
Attributes are the provider's report at the last write. For the local file that means content, filename, permissions, checksums and id. The sensitivity list marks paths to redact in displays and encrypts nothing; the private blob is provider-owned and opaque by design.
What state cannot do is just as concrete:
- It cannot recreate the object. There is no restore command, and a missing file with an intact record means the next plan creates it again.
- It cannot report what exists now without a refresh. The record is the last observation.
- It cannot prove ownership. The provider account and its policies decide, not the file.
- It cannot hold configuration. It stores values, not the
.tffiles, module sources or variable definitions. - It cannot provide history beyond one snapshot and one backup.
- It cannot replace credentials or permissions.
A resource whose payload is copied into state, as local_file.content is, can look like a backup — but the resemblance is accidental: no restore path, and no promise that every attribute survives.
The JSON is not an editing API
The layout changes between Terraform versions, the private blob is provider-defined, and schema_version tells Terraform how to upgrade attributes when a provider schema changes. Hand-edit a value and the state can parse while no longer matching the object. Supported mutations are commands and blocks: state mv, state rm, state replace-provider, import, moved and removed. Read the JSON as much as you like; write through those.
State, Backups and Saved Plans Can Contain Secrets
Redaction is a display feature. (sensitive value) in a plan and <sensitive> in output both mean Terraform declined to print a string. It did not remove the string from the artifact. State stores values as the provider returned them, the backup stores the previous snapshot, and a saved plan stores configuration, variables and planned values.
The gap is easy to miss. You approve a redacted plan while the state file sits in a bucket, its backup beside it, and the saved plan in a CI artifact store with ninety-day retention.
Three commands widen the leak. The JSON output form returns sensitive values in cleartext because machines consume it, and a state pull writes the entire raw state to standard output — useful for a backup, disastrous in a ticket. Crash logs and debug output can contain values from the failing operation.
Rotation does not clean history: a new password updates current state, while backups, versioned objects and CI artifacts may hold the old one. "Rotated" and "no longer stored" differ.
Redaction is a display decision
The (sensitive value) on screen and the <sensitive> in human-readable output both describe the same bytes that sit in cleartext in the state file, its backup, and any saved plan. Terminal redaction is not a storage transformation.
Figure 4 contrasts what the terminal shows with what the disk keeps.
The controls are cumulative: backend encryption and versioning, the smallest reader group, state out of Git before the first commit, short plan retention, CI secret scanning.
Verify the Git rule with the same three checks the read-only set uses:
Read the three answers. The ignore check prints the matching pattern; no output means the file is not ignored. The tracked-file check should fail, and success means a state file is already tracked. The history check shows whether a state file was ever committed, even if it is gone from the working tree.
The last check is uncomfortable. A state file committed once and deleted a week later is still in history, and cloning reproduces it. Remediation is history rewriting plus credential rotation, not a new ignore line — so the ignore file belongs in the first commit.
Why Deleting State Is Not a Cleanup Strategy
Three intentions hide under "clean up". Forgetting removes an address and leaves the object. Destroying asks the provider to delete it. Recovering reattaches an object to an address. Different commands, one cleanup.
terraform state rm local_file.hello forgets one instance. The file is untouched, and the next plan proposes to create it. A local file is rewritten. A cloud resource gains a second object with a new id while the first keeps running and billing, now untracked. Forgetting is a hand-off tool, not cleanup.
Deleting the state file forgets everything and discards outputs, lineage and ids. The next apply creates a parallel set. Unique names make it fail fast; without them you own two of everything and one is invisible.
Destroy is what people usually mean. A reviewed destroy plan deletes each object and writes state with an empty resources list. P06 left the file gone, the code intact, and the state present with a higher serial and the same lineage. That empty state says this root manages nothing; deleting it would destroy no infrastructure.
Four verbs, four outcomes
Removing a resource block changes desired state; the next plan proposes destruction, which is only a proposal. Forgetting removes the address, destroying removes the object, and recovering reattaches one to the other. Only destroy removes infrastructure.
Recovery depends on the mistake. If the object survives and you have a snapshot — the backup, a pulled copy, a versioned object — restore it as the only writer, after checking the lineage. Same lineage is the same state earlier; a different lineage is another state you are about to overwrite. Without a snapshot, import each survivor and converge to a no-change plan. Import works only where the provider supports it, and never recovers outputs or history.
A local file is forgiving: a missing hello.txt costs one rewrite. The commands are the same in production.
Investigate a local state snapshot
Execution status: design-only. Every command here is read-only. The configuration and expected shapes come from the P06 lab, executed on 5 November 2026 with Terraform 1.17.1 and hashicorp/local 2.9.1. This sequence was not recorded separately.
Prerequisites. Terraform 1.17.1, the P06 lab directory re-applied through a saved plan, jq, and the directory inside a Git repository. No cloud account or credential.
Minimal setup. Confirm both addresses with a state list, copy the state file to state-snapshot/state-2026-11-05.json, and restrict permissions on the copy. It is a specimen, not a backup to push, and it must not be committed.
Worksheet. Work top to bottom; each row names what to run and what the shape should prove.
| # | Run or read | Expect |
|---|---|---|
| 1 | terraform state list and terraform state list -id | Two addresses; a 40-character hash for the file and a UUID-shaped id for the control object |
| 2 | terraform state show local_file.hello | Filename, content, permission, id and checksums; the filename reads ./hello.txt though the file sits beside main.tf |
| 3 | terraform state show terraform_data.revision | Input and output only, no file attributes: one object stores a value, the other writes bytes |
| 4 | terraform show and the JSON filter | The same two addresses, with type and name as separate fields |
| 5 | The plan JSON filter from the previous section | Two entries whose action arrays describe creation |
| 6 | terraform output -json | file_id matches the hash in state; nothing was recomputed, so treat the JSON as sensitive anyway |
| 7 | The raw state filter | A small integer serial, a UUID lineage, the CLI version and one output key |
| 8 | The three Git checks | The ignore rule names your patterns; the tracked-file check fails |
| 9 | On paper, three outcomes | Deleting state, forgetting one address and applying a destroy plan should each match this section |
Expected observation. Two inventory rows, each pairing an address with an object and an id, plus a confirmed ignore rule and an untracked state file. Serial and lineage describe the snapshot, not the infrastructure.
Failure checks. An empty list in the lab directory means the wrong directory or workspace. An unquoted for_each key fails to parse. Reading the raw file with jq exposes attribute values, so do not paste that output into a ticket.
Cost dimensions. Zero provider or cloud charges. The snapshot is a few kilobytes; the CLI, jq and git are already present. The real cost is attention, because every command reads a file that may contain secrets.
Cleanup. Remove the snapshot directory, then destroy the lab if the file is no longer needed. Confirm with a state list that the inventory is empty, and keep the ignore file.
Next in the Series
In Variables, Locals and Outputs as a Typed Interface, we'll explore Design configuration inputs and outputs with precise types, defaults and validation.