-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Remove default from optional rule_visibility
field
#8060
Remove default from optional rule_visibility
field
#8060
Conversation
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. |
Hello! I am a robot who works on Magic Modules PRs. I've detected that you're a community contributor. @SarahFrench, a repository maintainer, has been assigned to assist you and help review your changes. ❓ First time contributing? Click here for more detailsYour assigned reviewer will help review your code by:
You can help make sure that review is quick by running local tests and ensuring they're passing in between each push you make to your PR's branch. Also, try to leave a comment with each push you make, as pushes generally don't generate emails. If your reviewer doesn't get back to you within a week after your most recent change, please feel free to leave a comment on the issue asking them to take a look! In the absence of a dedicated review dashboard most maintainers manage their pending reviews through email, and those will sometimes get lost in their inbox. |
I can't run the acceptance tests locally because my org has hit its security policy quota 🥲
I did run a manual test here, but as I said in the PR description, I've only solved the second of the two problems. If I do: adaptive_protection_config {
layer_7_ddos_defense_config {
enable = false
}
} Then I get no diff, but ideally I wouldn't even have to write that; not having an |
Hi there, I'm the Modular magician. I've detected the following information about your changes: Breaking Change(s) DetectedThe following breaking change(s) were detected within your pull request.
If you believe this detection to be incorrect please raise the concern with your reviewer. If you intend to make this change you will need to wait for a major release window. An Diff reportYour PR generated some diffs in downstreams - here they are. Terraform GA: Diff ( 1 file changed, 1 deletion(-)) |
Tests analyticsTotal tests: Action takenFound 9 affected test(s) by replaying old test recordings. Starting RECORDING based on the most recent commit. Click here to see the affected testsTestAccBillingSubaccount_basic|TestAccBillingSubaccount_renameOnDestroy|TestAccComputeFirewallPolicyRule_multipleRules|TestAccAlloydbBackup_missingLocation|TestAccApigeeKeystoresAliasesPkcs12_ApigeeKeystoresAliasesPkcs12Example|TestAccAlloydbCluster_missingLocation|TestAccDataSourceGoogleFirebaseAndroidAppConfig|TestAccDataSourceAlloydbLocations_basic|TestAccApigeeKeystoresAliasesKeyCertFile_apigeeKeystoresAliasesKeyCertFileTestExample |
This is accurate, although I always find this case tricky: I contend that the current default is wrong and already causing problems, but I understand if this means it needs to wait for a new major version. The only case (AFAICT) that will break in this way is: adaptive_protection_config {
layer_7_ddos_defense_config {
enable = true
}
} Which will need to become: adaptive_protection_config {
layer_7_ddos_defense_config {
enable = true
rule_visibility = "STANDARD"
}
} Is there a way to say that the default only applies when the other field is present? It looks like I could do that in |
Tests passed during RECORDING mode: Tests failed during RECORDING mode: Please fix these to complete your PR |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi 👋 - Thanks for your PR to address this issue! I'm currently thinking about whether there are different ways to approach this so it is less of a breaking change for users who have enable = true
and no rule_visibility
value in their config but already have rule_visibility = "STANDARD"
in their state file. I'll get back to you on that after I've had a think.
Some feedback I can give now though is that a good addition to this PR would be a test that shows a google_compute_security_policy
resource can be made without error when it contains this block:
adaptive_protection_config {
layer_7_ddos_defense_config {
enable = false
}
}
I saw that you're not able to run acceptance tests yourself, but could you please update the acceptance tests for this resource to include creation of a policy where the config contains that block above? Although you can't run the tests you can push test code to this PR to run them. I've supplied some info below to help with this as not being able to run the tests makes writing them tougher.
Acceptance test context & info
Currently there's an acceptance test called TestAccComputeSecurityPolicy_withAdaptiveProtection
that covers use of this resource but is missing the scenario that triggers this bug. That test starts by creating the adaptive protection config with enable = true
+ rule_visibility = "STANDARD"
and then performs an update that changes it to enable = false
+ rule_visibility = "STANDARD"
in a subsequent update. The test doesn't fail because it seems the API doesn't have the same validation when creating a policy versus when updating it.
I'll leave it up to you to decide whether to adapt the existing TestAccComputeSecurityPolicy_withAdaptiveProtection
function to have an extra step or to create a new standalone test, but you will need to create a new function to supply the config that triggers this problem addressed by this PR (achieved by making a variation of this function).
Thanks @SarahFrench, that's very helpful. I have never looked at the internals of a Terraform provider before, but here's what I think I want to express:
I'd love a better way to do this than I have right now. I will update the tests next week, thanks for the pointers. (I'll also see if we can get our quota increased.)
This is interesting, because we are updating an existing policy in our case 🤔 Maybe it's allowed for a state change, like you suggest. I might have a play around with the API once I get a quota increase too. |
In case I'm causing confusion, the test creates a
and then updates it to:
...and this doesn't trigger the |
Right. In our case in production, I tried setting (on an existing policy that can't be represented in the current version of the provider, but is equivalent to adaptive_protection_config {
layer_7_ddos_defense_config {
enable = false
rule_visibility = "STANDARD"
}
} And got that error. I wonder if it's because in the test here, the config already has |
How weird! For what it's worth, the API calls in that test are: Creating the resource
Updating the resource
That update works without validation errors 🤷 . I think this confusion shows that beefing up the acceptance tests definitely has value. It's the end of my Friday here in my timezone, but when you push those test changes next week we can pick up again 👋 |
`google_compute_security_policy` -> `adaptive_protection_config` -> `layer_7_ddos_defense_config` -> `rule_visibility` is optional, but had a default value, and was required to be either PREMIUM or STANDARD. This means that: 1. If you did not include this block at all, you get a persistent message about changing this from `false` (in state) to `null` (in config, due to the missing default). 2. If you included this block with `enable = false`, you'd get a plan attempting to set `rule_visibility = "STANDARD"`, which would then fail: > Invalid value for field > 'resource.adaptiveProtectionConfig.layer7DdosDefenseConfig.enable': > 'false'. Cannot set layer 7 DDoS options if it's not enabled. This fixes the second problem, but not the first.
968c387
to
fa19d39
Compare
I added a test that fails without this change. I haven't done any further exploration here yet so feel free to skip that push as it's not very interesting. |
It looks like DiffSuppressFunc could provide this? There are a few already in /~https://github.com/GoogleCloudPlatform/magic-modules/blob/main/tpgtools/ignored_handwritten/common_diff_suppress.go, although none handle I think if I provided that then the main problem goes away without needing to make a breaking change. (Also, @SarahFrench I hope you weren't hit in the recent layoffs.) |
Thanks for your concern 💟 - I'm still here
I think this would be worth addressing in a separate PR, because if we bundle non-breaking changes up with a breaking change in one PR then their release may be unnecessarily delayed. This PR could be included as a reference to refer to though, so our discussions aren't wasted.
Yeah that's the correct approach! I'll have to return to this PR next week, thanks for your patience! |
Hi there, I'm the Modular magician. I've detected the following information about your changes: Breaking Change(s) DetectedThe following breaking change(s) were detected within your pull request.
If you believe this detection to be incorrect please raise the concern with your reviewer. If you intend to make this change you will need to wait for a major release window. An Diff reportYour PR generated some diffs in downstreams - here they are. Terraform GA: Diff ( 2 files changed, 37 insertions(+), 1 deletion(-)) |
Tests analyticsTotal tests: Action takenFound 7 affected test(s) by replaying old test recordings. Starting RECORDING based on the most recent commit. Click here to see the affected testsTestAccComputeSecurityPolicy_withoutAdaptiveProtection|TestAccComputeFirewallPolicyRule_multipleRules|TestAccBigQueryDataTable_bigtable|TestAccApigeeKeystoresAliasesKeyCertFile_apigeeKeystoresAliasesKeyCertFileTestExample|TestAccApigeeKeystoresAliasesPkcs12_ApigeeKeystoresAliasesPkcs12Example|TestAccDataSourceGoogleFirebaseAndroidAppConfig|TestAccDataSourceAlloydbLocations_basic |
Tests passed during RECORDING mode: Tests failed during RECORDING mode: Please fix these to complete your PR |
@SarahFrench I'm glad to hear that. There is no need to review this as it is, let me rethink a bit now I've seen more of the options for the schema here. In #8060 (comment) I said I wanted:
I don't think we need the breaking change in this PR at all. We can do 1 with the DiffSuppressFunc, as you confirmed above. If we do that, then I personally don't care about 2 and 3. But I think a better breaking change would be to set RequiredWith on I'll create a new PR for item 1 once I've confirmed it fixes my immediate problem (persistent diff when nothing changed). |
@SarahFrench unfortunately the DiffSuppressFunc approach won't work 😞 When we run this, we effectively remove the entire block (which is why the diffs show the whole block changing), and DiffSuppressFunc runs on those blocks, not on the individual fields. I tested this by adding this func (with a different prefix) everywhere: func(k, old, new string, d *schema.ResourceData) bool {
fmt.Printf("adaptive_protection_config: {%#v} {%#v}\n", old, new)
return old == new
} When running a test to simulate this scenario, I got the below, with no calls for the
So I have two problems:
I can't see a way to fix the first case from the description, sadly. This PR still fixes the second case, so if I manually add the block with Does that work for you? If so, I'll update the PR to fix the conflicts. |
@SarahFrench ping 🙂 I got a note on another PR about the 5.0 release. What do you think about including this too? |
@GoogleCloudPlatform/terraform-team This PR has been waiting for review for 3 weeks. Please take a look! Use the label |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @smcgivern sorry for the long pause in this PR. After discussing the issue in our team we think we could change this field to no longer have a default but also have the field be Optional: true and Computed: true in its definition. This would stop the change being a breaking change and we can merge outside a major release cycle.
Making the field both optional and computed (O+C) We would then make the provider either use the value from a user's config to set the field, or let users not set that field in their config and Terraform will save the value returned from the API into state. Enabling that second behaviour via Computed: true will make this a non breaking change.
Would you be available to make these changes to the resource? If not I'm happy to open a PR myself to get your desired fix merged faster.
Superseded by #10823 |
google_compute_security_policy
->adaptive_protection_config
->layer_7_ddos_defense_config
->rule_visibility
is optional, but had a default value, and was required to be either PREMIUM or STANDARD.This means that:
If you did not include this block at all, you get a persistent message about changing this from
false
(in state) tonull
(in config, due to the missing default).If you included this block with
enable = false
, you'd get a plan attempting to setrule_visibility = "STANDARD"
, which would then fail:This fixes the second problem, but not the first.
Part of hashicorp/terraform-provider-google#12743
If this PR is for Terraform, I acknowledge that I have:
make test
andmake lint
in the generated providers to ensure it passes unit and linter tests.Release Note Template for Downstream PRs (will be copied)