Skip to content

compute: fix preview=false updates for OrganizationSecurityPolicyRule#18079

Merged
malhotrasagar2212 merged 1 commit into
GoogleCloudPlatform:mainfrom
sumanth-g31:fix-org-security-policy-preview-false
Jul 7, 2026
Merged

compute: fix preview=false updates for OrganizationSecurityPolicyRule#18079
malhotrasagar2212 merged 1 commit into
GoogleCloudPlatform:mainfrom
sumanth-g31:fix-org-security-policy-preview-false

Conversation

@sumanth-g31

@sumanth-g31 sumanth-g31 commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Fixes hashicorp/terraform-provider-google#27885

Summary

This change adds send_empty_value: true to the preview field of
OrganizationSecurityPolicyRule.

Without this annotation, the generated Terraform provider treats
preview = false as an empty value and omits it from create and update
requests. As a result, users cannot reliably update a rule from:

preview = true

to

preview = false

because the PATCH request does not include the preview field.

Root cause

The generated provider code used the condition:

!tpgresource.IsEmptyValue(reflect.ValueOf(v))

Since IsEmptyValue() considers the boolean value false to be empty,
preview = false was filtered out and never added to the request body.

Adding send_empty_value: true causes Magic Modules to generate:

ok || !reflect.DeepEqual(v, previewProp)

which preserves explicitly configured false values.

compute: fixed an issue where `preview = false` updates for `google_compute_organization_security_policy_rule` were omitted from API requests.

Verification

  • Added send_empty_value: true to the preview property in OrganizationSecurityPolicyRule.yaml.
  • Regenerated the Terraform provider.
  • Verified that the generated resource_compute_organization_security_policy_rule.go
    now includes preview whenever it is explicitly configured, including false.
  • Verified that the generated behavior now matches the existing implementation for
    SecurityPolicyRule and RegionSecurityPolicyRule.

Background

I initially investigated this issue in hashicorp/terraform-provider-google and opened hashicorp/terraform-provider-google#28000.

As suggested by @melinath in that PR, this fix has been moved to Magic Modules since the provider code is generated from this repository.

@modular-magician modular-magician added the awaiting-approval Pull requests that need reviewer's approval to run presubmit tests label Jun 25, 2026
@google-cla

google-cla Bot commented Jun 25, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@github-actions

github-actions Bot commented Jun 25, 2026

Copy link
Copy Markdown

Googlers: For automatic test runs see go/terraform-auto-test-runs.

@malhotrasagar2212, a repository maintainer, has been assigned to review your changes. If you have not received review feedback within 2 business days, please leave a comment on this PR asking them to take a look.

You can help make sure that review is quick by doing a self-review and by running impacted tests locally.

@github-actions
github-actions Bot requested a review from rileykarson June 25, 2026 05:47
@rileykarson

Copy link
Copy Markdown
Member

@modular-magician reassign-reviewer

@github-actions
github-actions Bot requested review from malhotrasagar2212 and removed request for rileykarson June 28, 2026 23:54
@sumanth-g31

Copy link
Copy Markdown
Contributor Author

Hi @malhotrasagar2212, just wanted to follow up on this PR whenever you have a chance. This addresses the preview=false update issue for google_compute_organization_security_policy_rule by marking the field with send_empty_value: true in Magic Modules so the generated provider includes preview=false in PATCH requests. I also added an acceptance test covering preview=truepreview=false.

I'd appreciate a review when you have time. Thanks!

@modular-magician modular-magician added service/compute-security-policy and removed awaiting-approval Pull requests that need reviewer's approval to run presubmit tests labels Jun 30, 2026
@modular-magician

modular-magician commented Jun 30, 2026

Copy link
Copy Markdown
Collaborator

Hi there, I'm the Modular magician. I've detected the following information about your changes for commit b7960f7:

Diff report

Your PR generated the following diffs in downstream repositories:

Repository Diff Link Changes
google provider View Diff 1 file changed, 2 insertions(+), 2 deletions(-)
google-beta provider View Diff 1 file changed, 2 insertions(+), 2 deletions(-)
terraform-google-conversion View Diff 1 file changed, 1 insertion(+), 1 deletion(-)

Test report

Analytics

Total Tests Passed Skipped Affected
1508 1408 94 6
Affected Service Packages
  • compute

Learn how VCR tests work


Step 1: Replaying Mode

Action taken

Found 6 affected test(s) by replaying old test recordings. Starting RECORDING based on the most recent commit.

Click here to see the affected tests
  • TestAccComputeOrganizationSecurityPolicyRule_organizationSecurityPolicyRuleExpressionUpdate
  • TestAccComputeOrganizationSecurityPolicyRule_organizationSecurityPolicyRuleFirewallUpdate
  • TestAccComputeOrganizationSecurityPolicyRule_organizationSecurityPolicyRuleUpdate
  • TestAccComputeOrganizationSecurityPolicyRule_organizationSecurityPolicyRuleWithHeaderAction
  • TestAccComputeOrganizationSecurityPolicyRule_organizationSecurityPolicyRuleWithPreconfiguredWafConfig
  • TestAccComputeOrganizationSecurityPolicyRule_organizationSecurityPolicyRuleWithRedirect

View the replaying VCR build log


Step 2: Recording Mode

Recording Mode Replaying Rerun Test Name
✅ Log TestAccComputeOrganizationSecurityPolicyRule_organizationSecurityPolicyRuleExpressionUpdate
✅ Log TestAccComputeOrganizationSecurityPolicyRule_organizationSecurityPolicyRuleFirewallUpdate
✅ Log TestAccComputeOrganizationSecurityPolicyRule_organizationSecurityPolicyRuleUpdate
✅ Log TestAccComputeOrganizationSecurityPolicyRule_organizationSecurityPolicyRuleWithHeaderAction
✅ Log TestAccComputeOrganizationSecurityPolicyRule_organizationSecurityPolicyRuleWithPreconfiguredWafConfig
✅ Log TestAccComputeOrganizationSecurityPolicyRule_organizationSecurityPolicyRuleWithRedirect

🟢 All tests passed!

View the recording VCR build log or the debug logs folder for detailed results.

@sumanth-g31, @malhotrasagar2212 VCR tests complete for b7960f7!

@github-actions

github-actions Bot commented Jul 2, 2026

Copy link
Copy Markdown

@malhotrasagar2212 This PR has been waiting for review for 3 weekdays. Please take a look! Use the label disable-review-reminders to disable these notifications.

@github-actions

github-actions Bot commented Jul 6, 2026

Copy link
Copy Markdown

@GoogleCloudPlatform/terraform-team @malhotrasagar2212 This PR has been waiting for review for 1 week. Please take a look! Use the label disable-review-reminders to disable these notifications.

@malhotrasagar2212 malhotrasagar2212 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, Thanks!

@sumanth-g31

Copy link
Copy Markdown
Contributor Author

Thanks everyone! I appreciate the review and the guidance on moving the fix to Magic Modules.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

google_compute_organization_security_policy_rule fails to update preview from true to false (unexpected new value cty.True)

4 participants