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_xss_match_set #1014

Merged
merged 2 commits into from
Mar 12, 2018

Conversation

DennyLoko
Copy link
Contributor

This PR is a port of the originally opened by @yusukegoto at hashicorp/terraform#13709.

@radeksimko radeksimko added the new-resource Introduces a new resource. label Jul 3, 2017
@DennyLoko DennyLoko force-pushed the aws_wafregional_xss_match_set branch from 5bbeb20 to f25ea30 Compare July 4, 2017 17:14
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.

Thanks for the PR, I left you some comments there in a very similar fashion to #1013

I will leave your other WAF regional PRs for now until these two are fixed, but I reckon the same issues will need addressing there too, once we get there.

Let me know if you have any questions.

Required: true,
ForceNew: true,
},
"xss_match_tuples": &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 we discussed in the other resource do you mind renaming this field to singular? i.e. xss_match_tuple?

resp, err := conn.GetXssMatchSet(params)
if err != nil {
if awsErr, ok := err.(awserr.Error); ok && awsErr.Code() == "WAFNonexistentItemException" {
log.Printf("[WARN] WAF IPSet (%s) not found, error code (404)", d.Id())
Copy link
Member

Choose a reason for hiding this comment

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

Typo here - this is XSS Match Set, not IPSet.

}

d.Set("name", resp.XssMatchSet.Name)

Copy link
Member

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 xss_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.


func resourceAwsWafRegionalXssMatchSetUpdate(d *schema.ResourceData, meta interface{}) error {
log.Printf("[INFO] Updating XssMatchSet: %s", d.Get("name").(string))
err := updateXssMatchSetResourceWR(d, meta, waf.ChangeActionInsert)
Copy link
Member

Choose a reason for hiding this comment

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

I think this isn't right, because during update we may be both inserting and deleting tuples, not just inserting. See 99e75ad for more context.

},
})
}

Copy link
Member

Choose a reason for hiding this comment

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

Because there has been a bug in the past affecting all WAF resources I'd like to see 2 more tests here, specifically with no tuples and another one changing tuples, see https://github.com/terraform-providers/terraform-provider-aws/blob/master/aws/resource_aws_waf_xss_match_set_test.go#L111-L197 for inspiration and 99e75ad for context (bugfix).


func testAccCheckAWSWafRegionalXssMatchSetDestroy(s *terraform.State) error {
for _, rs := range s.RootModule().Resources {
if rs.Type != "aws_wafregional_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 here 👀

The following arguments are supported:

* `name` - (Required) The name or description of the SizeConstraintSet.
* `xss_match_tuples` - The parts of web requests that you want to inspect for cross-site scripting attacks.
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 documenting all the nested fields here, too?

@radeksimko radeksimko added the waiting-response Maintainers are waiting on response from community or contributor. label Jul 18, 2017
@Ninir
Copy link
Contributor

Ninir commented Aug 30, 2017

Hi @DennyLoko

Do you think you would have time to finish this PR?
Please let us know if we can help on something :)

Thanks!

@radeksimko
Copy link
Member

FYI - As this PR has been stale for a couple of months I will take it over in coming week(s) unless you tell me not to.

@radeksimko radeksimko added the size/L Managed by automation to categorize the size of a PR. label Nov 15, 2017
@radeksimko radeksimko added the service/waf Issues and PRs that pertain to the waf service. label Jan 12, 2018
@radeksimko radeksimko changed the title Add support for aws_wafregional_xss_match_set New Resource: aws_wafregional_xss_match_set Jan 16, 2018
@radeksimko radeksimko added this to the v1.12.0 milestone Jan 16, 2018
@radeksimko radeksimko force-pushed the aws_wafregional_xss_match_set branch from f25ea30 to 60f3ff6 Compare March 8, 2018 12:46
@ghost ghost added size/XL Managed by automation to categorize the size of a PR. and removed size/L Managed by automation to categorize the size of a PR. labels Mar 8, 2018
@radeksimko radeksimko dismissed their stale review March 8, 2018 12:46

Implemented feedback

@radeksimko radeksimko removed the waiting-response Maintainers are waiting on response from community or contributor. label Mar 8, 2018
@radeksimko radeksimko force-pushed the aws_wafregional_xss_match_set branch from 60f3ff6 to 402d66d Compare March 8, 2018 12:49
@ghost ghost added the size/XL Managed by automation to categorize the size of a PR. label Mar 8, 2018
@radeksimko radeksimko force-pushed the aws_wafregional_xss_match_set branch from 402d66d to 4e0cc78 Compare March 8, 2018 12:49
@ghost ghost added the size/XL Managed by automation to categorize the size of a PR. label Mar 8, 2018
@radeksimko radeksimko requested a review from bflad March 8, 2018 12:50
@radeksimko
Copy link
Member

radeksimko commented Mar 8, 2018

I believe I addressed all things I saw myself as blockers, I think it's worth one more review from someone with a fresh eye though.

TF_ACC=1 go test ./aws -v -run=TestAccAWSWafRegionalXssMatchSet_ -timeout 120m
=== RUN   TestAccAWSWafRegionalXssMatchSet_basic
--- PASS: TestAccAWSWafRegionalXssMatchSet_basic (40.98s)
=== RUN   TestAccAWSWafRegionalXssMatchSet_changeNameForceNew
--- PASS: TestAccAWSWafRegionalXssMatchSet_changeNameForceNew (73.21s)
=== RUN   TestAccAWSWafRegionalXssMatchSet_disappears
--- PASS: TestAccAWSWafRegionalXssMatchSet_disappears (31.97s)
=== RUN   TestAccAWSWafRegionalXssMatchSet_changeTuples
--- PASS: TestAccAWSWafRegionalXssMatchSet_changeTuples (95.47s)
=== RUN   TestAccAWSWafRegionalXssMatchSet_noTuples
--- PASS: TestAccAWSWafRegionalXssMatchSet_noTuples (32.80s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	274.465s

Copy link
Contributor

@bflad bflad left a comment

Choose a reason for hiding this comment

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

A few minor nits, but it looks good!

5 tests passed (all tests)
=== RUN   TestAccAWSWafRegionalXssMatchSet_noTuples
--- PASS: TestAccAWSWafRegionalXssMatchSet_noTuples (11.10s)
=== RUN   TestAccAWSWafRegionalXssMatchSet_disappears
--- PASS: TestAccAWSWafRegionalXssMatchSet_disappears (13.78s)
=== RUN   TestAccAWSWafRegionalXssMatchSet_changeTuples
--- PASS: TestAccAWSWafRegionalXssMatchSet_changeTuples (18.37s)
=== RUN   TestAccAWSWafRegionalXssMatchSet_basic
--- PASS: TestAccAWSWafRegionalXssMatchSet_basic (25.62s)
=== RUN   TestAccAWSWafRegionalXssMatchSet_changeNameForceNew
--- PASS: TestAccAWSWafRegionalXssMatchSet_changeNameForceNew (28.88s)

})
}

func TestAccAWSWafRegionalXssMatchSet_noTuples(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Minor nitpick: Given the tuples attribute is optional, seems like we should swap this test's contents for the _basic one then name that one appropriately

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, I agree, but I'd prefer to do the cleanup across all WAF resources afterwards as the issue is not unique to this resource or PR 😉

#### `xss_match_tuple`

* `field_to_match` - (Required) Specifies where in a web request to look for cross-site scripting attacks.
* `text_transformation` - (Required) Which text transformation, if any, to perform on the web request before inspecting the request for cross-site scripting attacks.
Copy link
Contributor

Choose a reason for hiding this comment

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

Minor nitpick: we should probably point to the (rather complex) documentation here.

Copy link
Member

Choose a reason for hiding this comment

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

Agreed, but I'd prefer to do the cleanup across all WAF resources afterwards as the issue is not unique to this resource or PR 😉


The following arguments are supported:

* `name` - (Required) The name or description of the SizeConstraintSet.
Copy link
Contributor

Choose a reason for hiding this comment

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

Copypasta 🍝 : SizeConstraintSet

@radeksimko radeksimko force-pushed the aws_wafregional_xss_match_set branch from 4e0cc78 to c8c384d Compare March 12, 2018 13:46
@ghost ghost added the size/XL Managed by automation to categorize the size of a PR. label Mar 12, 2018
@radeksimko radeksimko merged commit 8f77c3c into hashicorp:master Mar 12, 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.

4 participants