Automation-friendly plan result
terraform plan -detailed-exitcode -out=tfplan
# exit 0: no changes; 2: changes; 1: error
terraform apply tfplan- CI systems can distinguish no-change, change and error outcomes.
Interpret plan actions, use detailed exit codes and saved plans in automation, and distinguish configuration changes from drift and refresh-only reconciliation.
Terraform plans compare desired configuration, prior state and provider observations. Review replacements and destroys carefully because they can have availability or data consequences.
terraform plan -out=FILE creates a plan artifact that terraform apply FILE can execute. This prevents an apply from silently recalculating a different plan after review. Plan files can contain sensitive data and should be protected.
If infrastructure changes outside Terraform, refresh during planning may detect drift. -refresh-only can reconcile state/output values without changing remote objects. -target is mainly for exceptional recovery/diagnosis, not routine dependency management.
terraform plan -detailed-exitcode -out=tfplan
# exit 0: no changes; 2: changes; 1: error
terraform apply tfplanGoal: Create a plan artifact, apply it, then detect a configuration change with detailed exit codes.
mkdir -p ~/gnu-terraform-labs/module09 && cd ~/gnu-terraform-labs/module09
cat > main.tf <<'EOF'
resource "terraform_data" "release" {
input = "v1"
}
EOF
terraform initterraform plan -out=tfplan
terraform show tfplanterraform apply -auto-approve tfplansed -i 's/"v1"/"v2"/' main.tf
set +e
terraform plan -detailed-exitcode >/tmp/tf-plan.out
rc=$?
set -e
echo "exit=$rc"
test "$rc" -eq 2A mature delivery pipeline often separates plan generation/review from apply while preserving the exact approved plan artifact.
Open each answer only after you have tried to answer the question yourself.
2.
To apply the exact set of reviewed changes rather than recalculate at apply time.
A difference caused by changes to managed infrastructure outside the desired Terraform configuration/workflow.
Progress is saved in this browser immediately. When you sign in to My Learning, it can also sync across devices.
Attempt the core lab and knowledge checks before marking the module complete.