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

New Resource: aws_waf_geo_match_set #3275

Merged
merged 1 commit into from
Mar 14, 2018
Merged

New Resource: aws_waf_geo_match_set #3275

merged 1 commit into from
Mar 14, 2018

Conversation

mikesouza
Copy link
Contributor

@mikesouza mikesouza commented Feb 7, 2018

I added a aws_waf_geo_match_set resource which supports the AWS WAF GeoMatchSet feature added back in October 2017.

Per the contributing guidelines, I followed the conventions used by the existing WAF resources/ match sets, included and passed acceptance tests, updated the documentation, and kept the LOC to a minimum.

I also added an acceptance test to the existing aws_waf_rule resource to verify that it works with the new aws_waf_geo_match_set resource.

This was relatively straightforward to implement, as the behavior of the new resource is identical to the existing WAF match set resources, with its main difference being a simpler schema (i.e. compared to aws_waf_xss_match_set).

Please let me know if you have any questions, concerns, or would like me to make any changes, thanks!

Related

@ghost ghost added the size/XL Managed by automation to categorize the size of a PR. label Feb 7, 2018
@mikesouza mikesouza changed the title Add support for AWS WAF GeoMatchSet. New Resource: aws_waf_geo_match_set Feb 7, 2018
@bflad bflad added new-resource Introduces a new resource. service/waf Issues and PRs that pertain to the waf service. labels Feb 7, 2018
Copy link
Member

@radeksimko radeksimko left a comment

Choose a reason for hiding this comment

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

Hi @mikesouza
thanks for the PR.

This is looking pretty good, especially as it's your first contribution 😃

I left you some comments to address + I think the branch will need rebasing & resolving conflicts. Once that is done I'm happy to merge this.


for k, v := range rs.Primary.Attributes {
fmt.Println(k)
fmt.Println(v)
Copy link
Member

Choose a reason for hiding this comment

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

👆 Do you plan to finish this? I'm not sure what was supposed to be the purpose of this function - maybe it just needs removing?


func testAccCheckAWSWafGeoMatchSetDestroy(s *terraform.State) error {
for _, rs := range s.RootModule().Resources {
if rs.Type != "aws_waf_byte_match_set" {
Copy link
Member

Choose a reason for hiding this comment

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

Typo - I assume this should be aws_waf_geo_match_set

@@ -54,7 +54,7 @@ The following arguments are supported:
For example, if an IPSet includes the IP address `192.0.2.44`, AWS WAF will allow or block requests based on that IP address.
If set to `true`, AWS WAF will allow, block, or count requests based on all IP addresses _except_ `192.0.2.44`.
* `data_id` - (Required) A unique identifier for a predicate in the rule, such as Byte Match Set ID or IPSet ID.
* `type` - (Required) The type of predicate in a rule, such as `ByteMatchSet` or `IPSet`
* `type` - (Required) The type of predicate in a rule. Must be one of `IPMatch`, `ByteMatch`, `SqlInjectionMatch`, `SizeConstraint`, `XssMatch`, or `GeoMatch`.
Copy link
Member

Choose a reason for hiding this comment

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

Nitpick: We don't usually try to put extensive list of all valid values in our documentation, but instead link to official docs. This is to avoid a constant uphill battle of being out of date as Amazon releases new stuff and changes these things.


// Return nil if the GeoMatchSet is already destroyed
if awsErr, ok := err.(awserr.Error); ok {
if awsErr.Code() == "WAFNonexistentItemException" {
Copy link
Member

Choose a reason for hiding this comment

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

Do you mind using a helper function here and simplify the code that way a bit? 😉

if isAWSErr(err, "WAFNonexistentItemException", "") {


resp, err := conn.GetGeoMatchSet(params)
if err != nil {
if awsErr, ok := err.(awserr.Error); ok && awsErr.Code() == "WAFNonexistentItemException" {
Copy link
Member

Choose a reason for hiding this comment

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

Do you mind using a helper function here and simplify the code that way a bit? 😉

if isAWSErr(err, "WAFNonexistentItemException", "") {

Schema: map[string]*schema.Schema{
"type": {
Type: schema.TypeString,
Optional: true,
Copy link
Member

Choose a reason for hiding this comment

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

This field seems to be required per docs, do you mind reflecting it here?

Required: true,
ForceNew: true,
},
"geo_match_constraints": &schema.Schema{
Copy link
Member

Choose a reason for hiding this comment

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

As discussed in all recent WAF PRs we tend to use singular names for Sets/Lists which have nested fields of non-primitive data types, like here. This is because we expect them to be used in HCL like this:

geo_match_constraint {
  type = "Country"
  value = "US"
}
geo_match_constraint {
  type = "Country"
  value = "CA"
}

as opposed to lists/sets with primitive data types, like

countries = ["CA", "US", "CN"]

Do you mind changing it to geo_match_constraint and reflecting it in CRUD & docs too?

@radeksimko radeksimko added the waiting-response Maintainers are waiting on response from community or contributor. label Mar 14, 2018
@ghost ghost added the size/XL Managed by automation to categorize the size of a PR. label Mar 14, 2018
@mikesouza
Copy link
Contributor Author

mikesouza commented Mar 14, 2018

@radeksimko Thanks for reviewing! I believe I've addressed all of your comments, and rebased and merged.

Unfortunately, I force-pushed the changes and so I apologize if this had caused any inconvenience or issues with reviewing/ merging. I've learned my lesson.

@radeksimko radeksimko removed the waiting-response Maintainers are waiting on response from community or contributor. label Mar 14, 2018
Copy link
Member

@radeksimko radeksimko left a comment

Choose a reason for hiding this comment

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

LGTM, thanks 🚀

@radeksimko radeksimko merged commit 0bda6bf into hashicorp:master Mar 14, 2018
@bflad bflad added this to the v1.12.0 milestone Mar 23, 2018
@bflad
Copy link
Contributor

bflad commented Mar 23, 2018

This has been released in version 1.12.0 of the AWS provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

@ghost
Copy link

ghost commented Apr 7, 2020

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!

@ghost ghost locked and limited conversation to collaborators Apr 7, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
new-resource Introduces a new resource. service/waf Issues and PRs that pertain to the waf service. size/XL Managed by automation to categorize the size of a PR.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Documentation resource aws_waf_rule is wrong No Geo match Conditions on AWS WAF
3 participants