Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

terraform-provider-github #3554 — merge-commit drift reproduction

Reproduces the perpetual drift from integrations/terraform-provider-github#3554 against the published provider v6.13.0, using a throwaway private repository.

It specifically reproduces the shape seen in Storytel/infra-github#3244: commenting out merge_commit_title / merge_commit_message causes drift.

The bug

While allow_merge_commit = false, GitHub refuses to change merge_commit_title / merge_commit_message — the REST API returns HTTP 422 "no_merge_strategy". The provider works around this by silently not sending those fields on apply. The result is a plan/apply mismatch: apply never changes GitHub, yet the fields end up in Terraform state with the planned values, so subsequent plans report "No changes" while state quietly disagrees with GitHub (see steps 6–8 below). The same applies to allow_squash_merge + squash_merge_commit_*.

Why commenting the fields out does NOT help

merge_commit_title / merge_commit_message are Optional with schema defaults:

field default
merge_commit_title MERGE_MESSAGE
merge_commit_message PR_TITLE

Commenting them out does not mean "leave them alone" — when the plan reconciles config it falls back to those defaults. If the repo's actual values differ from the defaults (e.g. a repo holding PR_TITLE / PR_BODY), the commented-out config now effectively asks for MERGE_MESSAGE / PR_TITLE → drift, and it can never be applied while allow_merge_commit = false.

Requirements

  • terraform
  • gh (GitHub CLI), authenticated: gh auth login
    • the token must be able to create and modify a private repo
    • the script reads the token automatically via gh auth token

Usage

./run.sh

Nothing is hardcoded to a particular account. Override via environment:

env var default meaning
OWNER your gh-authenticated user (gh api user) org/user to create the repo under
REPO tpg-issue-3554-probe throwaway repo name
PAUSE_SECS 10 seconds to wait between steps (lets GitHub's read-after-write settle); set 0 to disable
OWNER=my-org REPO=drift-probe ./run.sh

Testing a fixed provider build instead of v6.13.0

Point Terraform at a locally built provider via a dev override and run the same script:

# dev.tfrc
provider_installation {
  dev_overrides { "integrations/github" = "/abs/path/to/dir/containing/binary" }
  direct {}
}
TF_CLI_CONFIG_FILE=/abs/path/dev.tfrc ./run.sh

With a dev override Terraform skips provider installation; the script's init step prints a warning but the override still takes effect. A fixed build (e.g. the diff-suppression fix) makes step4 report no drift — and with no drift to mask, steps 5–8 become trivially clean too.

What the script does

The repo starts with allow_merge_commit = true, merge_commit_title = "PR_TITLE", merge_commit_message = "PR_BODY".

step action expectation
step0 terraform init (installs integrations/github v6.13.0); import repo if it already exists but is missing from state —
step1 apply allow_merge_commit=true (title=PR_TITLE, message=PR_BODY) applied
step2 apply allow_merge_commit=false (title/message still PR_TITLE/PR_BODY) applied; GitHub retains values
step3 plan again, fields still set NO drift (config matches GitHub)
step4 comment out merge_commit_title / merge_commit_message, plan DRIFT (reproduces #3244)
step5 terraform apply the commented-out config OK; but no-op on GitHub
step6 plan after apply NO drift — but the drift is masked, not solved (see below)
step7 terraform apply -refresh-only (attempt to reconcile state with GitHub) "No changes" — refresh does not fix it
step8 plan after refresh NO drift — yet state still ≠ GitHub

The script asserts the load-bearing steps: it exits non-zero if step3 drifts, if step4 does not drift, or if step5 apply fails. steps 6 and 8 print whether drift is present for the record; they don't hard-fail, so the script still passes if a future provider build changes their behaviour.

Why step6 shows no drift (the drift is masked, not solved)

step5's apply "succeeds" but is a no-op on GitHub: while allow_merge_commit = false the provider omits merge_commit_title / merge_commit_message from the PATCH, so GitHub keeps PR_TITLE / PR_BODY (confirmed in the debug logs). However, Update writes the planned values (MERGE_MESSAGE / PR_TITLE) into Terraform state during that no-op apply. So after step5:

  • state says MERGE_MESSAGE / PR_TITLE
  • GitHub still says PR_TITLE / PR_BODY

step6's plan compares state-vs-config, which now match, and reports "No changes." The drift did not converge — it went silent. State disagrees with reality.

Why -refresh-only (step7) doesn't fix it

You might expect terraform apply -refresh-only to pull GitHub's real values back into state and re-expose the drift. It doesn't — because the provider's Read also skips merge_commit_title / merge_commit_message while allow_merge_commit = false. step7 reports "No changes. Your infrastructure still matches the configuration." and leaves the wrong values in state. step8's plan is then clean too — even though state and GitHub still disagree:

state:  merge_commit_title = MERGE_MESSAGE   merge_commit_message = PR_TITLE
GitHub: merge_commit_title = PR_TITLE        merge_commit_message = PR_BODY

That is the most insidious form of the bug: not just a plan that never applies, but a state file that quietly disagrees with reality and that a normal refresh cannot repair. step8 prints both the GitHub: and STATE: values so you can see the mismatch directly.

Logs

Every step writes to logs/:

  • stepN_*.plan.txt — human-readable terraform plan output
  • stepN_*.debug.log — full TF_LOG=DEBUG log for that plan/apply
  • stepN_*.apply.txt — apply output (steps 1, 2, 5 & 7)
  • step0_init.txt, step0_import.txt — setup output
logs/
  step0_init.{txt,debug.log}
  step0_import.{txt,debug.log}   # only if the repo pre-existed
  step1_amc_true.{plan.txt,apply.txt,debug.log}
  step2_amc_false.{plan.txt,apply.txt,debug.log}
  step3_replan.{plan.txt,debug.log}
  step4_commented.{plan.txt,debug.log}
  step5_apply.{apply.txt,debug.log}
  step6_replan_after_apply.{plan.txt,debug.log}
  step7_refresh_only.{apply.txt,debug.log}
  step8_replan_after_refresh.{plan.txt,debug.log}

Expected output (v6.13.0)

step3: DRIFT: NO ✅ (config still matches GitHub)
step4: DRIFT AFTER COMMENTING OUT: YES ✅ (reproduces #3244)
step5: APPLY: OK ✅ (no error; but GitHub values are unchanged)
step6: DRIFT STILL PRESENT: NO      <- drift masked (state written with planned values)
step7: REFRESH: OK ✅ (but does not fix the masked merge_commit_* values)
step8: DRIFT AFTER REFRESH: NO
       STATE:  merge_commit_title=MERGE_MESSAGE merge_commit_message=PR_TITLE
       GitHub: amc=false title=PR_TITLE message=PR_BODY   <- state != GitHub

step4's plan shows the schema defaults being forced back in — the same diff as #3244:

~ merge_commit_message = "PR_BODY"  -> "PR_TITLE"       # PR_TITLE = default
~ merge_commit_title   = "PR_TITLE" -> "MERGE_MESSAGE"  # MERGE_MESSAGE = default

Files

file purpose
run.sh the reproduction script
config_with_fields.tf.tmpl config with merge_commit_title / message set (steps 1–3)
config_commented.tf.tmpl same config with those two fields commented out (step 4)
.gitignore ignores runtime artifacts (main.tf, logs/, .terraform*, terraform.tfstate*)

main.tf is generated at runtime by copying whichever template the current step needs; it is git-ignored.

Re-running / cleanup

Re-runs are safe: if the repo already exists but local state was cleared, step0 imports it. The repo is left in place between runs. Delete it when done (needs the delete_repo scope: gh auth refresh -s delete_repo):

gh repo delete "$OWNER/${REPO:-tpg-issue-3554-probe}" --yes

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages