Use it when configuring, checking or troubleshooting Terraform / OpenTofu.
Terraform / OpenTofu
Terraform and OpenTofu are separate IaC implementations that evaluate HCL-style configuration, resolve providers/modules, maintain state and execute dependency-aware plans against infrastructure APIs.
1. Terraform/OpenTofu: HCL, providers, state, modules.
2. OpenTofu is the open-source fork (MPL) — mostly compatible.
3. Pin CLI and providers.
4. Remote state with locking.
5. Plans in CI with approvals.
HCL → init → plan → apply → state
Context & applicabilityCommon mistakes · platform/version boundaries
Operational reference
Fast context before you go deeper.
terraform fmtPrimary Commands
Configuration and operational commands for this Topic.
terraform fmtReferenceFormat Terraform files to the standard style.
Use when: Use after confirming the Terraform target and before changing state.
Quick note: Cross-platform automation / API / controller. Tool success, HTTP 2xx or changed=true does not prove idempotency, complete realization, service health or safe retry behavior.
Terraform · mixedterraform showReferenceShow the current state or a saved plan.
Use when: Use after confirming the Terraform target and before changing state.
Quick note: Cross-platform automation / API / controller. Tool success, HTTP 2xx or changed=true does not prove idempotency, complete realization, service health or safe retry behavior.
Terraform · mixedVerification & 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
tool/version + HCL/revision → init/provider/module/backend resolution → effective variables/locals → selected workspace/state + refresh → dependency graph → plan → approval → apply/import/destroy → provider API → state write/lock release → target read-back → fresh plan
- Capture exact Terraform/OpenTofu binary/version, repository revision, dependency lock context, working directory and selected workspace/backend.
- Resolve effective variables/locals, provider aliases/credentials, module versions and state identity before trusting validate/plan results.
- Preserve the plan/action summary, provider/API responses, lock/state-write outcome and any partial-apply recovery artifacts.
- Verify real target state/workload acceptance and run a fresh plan under the same intended context before declaring convergence.
Healthy evidence: The exact binary/version, configuration revision, dependency lock/provider sources, backend/state and target identity are explicit for each run.
Step 2 Verify plan identity, apply result, refreshed state and platform resource Verify boundary
Record the Terraform / OpenTofu configuration revision, provider lock versions, workspace/backend and plan digest. Review the bounded plan for the intended resource actions, apply that exact saved plan when the workflow supports it, and capture the resource addresses/results. Run a fresh plan with refresh after apply and expect no unintended changes, then query the cloud/hypervisor/network platform directly for critical resource attributes. Finally repeat the original service test. An empty post-apply plan shows reconciliation under the provider model, not application functionality or every external dependency.
Step 3 Target-state verification ladder Verify boundary
Terraform / OpenTofu uses a strict target-state ladder for plan/apply state and provider target state: request accepted → job/task succeeded → target object changed → effective runtime state confirmed → original workload verified.
Step 4 Failure modes and next checks Narrow the fault
Suspicious evidence: A workflow assumes the two tools are interchangeable or silently changes binary/provider/module/backend behavior between plan and apply.
It does not show every downstream workload, external dependency or unmanaged object. Terraform/OpenTofu similarity ≠ universal interchangeability; behavior, features, registries and compatibility must be verified against pinned tool/provider/module versions. The limit of what it shows ends where provider/state evidence stops and target-domain acceptance begins.
Next check: Continue from the first step that has not been verified: reproduce the same revision/tool/backend/workspace/input context, confirm provider/module resolution and state identity, refresh the intended target, preserve plan plus provider/API/state-write evidence, then read back target/workload state and generate a fresh bounded plan before retrying.
Step 5 Separate configuration, state, provider and remote-platform failures Narrow the fault
If Terraform / OpenTofu fails before planning, validate syntax/configuration and provider initialization first. If plan shows unexpected replacement or drift, inspect resource address, imported/state identity and provider refresh data before applying. If state locking fails, identify the active operation and backend lease rather than force-unlocking blindly. If apply fails after partial changes, use the resource-specific provider error and refresh current remote state before retrying. If the configuration is unchanged but plan differs across runners, compare provider lock file, variables, credentials and backend workspace. Plan success does not show apply or workload health.
Evidence · 2 on this Topic
Expected observations and documentation recipes are reference material. Record actual output, device identity, scope and time before claiming a verified result.
Healthy evidence: The exact binary/version, configuration revision, dependency lock/provider sources, backend/state and target identity are explicit for each run. Suspicious evidence: A workflow assumes the two tools are interchangeable or silently changes binary/provider/module/backend behavior between plan and apply.
command output · Documented exampleTerraform local healthy-state checkpointThe expected object, scope, state and counters match a controlled test.
Subtopics
Go one level deeper into this subject.
Terraform/OpenTofu fundamentals center on HCL configuration, provider plugins, dependency graphs, state, planning and explicit reconciliation of managed resources.
Subtopic HCLHCL expresses blocks, arguments, expressions, references and values used by Terraform/OpenTofu to build an evaluated infrastructure graph.
Subtopic ProvidersTerraform/OpenTofu providers are separately versioned plugins that supply resource/data-source schemas and implement API operations against target systems.
Subtopic ResourcesTerraform/OpenTofu resource blocks declare managed resource instances whose remote identities are tracked in state and reconciled by provider lifecycle operations.
Subtopic Data SourcesTerraform/OpenTofu data sources read external information during evaluation and feed values into the graph without owning those source objects.
Subtopic VariablesTerraform/OpenTofu input variables parameterize root/module configuration with typed values supplied through supported input mechanisms.
Subtopic Local ValuesLocal values name derived expressions inside a module to simplify reuse and make evaluated relationships explicit.
Subtopic OutputsTerraform/OpenTofu outputs expose selected root/module values for operators and downstream configurations or automation.
Subtopic ModulesTerraform/OpenTofu modules compose reusable resource graphs through explicit sources, versions, inputs, outputs and provider mappings.
Subtopic StateTerraform/OpenTofu state maps configured resource instances to remote objects and stores metadata required for planning and lifecycle operations.
Subtopic Remote StateRemote state stores state in a shared backend or collaboration service so automation and teams can coordinate around the same management record.
Subtopic State LockingTerraform/OpenTofu state locking prevents concurrent state-writing operations when the selected backend supports a locking mechanism.
Subtopic BackendThe backend determines where Terraform/OpenTofu persists state and may also provide coordination capabilities such as locking.
Subtopic InitInit prepares a working directory by configuring the backend and installing/resolving required providers and modules for later operations.
Subtopic ValidateValidate checks Terraform/OpenTofu configuration syntax and internal consistency within the initialized module context.
Subtopic PlanTerraform/OpenTofu plan compares evaluated configuration, selected state and provider reads to propose concrete resource actions.
Subtopic ApplyTerraform/OpenTofu apply executes a saved or freshly generated plan, updates remote resources through providers and persists resulting state.
Subtopic DestroyTerraform/OpenTofu destroy plans and applies removal of managed resources for the selected state and configuration scope.
Subtopic ImportTerraform/OpenTofu import associates an existing remote object with a resource address so it can enter managed state under configuration.
Subtopic LifecycleLifecycle settings influence Terraform/OpenTofu resource replacement, destruction protection, change ignoring and dependency-trigger behavior.
Subtopic DependenciesTerraform/OpenTofu dependencies arise primarily from expression references and may be supplemented by explicit dependency metadata when no data reference exists.
Subtopic WorkspacesTerraform/OpenTofu CLI workspaces select separate state instances for one configuration/backend context and can support repeated deployments with shared configuration.
Subtopic DriftTerraform/OpenTofu drift appears when provider refresh/read shows the remote object differs from the last managed expectation or current configuration.
Subtopic Terraform / OpenTofu TroubleshootingTerraform/OpenTofu troubleshooting isolates failures across binary/version, HCL evaluation, init/dependency resolution, backend/state/locking, provider credentials/schema, graph/plan and target API execution.
- Terraform/OpenTofu similarity ≠ universal interchangeability; behavior, features, registries and compatibility must be verified against pinned tool/provider/module versions.
- 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 version / tofu version— CLI and provider versionsterraform fmt -check && terraform validate— static checksterraform plan— preview
ReferenceWhat it is1 section · depth on demand
What it is
Terraform: Declarative Infrastructure, Provider, Resource, State.
Close with Compare plan and state with an independent provider/resource read, wait for effective readiness conditions, then execute the original consumer transaction. and state what the evidence does not show.
ReferenceWhy it matters2 sections · depth on demand
When to use it
Use Terraform when the problem concerns data models, APIs, code, orchestration, infrastructure as code, controllers or AI-assisted workflows.
Terraform and OpenTofu reconcile configuration, state and provider-observed infrastructure
Terraform / OpenTofu build a dependency graph from configuration and provider schemas, compare desired configuration with state and provider refresh results, then propose an execution plan. State contains resource identity and attributes used for reconciliation; it is not a substitute for the real platform, and stale or manually edited remote objects can create drift. Provider version, backend/locking and variable inputs are part of the reproducible execution context. A saved plan is meaningful only for the configuration, state snapshot and provider context from which it was created.
ReferenceImportant terms & boundaries3 sections · depth on demand
What this shows and what it does not
Terraform/OpenTofu similarity ≠ universal interchangeability; behavior, features, registries and compatibility must be verified against pinned tool/provider/module versions. The limit of what it shows ends where provider/state evidence stops and target-domain acceptance begins.
Key operational limits
- Desired state, source of truth, rendered change, apply result and realized infrastructure state are distinct
- Validate schema, identity, authorization, idempotency, error handling and partial failure
- Preview/diff, limit blast radius, verify read-after-write and preserve rollback/audit evidence
In depth
Terraform and OpenTofu (its open-source fork) are Infrastructure as Code tools. You declare resources in HCL, the tool compares that with its state file and the real infrastructure, shows a plan of creates, updates and destroys, and then applies it through provider plugins (AWS, Azure, vSphere, NetBox, Cisco and many more).
| Command | Purpose |
|---|---|
init | Download providers, configure backend |
fmt / validate | Format and check syntax |
plan | Show proposed changes |
apply | Make the changes |
destroy | Remove managed resources |
state | Inspect or move state entries |
Store state remotely with locking, pin provider versions, and always review the plan — a renamed resource can mean destroy-and-recreate.
ReferenceConfiguration & state1 section · depth on demand
Concrete configuration contract
Concrete configuration/input contract for Terraform / OpenTofu.
terraform { required_version = ">= 1.8" }
# pin provider constraints and backend explicitly
# review plan before apply; refresh/read back remote state afterward
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.
Lowest-Good remediation source for Terraform / OpenTofu. Documentation authority supports bounded reference claims only; it is not observed lab/production Evidence.
Basis: https://opentofu.org/docs/ · confidence 94%What changed and what may be affected
Recent technical edits are separated from ordinary page timestamps. Relationship impact is advisory: it identifies nearby canonical references to review, not automatic breakage.
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
Terraform / OpenTofu IaC proof-boundary map
Fast definition/state/plan/execution/target-proof boundaries for Terraform / OpenTofu.
| 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 |
Terraform evidence chain
Configuration, operational state, counters and downstream proof remain separate.
| Boundary | Question | Evidence | Does not prove |
|---|---|---|---|
| Definition | What is configured or intended? | running configuration / controller policy | live operation |
| Local state | Is the feature active at the expected scope? | terraform plan | remote success |
| Counters | Did controlled traffic or an event reach this stage? | scoped counters/timestamps | complete return path |
| Next boundary | What consumes or transports this state? | source of truth/input → schema/model → authentication/authorization → plan/diff → controlled execution → task/result → realized-state assertion | application success |
Deep reference
Healthy vs suspicious evidence
Concrete output contract
Concrete output contract for Terraform / OpenTofu. The minimum retained result is: workspace, configuration_revision, plan_summary, resource_address, action, provider_version, remote_id, apply_result, refreshed_state.