Skip to content

Commit d29b0a8

Browse files
Add nil check to exprOptions.RecaptchaOptions in google_compute_security_policy (#15125) (#10715)
[upstream:1a52c1d06bcef50a5e2f578aa14d2432dbe9d163] Signed-off-by: Modular Magician <[email protected]>
1 parent cb7a5fb commit d29b0a8

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

.changelog/15125.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:bug
2+
compute: fixed a crash in `google_compute_security_policy` due to a changed API response for empty `match.0.expr_options` blocks
3+
```

google-beta/services/compute/resource_compute_security_policy.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1374,15 +1374,24 @@ func flattenMatchExprOptions(exprOptions *compute.SecurityPolicyRuleMatcherExprO
13741374
return nil
13751375
}
13761376

1377-
// We check if the API is returning a empty non-null value then we find the current value for this field in the rule config and check if its empty
1377+
// The API can return an explicit entry `exprOptions` object, causing evaluation of the `recaptcha_options` settings to fail as it's nil: https://github.com/hashicorp/terraform-provider-google/issues/24334
1378+
// Explicitly check it's available and exit early if not.
1379+
if exprOptions.RecaptchaOptions == nil {
1380+
return nil
1381+
}
1382+
1383+
// The API can return an explicit empty rule causing an issue: https://github.com/hashicorp/terraform-provider-google/issues/16882#issuecomment-2474528447
1384+
// We check if the API is returning a empty non-null value then we find the current value for this field in the rule config and check if its empty.
13781385
if (tpgresource.IsEmptyValue(reflect.ValueOf(exprOptions.RecaptchaOptions.ActionTokenSiteKeys)) &&
13791386
tpgresource.IsEmptyValue(reflect.ValueOf(exprOptions.RecaptchaOptions.SessionTokenSiteKeys))) &&
13801387
verifyRulePriorityCompareEmptyValues(d, rulePriority, "recaptcha_options") {
13811388
return nil
13821389
}
13831390

13841391
data := map[string]interface{}{
1392+
// NOTE: when adding new entries, the recaptcha_options rule above will need to be revised
13851393
"recaptcha_options": flattenMatchExprOptionsRecaptchaOptions(exprOptions.RecaptchaOptions),
1394+
// NOTE: when adding new entries, the recaptcha_options rule above will need to be revised
13861395
}
13871396

13881397
return []map[string]interface{}{data}

0 commit comments

Comments
 (0)