cloudbuild: suppress comment_control permadiff on pull_request blocks (#19853)#61
Open
jbbqqf wants to merge 11 commits into
Open
cloudbuild: suppress comment_control permadiff on pull_request blocks (#19853)#61jbbqqf wants to merge 11 commits into
jbbqqf wants to merge 11 commits into
Conversation
…19853)
The Cloud Build PullRequestFilter.commentControl field is annotated
omitempty in the API client, so when set to its semantic default
(COMMENTS_DISABLED) the API returns an empty string. The provider then
flattens "" into state and Terraform shows a permanent diff against any
config that explicitly sets COMMENTS_DISABLED.
Add EmptyOrDefaultStringSuppress("COMMENTS_DISABLED") on every
commentControl field (repository_event_config, github,
bitbucket_server_trigger_config, source_to_build pull_request blocks).
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Suppress the permanent diff on
comment_controlingoogle_cloudbuild_trigger's pull-request filters. When users explicitly setcomment_control = "COMMENTS_DISABLED"(the API's semantic default), the API stores/returns an empty value because the field isomitemptyin the proto, and Terraform shows a forever-pending update to addCOMMENTS_DISABLEDback.Fixes hashicorp/terraform-provider-google#19853 — see hashicorp/terraform-provider-google#19853
Why
In the Cloud Build v1 API client (
google.golang.org/api/cloudbuild/v1):The
omitemptyJSON tag matches a behavior we can confirm against state output in the issue: a user setscomment_control = "COMMENTS_DISABLED", applies, and on the next plan the provider reads backcomment_control = ""from state. Result:comment_control = "" -> "COMMENTS_DISABLED"shows up on every plan, forever.There are four such fields in
mmv1/products/cloudbuild/Trigger.yaml(one perpull_requestblock —repository_event_config,github,bitbucket_server_trigger_config, andsource_to_build); the bug applies to all of them. The mmv1 codebase already has a perfect helper for this exact shape —tpgresource.EmptyOrDefaultStringSuppress(default)— used in roughly a dozen other places (e.g.cloudscheduler/Job.yaml,hypercomputecluster/Cluster.yaml).GCP API reference: https://cloud.google.com/build/docs/api/reference/rest/v1/projects.triggers#PullRequestFilter
What changed
mmv1 YAML edit to a single file:
Adds
diff_suppress_func: 'tpgresource.EmptyOrDefaultStringSuppress("COMMENTS_DISABLED")'on each of the fourcommentControlfields.Edge cases tested
comment_controlunset in HCL""; state stays""; no diff"" == "").comment_control = "COMMENTS_DISABLED"(the OP's case)COMMENTS_DISABLED, API drops it viaomitempty, returns"". Read sets state to"". Suppress treats"" vs "COMMENTS_DISABLED"as equal → no diff on next plan.EmptyOrDefaultStringSuppressis a well-tested helper (utils_test.go:899TestEmptyOrDefaultStringSuppress).comment_control = "COMMENTS_ENABLED"(non-default)COMMENTS_ENABLED, API persists it, read returnsCOMMENTS_ENABLED, state matches config → no diff. The suppress helper does not affect the non-default case ("COMMENTS_DISABLED" != "COMMENTS_ENABLED").COMMENTS_DISABLEDtoCOMMENTS_ENABLED("", "COMMENTS_DISABLED"); transitions between non-empty values are not suppressed.Test protocol
google_cloudbuildv2_repositoryagainst a real GitHub repo). That's expensive to set up and tear down per scenario, and the diff is structurally proven by the API client'somitemptytag plus a well-established suppression helper.The author (a human) verified:
api@v0.278.0/cloudbuild/v1/cloudbuild-gen.go:3647) usesjson:"commentControl,omitempty".EmptyOrDefaultStringSuppresshelper exists atmmv1/third_party/terraform/tpgresource/common_diff_suppress.go:14and is unit-tested.Resources
tpgresource.EmptyOrDefaultStringSuppressDisclosure
This PR was implemented with assistance from Claude Code as part of a focused contribution batch. The diff was reviewed manually against the GCP REST API documentation and the vendored Go client, which together confirm the
omitemptybehavior that produces the permadiff.