-
Notifications
You must be signed in to change notification settings - Fork 9.6k
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
provider/aws: AWS WAF Regional IPSet + ByteMatchSet support #13705
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.
Thanks again for splitting this out. It's so much easier to review! 👍 💯
I left you some comments there - some are rather nitpicks, some are more important.
Read()
funcs not setting all fields and region-based locking are the main ones.
I will ping you once I have a PR for WAF fixes ready - just for the reference. 😃
ByteMatchSetId: aws.String(d.Id()), | ||
} | ||
|
||
ByteMatchTuples := d.Get("byte_match_tuples").(*schema.Set) |
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.
Perhaps a nitpick, but It's a convention to keep all internal variables (valid only within the context of a function) with lowercased letter at the beginning.
} | ||
|
||
d.Set("name", resp.ByteMatchSet.Name) | ||
|
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.
I think we're missing some fields here, specifically byte_match_tuples
and all nested fields under it. The expectation from the Terraform user is that for any resource Terraform will detect drifts from the configuration. In order to do that we need to set all the available data from the API via d.Set()
here in Read func.
Sets can be slightly trickier to work with, I will try and fix the WAF resources first and point you there for reference instead of trying to explain how this can be done. 😅
It's probably the cause of some of the reported WAF bugs I saw earlier, so it's worth fixing there either way.
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.
btw. this would also break import functionality when it's actually implemented as it leverages Read()
(at least the default implementation)
resource.TestStep{ | ||
Config: testAccAWSWafRegionalByteMatchSetConfig(byteMatchSet), | ||
Check: resource.ComposeTestCheckFunc( | ||
testAccCheckAWSWafRegionalByteMatchSetExists("aws_wafregional_byte_match_set.byte_set", &v), |
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.
It would be nice to have some checks for the real object, i.e. v
- like we have in many other resources, but it's not a blocker for the PR. 👌
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.
Given how the sets and lists are represented in HCL, i.e.
byte_match_tuples {
...
}
byte_match_tuples {
...
}
it would make more sense if this field name was singular - i.e. byte_match_tuple
. I will have a look into deprecating byte_match_tuples
in favour of singular name in WAF resources too as we seemed to overlook this in the review of that resource code there.
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.
@radeksimko I agree with this. AWS CLI's api ByteMatchTuples
requires list but in this case we can write each tuple. Go SDK uses tuple.
Should I change into byte_match_tuple
only in WAF Regional? Or leave them in this time and change them later at the same time with WAF?
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.
uhm... I got the idea resource name should be singular during writing document.
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.
Should I change into byte_match_tuple only in WAF Regional?
Yes, please.
Don't worry about other (WAF) resources - we can rename/deprecate those later - that's a job for a separate PR.
Required: true, | ||
ForceNew: true, | ||
}, | ||
"ip_set_descriptors": &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.
Similar to the other schema - it would make more sense to call this ip_set_descriptor
IMO.
IPSetDescriptors = append(IPSetDescriptors, IPSet) | ||
} | ||
|
||
d.Set("ip_set_descriptors", IPSetDescriptors) |
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.
Would you mind adding error check here? We tend to avoid error checking for d.Set()
of all primitive fields merely to avoid cluttering the code, but we tend to do it for lists and sets as we were bitten by not doing it many times in the past.
) | ||
|
||
type WafRegionalRetryer struct { | ||
Connection *wafregional.WAFRegional |
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.
I thought my original WafRetryer
would be useful for you here too, but I never realized it's a different service with a different name 🤦♂️
Oh well, good decision to create a copy of it. 👍
return out, err | ||
} | ||
|
||
func newWafRegionalRetryer(conn *wafregional.WAFRegional) *WafRegionalRetryer { |
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.
I'm aware this will require some refactoring throughout all the resources, but I think it's important to only lock for a given region, so that if folks deploy regional WAF in say 2 regions, one region doesn't wait for lock of the other region as it doesn't have to.
The following arguments are supported: | ||
|
||
* `name` - (Required) The name or description of the ByteMatchSet. | ||
* `byte_match_tuples` - Settings for the ByteMatchSet, such as the bytes (typically a string that corresponds with ASCII characters) that you want AWS WAF to search for in web requests. |
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.
Would you mind documenting the nested fields of byte_match_tuples
here too? 🙂
The following arguments are supported: | ||
|
||
* `name` - (Required) The name or description of the IPSet. | ||
* `ip_set_descriptors` - (Required) The IP address type and IP address range (in CIDR notation) from which web requests originate. |
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.
Would you mind documenting the nested fields of ip_set_descriptors
here too? 🙂
FYI I will hold on reviewing the other WAF Regional PRs until we get this in as those will most likely require rebase and/or some cherry-picking of changes from this PR. |
d4a118e
to
38a0c16
Compare
38a0c16
to
3bd1683
Compare
Hi @yusukegoto #13766 was merged - would you mind looking over it 👀 and adapting the rest of the changes/fixes there to this PR too? Namely:
I hope I didn't miss anything 😃 |
@radeksimko Thanks for clearing remaining tasks! And sorry for slow response. |
3bd1683
to
2ba6e2b
Compare
f058f6b
to
465cf4a
Compare
@radeksimko |
@yusukegoto, I think you mean @radeksimko, not me. :) |
@reedloden sorry for disturbing 🙇 |
3d2c512
to
5a73a6f
Compare
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.
There was a few small last things which I decided to fix and push into your branch to speed things up, I hope you don't mind. 😅
Thank you for all the changes and patience. 👍
}) | ||
} | ||
|
||
func TestDiffWafRegionalIpSetDescriptors(t *testing.T) { |
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.
Nice, good to have this test 👍
@radeksimko Thank you very much for additional commits and care!! I'm trying to clean other WIP PRs:smile: |
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 have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further. |
This PR is from #13676.
test
exec