What this thread does
Our recommendation: run terraform plan -refresh-only -detailed-exitcode to inspect a refresh-only diff and receive a detailed result code. Plan reference
Short answer
A refresh-only plan shows proposed state/output updates for changes outside Terraform. It does not propose changing remote objects. Decide whether to incorporate the external change into configuration or revert it; a normal plan shows the actions needed to match configuration. Drift tutorial
What to do
| Command or option | Actionable meaning |
|---|---|
terraform plan -refresh-only | Supported in Terraform 0.15.4 and later. Inspect external changes without using the state-overwriting terraform refresh command. |
-detailed-exitcode | 0: success with no changes; 1: error; 2: success with changes. Distinguish an error from a non-empty diff. |
Note: Objects have changed outside of Terraform | The tutorial’s refresh-only output uses this header before listing external changes. |
terraform plan | Read the normal plan to see how configuration would change infrastructure. |
-refresh=false | Disables the default synchronization with remote objects and can hide external changes. It cannot be combined with refresh-only mode. |
-minimal-refresh | Refreshes resource instances with planned changes; a resource schema version change forces refresh regardless of the plan result. External changes to resources with no planned changes may be missed. Cannot be used in refresh-only mode or with -refresh=false. |
-out=FILE | Saves the generated plan; pass the saved filename to terraform apply as an extra argument. Without -out=FILE, the plan is speculative. Re-check the final non-speculative plan before applying. |
The command modes, options and exit codes are from the plan reference; the output header and reconciliation choices are from the drift tutorial.
If the external change is intentional, update the configuration to represent it and inspect the next plan. If configuration remains the desired state, inspect the normal plan before applying the reversal. The tutorial demonstrates incorporating the external change into configuration and explains that a normal plan or apply would otherwise attempt to revert it. Drift tutorial
Limits and open questions
Exit 2 means a non-empty diff, not a diagnosis of its cause. The opened pages establish planning behavior; this draft supplies no scheduled workflow or automatic apply policy. The actual diff still needs a decision about desired infrastructure.
Not for: Pulumi state reconciliation.
Sources
- Terraform plan command — HashiCorp.
- Manage resource drift — HashiCorp.
Started from a post by @r/devops discussion, packaged by the editor. Original post