Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add customize diff to prevent two rules with the same priority #3202

Merged

Conversation

megan07
Copy link
Contributor

@megan07 megan07 commented Mar 3, 2020

Added CustomizeDiff to prevent users from adding/updating the security policy with two rules of the same priority.

Fixes hashicorp/terraform-provider-google#5804

Release Note Template for Downstream PRs (will be copied)

compute: fixed `google_compute_security_policy` from allowing two rules with the same priority.

@megan07 megan07 requested a review from danawillow March 3, 2020 16:37
@modular-magician
Copy link
Collaborator

Hi! I'm the modular magician. Your PR generated some diffs in downstreams - here they are.

Diff report:

Terraform GA: Diff ( 2 files changed, 69 insertions(+))
Terraform Beta: Diff ( 2 files changed, 69 insertions(+))

@danawillow
Copy link
Contributor

Mind asking someone else for a review? I've got a lot on my plate this week and next and trying to offload as many non-perf tasks as possible.

@megan07 megan07 requested review from nat-henderson and removed request for danawillow March 3, 2020 22:12

nPriorities := map[int64]bool{}
for _, rule := range nSet.List() {
priority := int64(rule.(map[string]interface{})["priority"].(int))
Copy link
Contributor

Choose a reason for hiding this comment

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

This will panic if the values aren't set correctly - is that okay? I'm not sure what invariants TF provides for types, unfortunately.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Terraform should verify that priority is an int before we get here. Is that what you're asking? Very similar code is used in the update function and it seems we haven't hit any problems with that yet (https://github.com/terraform-providers/terraform-provider-google/blob/master/google/resource_compute_security_policy.go#L254), however if you feel more comfortable with double-checking it, I can certainly throw some checks around here.

@@ -97,6 +97,11 @@ func TestAccComputeSecurityPolicy_update(t *testing.T) {
ImportStateVerify: true,
},

{
Config: testAccComputeSecurityPolicy_updateSamePriority(spName),
ExpectError: regexp.MustCompile("Two rules have the same priority, please update one of the priorities to be different."),
Copy link
Contributor

Choose a reason for hiding this comment

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

nice! thank you!!

@megan07 megan07 force-pushed the megan_sec_rule_priorities branch from f8b92b2 to 07597d8 Compare March 5, 2020 18:48
@modular-magician
Copy link
Collaborator

Hi! I'm the modular magician. Your PR generated some diffs in downstreams - here they are.

Diff report:

Terraform GA: Diff ( 2 files changed, 69 insertions(+))
Terraform Beta: Diff ( 2 files changed, 69 insertions(+))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

google_compute_security_policy - no error message when rule has same priority
5 participants