Skip to content

Commit ef8fcbf

Browse files
authored
fix: resolve oauth2_client_id permadiff in backend services (GoogleCloudPlatform#17087)
1 parent 4134d93 commit ef8fcbf

4 files changed

Lines changed: 80 additions & 0 deletions

File tree

mmv1/products/compute/BackendService.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -891,6 +891,7 @@ properties:
891891
description: |
892892
OAuth2 Client ID for IAP
893893
send_empty_value: true
894+
diff_suppress_func: 'tpgresource.EmptyOrDefaultStringSuppress(" ")'
894895
- name: 'oauth2ClientSecret'
895896
type: String
896897
description: |

mmv1/products/compute/RegionBackendService.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -901,6 +901,7 @@ properties:
901901
description: |
902902
OAuth2 Client ID for IAP
903903
send_empty_value: true
904+
diff_suppress_func: 'tpgresource.EmptyOrDefaultStringSuppress(" ")'
904905
- name: 'oauth2ClientSecret'
905906
type: String
906907
description: |

mmv1/third_party/terraform/services/compute/resource_compute_backend_service_test.go.tmpl

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3436,3 +3436,44 @@ resource "google_compute_http_health_check" "zero" {
34363436
}
34373437
`, serviceName, tagKey, tagValue, checkName)
34383438
}
3439+
3440+
func TestAccComputeBackendService_iapOauthClientIdPermadiff(t *testing.T) {
3441+
t.Parallel()
3442+
3443+
context := map[string]interface{}{
3444+
"random_suffix": acctest.RandString(t, 10),
3445+
}
3446+
3447+
acctest.VcrTest(t, resource.TestCase{
3448+
PreCheck: func() { acctest.AccTestPreCheck(t) },
3449+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
3450+
CheckDestroy: testAccCheckComputeBackendServiceDestroyProducer(t),
3451+
Steps: []resource.TestStep{
3452+
{
3453+
// Step 1: Explicitly set to a single space (simulating API state)
3454+
Config: testAccComputeBackendService_iapOauthClientId(context, " "),
3455+
},
3456+
{
3457+
// Step 2: Remove it from config (set to empty)
3458+
// With the fix, this should NOT trigger an update.
3459+
Config: testAccComputeBackendService_iapOauthClientId(context, ""),
3460+
PlanOnly: true,
3461+
},
3462+
},
3463+
})
3464+
}
3465+
3466+
func testAccComputeBackendService_iapOauthClientId(context map[string]interface{}, clientId string) string {
3467+
context["client_id"] = clientId
3468+
return acctest.Nprintf(`
3469+
resource "google_compute_backend_service" "myservice" {
3470+
name = "tf-test-iap-diff-%{random_suffix}"
3471+
iap {
3472+
enabled = true
3473+
oauth2_client_id = "%{client_id}"
3474+
oauth2_client_secret = "my-secret"
3475+
}
3476+
load_balancing_scheme = "EXTERNAL"
3477+
}
3478+
`, context)
3479+
}

mmv1/third_party/terraform/tpgresource/common_diff_suppress_test.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,3 +252,40 @@ func TestBase64DiffSuppress(t *testing.T) {
252252
}
253253
}
254254
}
255+
256+
func TestEmptyOrDefaultStringSuppress_IAP(t *testing.T) {
257+
// The fix we added: tpgresource.EmptyOrDefaultStringSuppress(" ")
258+
suppressor := EmptyOrDefaultStringSuppress(" ")
259+
260+
cases := map[string]struct {
261+
Old, New string
262+
ExpectDiffSuppress bool
263+
}{
264+
"API returns space, config is empty": {
265+
Old: " ",
266+
New: "",
267+
ExpectDiffSuppress: true,
268+
},
269+
"API returns space, config is null": {
270+
Old: " ",
271+
New: "",
272+
ExpectDiffSuppress: true,
273+
},
274+
"Config has space, API returns empty": {
275+
Old: "",
276+
New: " ",
277+
ExpectDiffSuppress: true,
278+
},
279+
"Actual Client ID change (Should NOT suppress)": {
280+
Old: " ",
281+
New: "actual-id",
282+
ExpectDiffSuppress: false,
283+
},
284+
}
285+
286+
for tn, tc := range cases {
287+
if suppressor("iap.0.oauth2_client_id", tc.Old, tc.New, nil) != tc.ExpectDiffSuppress {
288+
t.Errorf("failed case %s: Old='%s', New='%s', expected suppress=%t", tn, tc.Old, tc.New, tc.ExpectDiffSuppress)
289+
}
290+
}
291+
}

0 commit comments

Comments
 (0)