-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
Fix the difference between aws_waf_byte_match_set and aws_wafregional_byte_match_set #5043
Conversation
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 @chroju 👋 Thanks for submitting this. When renaming attributes, we need to be sure to keep backwards compatibility for at least one major version by deprecating the existing attribute. This change also requires documentation. Please see below for notes.
@@ -24,7 +24,7 @@ func resourceAwsWafByteMatchSet() *schema.Resource { | |||
Required: true, | |||
ForceNew: true, | |||
}, | |||
"byte_match_tuples": &schema.Schema{ |
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.
We need to duplicate the entire existing byte_match_tuples
attribute into the new byte_match_tuple
attribute. Then in the existing byte_match_tuples
attribute, we need to add some additional fields, e.g.
Computed: true,
ConflictsWith: []string{"byte_match_tuple"},
Deprecation: "use `byte_match_tuple` instead",
@@ -107,7 +107,7 @@ func resourceAwsWafByteMatchSetRead(d *schema.ResourceData, meta interface{}) er | |||
} | |||
|
|||
d.Set("name", resp.ByteMatchSet.Name) | |||
d.Set("byte_match_tuples", flattenWafByteMatchTuples(resp.ByteMatchSet.ByteMatchTuples)) |
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.
When renaming attributes, we need to ensure both the old and new are still read into the Terraform state.
@@ -117,8 +117,8 @@ func resourceAwsWafByteMatchSetUpdate(d *schema.ResourceData, meta interface{}) | |||
|
|||
log.Printf("[INFO] Updating ByteMatchSet: %s", d.Get("name").(string)) | |||
|
|||
if d.HasChange("byte_match_tuples") { |
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.
The existing logic for byte_match_tuples
must be preserved in addition to the new byte_match_tuple
@@ -24,7 +24,7 @@ func resourceAwsWafByteMatchSet() *schema.Resource { | |||
Required: true, | |||
ForceNew: true, | |||
}, | |||
"byte_match_tuples": &schema.Schema{ | |||
"byte_match_tuple": &schema.Schema{ |
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.
The documentation in website/docs/r/waf_byte_match_set.html.markdown
should add the new attribute and add a deprecated notice to the existing attribute.
aws/resource_aws_waf_rule_test.go
Outdated
@@ -402,15 +402,15 @@ func testAccAWSWafRuleConfig_changePredicates(name string) string { | |||
return fmt.Sprintf(` | |||
resource "aws_waf_ipset" "ipset" { | |||
name = "%s" | |||
ip_set_descriptors { |
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.
Was this change intentional?
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.
Sorry, this is my mistake. Too mach changes were in the commit.
For what its worth, there can be multiple ByteMatchSet tuples as the attribute is |
@bflad Thanks for your review and comments. I have noticed that this is so complex and breaking change than I thought. There are much more inconsistent attributes about AWS WAF and AWS WAFRegional, and it is debatable whether each of them should be plural or singular. So, at first I would fix this PR not about these all inconsistent attributes but only |
The maintainers would love this. ❤️ Design decisions in the issue and single resource/data source pull requests (easier to review/test quickly) is perfect. Thanks for tackling this, its quite complex! |
I have reflected your review.
|
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.
LGTM -- this should cover properly deprecating the old attribute and migrating it to the new one. Thanks for this @chroju! I'll include an additional note in the CHANGELOG about this deprecation as well.
5 tests passed (all tests)
=== RUN TestAccAWSWafRegionalByteMatchSet_disappears
--- PASS: TestAccAWSWafRegionalByteMatchSet_disappears (8.93s)
=== RUN TestAccAWSWafRegionalByteMatchSet_noByteMatchTuples
--- PASS: TestAccAWSWafRegionalByteMatchSet_noByteMatchTuples (11.31s)
=== RUN TestAccAWSWafRegionalByteMatchSet_basic
--- PASS: TestAccAWSWafRegionalByteMatchSet_basic (16.36s)
=== RUN TestAccAWSWafRegionalByteMatchSet_changeNameForceNew
--- PASS: TestAccAWSWafRegionalByteMatchSet_changeNameForceNew (24.54s)
=== RUN TestAccAWSWafRegionalByteMatchSet_changeByteMatchTuples
--- PASS: TestAccAWSWafRegionalByteMatchSet_changeByteMatchTuples (39.42s)
This has been released in version 1.27.0 of the AWS provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading. |
After changing
into: I get the following change in terraform: But I end up with an empty filter in WAF |
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks! |
Changes proposed in this pull request:
Some aws waf and aws waf-regional API have same attributes each other. However, Terraform
aws_waf_***
resources andaws_wafregional_***
resources have same attributes with the different name, one is singular and the other is plural. Although this is mentioned a little in #4137 , this discrepancy can also be seen in several other resources about AWS WAF(Regional).This PR will fix such inconsistencies. I think it would be better to unify in singular names, because these attributes type is not
list
butmap
.Output from acceptance testing:
WIP