Use it when configuring, checking or troubleshooting State in Infrastructure as Code.
State · Infrastructure as Code
IaC state records management bindings and metadata used to correlate configuration objects with remote infrastructure and prior observations.
1. State maps code to real resources.
2. Contains secrets — protect.
3. Remote, locked, versioned.
4. Never edit manually; use state commands.
5. Back up.
code + state → real resources
Context & applicabilityCommon mistakes · platform/version boundaries
Operational reference
Fast context before you go deeper.
Verification & Troubleshooting
Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.
Use the operational verification above to establish the expected state.
Capture the concrete output, symptom, packet, log or counter before changing anything.
Step 1 Operational evidence path Verify boundary
Healthy evidence: State identity, lineage/version context, bindings and current provider reads are consistent with the intended target.
Step 2 Verification path Verify boundary
Record workspace/state lineage, configuration commit, resource address, provider version and plan/apply run ID; inspect the runtime/control-plane result; then query the provider-owned infrastructure objects plus authoritative IaC state representing them through an independent read path and compare it with the versioned intent. For Infrastructure as Code → State, the evidence must connect the control-plane result to the provider-owned infrastructure objects plus authoritative IaC state representing them and explain any gap between desired, controller-reported and consumer-visible state.
Step 3 Failure modes and next checks Narrow the fault
Suspicious evidence: State is stale, missing, duplicated, manually edited, exposed or bound to the wrong remote object.
State is operational metadata, not the live infrastructure itself, and it can contain sensitive values.
Step 4 Common mistakes Narrow the fault
- State stored locally.
Step 5 Where it fails Narrow the fault
Failure analysis for Infrastructure as Code → State should follow the path through the components: configuration/variables → graph/plan → state lock → provider API → infrastructure mutation → state update → refresh/target read-back. Common failure classes include wrong workspace/backend, stale plan, provider drift, concurrent state write, partial apply, import/address mismatch and state success without healthy infrastructure. Before retrying a mutating operation, read current target state using the stable identity workspace/state lineage, configuration commit, resource address, provider version and plan/apply run ID; if state is unknown, stop broad retries.
Evidence · 1 on this Topic
Expected observations and documentation recipes are reference material. Record actual output, device identity, scope and time before claiming a verified result.
- State is operational metadata, not the live infrastructure itself, and it can contain sensitive values.
- State or engine metadata ≠ authoritative live-service health; always confirm with provider read-back and target acceptance checks.
- A green execution step ≠ complete convergence when later state persistence, external dependencies or workload readiness remain unverified.
- Provider/API success ≠ business outcome; keep engine evidence and target-domain evidence separate.
terraform state list— resourcesterraform show -json | jq '.values.root_module.resources | length'— count- State backend encryption and access — protection
ReferenceWhy it matters1 section · depth on demand
In depth
In IaC, state is the tool's record of which real resources it manages and their last known attributes. Terraform/OpenTofu use it to map code to resources and calculate plans; losing or corrupting it makes the tool lose track of infrastructure.
| Practice | Reason |
|---|---|
| Remote backend (S3, Azure Blob, HTTP, Terraform Cloud) | Shared and durable |
| Locking | Prevent concurrent applies |
| Encryption and restricted access | State may contain secrets |
| Separate state per environment/component | Limit blast radius |
| Versioning on the backend | Recover from mistakes |
terraform state list
terraform state show aws_instance.web
ReferenceImportant terms & boundaries2 sections · depth on demand
What this shows and what it does not
State is operational metadata, not the live infrastructure itself, and it can contain sensitive values.
Mechanics
Infrastructure as Code → State is owned at runtime by the Terraform/OpenTofu CLI/runtime, provider plugins and remote APIs/state backend that evaluate and apply the graph. Its durable intent is versioned configuration, provider/module constraints, variable inputs and state/backend contract; the stable identity contract is workspace/state lineage, configuration commit, resource address, provider version and plan/apply run ID. The consumer-visible target is the provider-owned infrastructure objects plus authoritative IaC state representing them. The operating invariants are that state identity is explicit, provider/module versions are controlled, plan is reviewed, locking prevents concurrent state writes and apply is followed by refresh/read-back. Follow the chain of components configuration/variables → graph/plan → state lock → provider API → infrastructure mutation → state update → refresh/target read-back and record which layer currently owns truth. The linked authority for bounded mechanics is OpenTofu Documentation; documentation support is separate from observed lab/production Evidence.
Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Verification history & basis
When and against what this Topic was checked. Later text edits do not count as a new check.
Authoritative/upstream documentation reviewed for bounded claims in Infrastructure as Code > State. Documentation verification only; this is not observed lab or production Evidence.
Basis: https://opentofu.org/docs/ · confidence 94%Terms & aliases
Hover a linked term for a quick definition; click it to open its glossary entry. Aliases are other names that find this Topic in search.
Quick lookup tables
State IaC proof-boundary map
Fast definition/state/plan/execution/target-proof boundaries for State.
| Boundary | Healthy evidence | Suspicious evidence |
|---|---|---|
| Definition / inputs | Exact revision, toolchain and effective inputs are reproducible | Different runner/version/input context changes evaluation |
| State / planning | Correct backend/state/lock, fresh reads and reviewed graph/plan | Wrong state/workspace, stale reads, unsafe replacement/destroy or missing lock |
| Execution | Expected provider/API operations complete and state persists | Partial apply, auth/API error, ambiguous retry or failed state write |
| Target proof | Independent read-back plus fresh plan confirm intended convergence | Engine success treated as workload acceptance or drift remains unexplained |
Deep reference
Healthy vs suspicious evidence
Output interpretation
Capture at minimum workspace/state lineage, plan/apply ID, resource address, provider/version, action/diff, lock state, API error and refreshed state/object ID.