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_wafregional_rule #3756

Merged
merged 9 commits into from
Mar 18, 2018

Conversation

pvanbuijtene
Copy link
Contributor

Trying to help a bit to finish the WAF Regional PRs, this is the result of the split up of #3199

Related PRs: #1045 hashicorp/terraform#13710

Thanks to the contributors: @yusukegoto @DennyLoko @BSick7

@ghost ghost added the size/XL Managed by automation to categorize the size of a PR. label Mar 12, 2018
@radeksimko radeksimko added new-resource Introduces a new resource. service/waf Issues and PRs that pertain to the waf service. labels Mar 13, 2018
Required: true,
ForceNew: true,
},
"predicates": &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.

Due to the way this may (and likely is going to be) expressed in HCL:

predicates {
  negated = true
  data_id = "..."
}
predicates {
  data_id = "..."
}

we tend to prefer singular names for TypeSet/TypeList fields with non-primitive nested types. i.e. predicate in this case. Do you mind changing it here in the schema and in the CRUD & docs?

"%q must be one of IPMatch | ByteMatch | SqlInjectionMatch | SizeConstraint | XssMatch", k))
}
return
},
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 have a handy validation helper for this:

ValidateFunc: validation.StringInSlice([]string{
	"IPMatch",
	"ByteMatch",
	"SqlInjectionMatch",
	"SizeConstraint",
	"XssMatch",
}, false),

}
return
},
},
Copy link
Member

Choose a reason for hiding this comment

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

Nipick: We have a validation helper for this:

ValidateFunc: validation.StringLenBetween(1, 128),


resp, err := conn.GetRule(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 to simplify the code here?

if isAWSErr(err, wafregional.ErrCodeWAFNonexistentItemException, "") {

predicates = append(predicates, predicate)
}

d.Set("predicates", predicates)
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 tend to decouple logic like this (anything converting SDK structures to schema-friendly structures and vice-versa) to functions which are usually called expanders (schema -> SDK) or flatteners (SDK -> schema).
This may then simplify the code above to

d.Set("predicates", flattenWafPredicates(resp.Rule.Predicates))

},
"metric_name": &schema.Schema{
Type: schema.TypeString,
Required: true,

This comment was marked as resolved.

This comment was marked as resolved.

Schema: map[string]*schema.Schema{
"name": &schema.Schema{
Type: schema.TypeString,
Required: true,

This comment was marked as resolved.

This comment was marked as resolved.

},
"predicates": &schema.Schema{
Type: schema.TypeSet,
Optional: true,

This comment was marked as resolved.

This comment was marked as resolved.

},
"data_id": &schema.Schema{
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.

It seems this field is actually required per docs:
https://docs.aws.amazon.com/waf/latest/APIReference/API_regional_Rule.html 🤔
Do you mind double checking it and eventually reflecting it here and in the CRUD?

}

resource "aws_wafregional_rule" "wafrule" {
depends_on = ["aws_wafregional_ipset.ipset"]
Copy link
Member

Choose a reason for hiding this comment

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

This line is redundant as the relationship is already defined by the reference below (${aws_wafregional_ipset.ipset.id}). Do you mind removing it?

@radeksimko radeksimko added the waiting-response Maintainers are waiting on response from community or contributor. label Mar 13, 2018
@radeksimko radeksimko added this to the v1.12.0 milestone Mar 15, 2018
@radeksimko
Copy link
Member

@pvanbuijtene let me know if you need any help finishing this. I'd like to get it into 1.12.0 (tentatively scheduled for the end of next week) and this particular resource has been PR'd a couple of times, so I'm willing to take it to the finish line myself, if necessary 😉

@ghost ghost added the size/XL Managed by automation to categorize the size of a PR. label Mar 15, 2018
@ghost ghost added the size/XL Managed by automation to categorize the size of a PR. label Mar 15, 2018
@pvanbuijtene
Copy link
Contributor Author

@radeksimko I will finish this one first since the tests of #3754 depend on it.

So most work for this PR, #3754 and #3755 I can probably do in the weekend, but finishing it depends on when this PR can be merged which will be Monday or later guess?

@radeksimko
Copy link
Member

@pvanbuijtene The plan makes sense to me. I'll do my best to review any WAF PR that you tell me is ready for review. 😉 Just feel free to ping me the same way you just did.

@ghost ghost added the size/XL Managed by automation to categorize the size of a PR. label Mar 17, 2018
@pvanbuijtene
Copy link
Contributor Author

@radeksimko this one is ready :) ... hope I didn't forget anything.

Some questions arose while being busy with this:
I guess there is an internal build which runs the acceptance tests?
What are the rules/guidelines regarding the usage of funcs from different resources?

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

Thanks @pvanbuijtene
I just reformatted imports in one file and removed a few lines of redundant code related to error checks. I hope these changes make sense. Let me know if you need any further explanation.

I guess there is an internal build which runs the acceptance tests?

We run acceptance tests nightly on our side, but anyone can run them locally e.g.

AWS_PROFILE=... make testacc TEST=./aws TESTARGS='-run=TestAccAWSWafRegionalRule_'

What are the rules/guidelines regarding the usage of funcs from different resources?

We don't have any particular rules, but WAF resources in particular could use some refactoring in that sense. We can address that in a separate PR, eventually.

@radeksimko radeksimko merged commit cecf1d8 into hashicorp:master Mar 18, 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.

5 participants