Use it when configuring, checking or troubleshooting Resources in Terraform / OpenTofu.
Resources · Terraform / OpenTofu
Terraform/OpenTofu resource blocks declare managed resource instances whose remote identities are tracked in state and reconciled by provider lifecycle operations.
1. Resources are managed objects.
2. Use for_each for stable addressing.
3. Tags/labels.
4. Lifecycle rules.
5. Avoid giant monolith configs.
resource block → API object
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: Resource addresses, instance keys, provider identity, state binding and remote objects match the intended ownership model.
Step 2 Verification path Verify boundary
The negative fixture should deliberately exercise risks such as wrong workspace/backend, stale plan, provider drift, concurrent state write, partial apply, import/address mismatch and state success without healthy infrastructure, choosing the cases most relevant to resource schema/key properties, Get/Test/Set behavior, module/version identity and confirming the underlying managed resource converges. For Terraform / OpenTofu → Resources, 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: Address/key changes orphan or replace objects, two configurations manage one object, or provider lifecycle differs from expected in-place updates.
Resource block ≠ single instance automatically; count/for_each and moved addresses can change instance identity and replacement behavior.
Step 4 Common mistakes Narrow the fault
- Managing the same resource in two configurations.
Step 5 Where it fails Narrow the fault
Failure analysis for Terraform / OpenTofu → Resources should follow the path through the components: configuration/variables → graph/plan → state lock → provider API → infrastructure mutation → state update → refresh/target read-back.
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.
- Resource block ≠ single instance automatically; count/for_each and moved addresses can change instance identity and replacement behavior.
- Terraform/OpenTofu command success ≠ target workload health; provider operations and application acceptance are separate proof boundaries.
- The same repository ≠ same run when binary, provider/module versions, backend/workspace, variables, credentials or lock selections differ.
- Treat Terraform and OpenTofu as separate implementations: verify behavior against the pinned tool and dependency versions rather than assuming interchangeability.
terraform state list— managed resourcesterraform state show <addr>— attributes- for_each over count for stable addresses — design
ReferenceImportant terms & boundaries2 sections · depth on demand
In depth
A resource block declares one infrastructure object that Terraform manages: its type (from a provider), a local name and its arguments. Terraform records each resource in state and plans create, update or replace actions by comparing configuration, state and reality.
resource "aws_security_group" "mgmt" {
name = "mgmt-ssh"
vpc_id = data.aws_vpc.core.id
ingress {
from_port = 22
to_port = 22
protocol = "tcp"
cidr_blocks = ["10.0.0.0/24"]
}
}
Some argument changes can be applied in place; others force replacement (shown as -/+ and "forces replacement" in the plan) — always check which before applying. Use for_each with stable keys rather than count for collections, so removing one item does not shift and recreate the others.
Mechanics
Terraform / OpenTofu → Resources is owned at runtime by the Terraform/OpenTofu CLI/runtime, provider plugins and remote APIs/state backend that evaluate and apply the graph.
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 Terraform / OpenTofu > Resources. 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
Resources IaC proof-boundary map
Fast definition/state/plan/execution/target-proof boundaries for Resources.
| 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
For resource schema/key properties, Get/Test/Set behavior, module/version identity and confirming the underlying managed resource converges, prefer typed fields and stable IDs over human presentation text.