Skip to content

fix(terraform): stop claiming a partial apply when nothing was applied [NOJIRA] - #346

Open
tobias0106 wants to merge 2 commits into
mainfrom
fix/terraform-apply-failure-message
Open

tobias0106 wants to merge 2 commits into
mainfrom
fix/terraform-apply-failure-message

Conversation

@tobias0106

Copy link
Copy Markdown
Contributor

The terraform-failed issue asserts this unconditionally:

The stack is partially applied. State is accurate for the resources that completed; the plan below is exactly what is left over. This will not resolve itself.

That is false whenever Terraform rejects the plan before acting. It said exactly that on monta-app/terraform#179, where global/clickhouse/production failed with:

Error: Inconsistent dependency lock file

The given plan file was created with a different set of external dependency
selections than the current configuration.

Nothing was applied. The issue still told the assignee the stack was half-changed and would not resolve itself.

Change

Apply output is teed to apply.txt, and the issue reports a partial apply only when Terraform actually started acting on a resource — it prints one <address>: Creating... line per resource, so the absence of all of them means it never began.

started = /^\S+: (Creating|Modifying|Destroying|Still|Creation|Modifications|Destruction)/m
  .test(fs.readFileSync(`${stack}/apply.txt`, 'utf8'))
issue now says
plan rejected up front Terraform rejected the plan before making any change — nothing was applied and the stack is exactly as it was
failed mid-apply The stack is partially applied(unchanged)

The catch defaults to started = true, so if apply.txt is missing for any reason the wording is the old, conservative one.

set -o pipefail is load-bearing, not tidying: without it tee's exit status masks a failed apply and the step reports success.

Also adds the lock-file case to the remediation list, since that is the one that just fired.

Checks

Regex against real output shapes:

NOT started   #179 real failure (pre-flight reject)
started       mid-apply failure
started       module-nested address (module.route53.aws_route53_record.a: Modifying...)
started       destroy (Destroying... / Destruction complete)
NOT started   no-op success

YAML parses; the inline script passes node --check.

🤖 Generated with Claude Code

…d [NOJIRA]

The failure issue asserted "The stack is partially applied" for every
failed apply. When Terraform rejects the plan up front - a lock file
that drifted, a provider that moved - it changes nothing, and the issue
sent the assignee looking for drift that does not exist. It said exactly
that on monta-app/terraform#179.

Apply output now goes to apply.txt, and the issue reports a partial
apply only when Terraform actually started acting on a resource. On any
doubt (no apply.txt) it keeps the old wording.

set -o pipefail is required: without it tee's exit status masks a failed
apply and the step reports success.

Also adds the lock-file case to the remediation list, since that is the
one that just fired.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@tobias0106
tobias0106 requested a review from a team as a code owner September 16, 2026 14:44
@tobias0106
tobias0106 requested review from sudheer-monta and removed request for a team September 16, 2026 14:44
Drops the comment, the const state indirection and four unreachable
regex alternations (Creation/Modifications/Destruction/Still only ever
print after their -ing line). Same behaviour, 10 fewer lines.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant