Skip to content

Commit c3c9caf

Browse files
modular-magicianrileykarson
authored andcommitted
Add nil check to exprOptions.RecaptchaOptions in google_compute_security_policy (#15125) (#10715)
[upstream:1a52c1d06bcef50a5e2f578aa14d2432dbe9d163] Signed-off-by: Modular Magician <[email protected]>
1 parent 6a9e0f0 commit c3c9caf

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
@@ -1271,15 +1271,24 @@ func flattenMatchExprOptions(exprOptions *compute.SecurityPolicyRuleMatcherExprO
12711271
return nil
12721272
}
12731273

1274-
// 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
1274+
// 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
1275+
// Explicitly check it's available and exit early if not.
1276+
if exprOptions.RecaptchaOptions == nil {
1277+
return nil
1278+
}
1279+
1280+
// The API can return an explicit empty rule causing an issue: https://github.com/hashicorp/terraform-provider-google/issues/16882#issuecomment-2474528447
1281+
// 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.
12751282
if (tpgresource.IsEmptyValue(reflect.ValueOf(exprOptions.RecaptchaOptions.ActionTokenSiteKeys)) &&
12761283
tpgresource.IsEmptyValue(reflect.ValueOf(exprOptions.RecaptchaOptions.SessionTokenSiteKeys))) &&
12771284
verifyRulePriorityCompareEmptyValues(d, rulePriority, "recaptcha_options") {
12781285
return nil
12791286
}
12801287

12811288
data := map[string]interface{}{
1289+
// NOTE: when adding new entries, the recaptcha_options rule above will need to be revised
12821290
"recaptcha_options": flattenMatchExprOptionsRecaptchaOptions(exprOptions.RecaptchaOptions),
1291+
// NOTE: when adding new entries, the recaptcha_options rule above will need to be revised
12831292
}
12841293

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

0 commit comments

Comments
 (0)