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

Allow hyphens and underscores in metric_name in wafregional_* resourc… #12089

Conversation

Y-Tian
Copy link

@Y-Tian Y-Tian commented Feb 19, 2020

…es fix #12080

Community Note

  • Please vote on this pull request by adding a 👍 reaction to the original pull request comment to help the community and maintainers prioritize this request
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for pull request followers and do not help prioritize the request

Relates #12080

Release note for CHANGELOG:


Output from acceptance testing:

$ make testacc TESTARGS='-run=TestAccXXX'

...

I am unable to run the acceptance tests, due to finances.

@Y-Tian Y-Tian requested a review from a team February 19, 2020 18:18
@ghost ghost added needs-triage Waiting for first response or review from a maintainer. size/XS Managed by automation to categorize the size of a PR. service/waf Issues and PRs that pertain to the waf service. labels Feb 19, 2020
@Y-Tian Y-Tian changed the title allow hyphens and underscores in metric_name in wafregional_* resourc… Allow hyphens and underscores in metric_name in wafregional_* resourc… Feb 19, 2020
@ewbankkit
Copy link
Contributor

@Y-Tian Thanks for diving into this.
If I run an acceptance test and set the metric_name attribute to a value with an underscore then the underlying AWS API returns an exception:

% make testacc TEST=./aws TESTARGS='-run=TestAccAWSWafRegionalRateBasedRule_basic'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws -v -count 1 -parallel 20 -run=TestAccAWSWafRegionalRateBasedRule_basic -timeout 120m
=== RUN   TestAccAWSWafRegionalRateBasedRule_basic
=== PAUSE TestAccAWSWafRegionalRateBasedRule_basic
=== CONT  TestAccAWSWafRegionalRateBasedRule_basic
--- FAIL: TestAccAWSWafRegionalRateBasedRule_basic (20.92s)
    testing.go:654: Step 0 error: errors during apply:
        
        Error: Error creating WAF Regional Rate Based Rule (): WAFDisallowedNameException: The specified name is not permitted.
        
          on /var/folders/cs/yqdfp44s6hz9pmy2_g8qpmvm0000gq/T/tf-test502958926/main.tf line 11:
          (source code not available)
        
        
FAIL
FAIL	github.com/terraform-providers/terraform-provider-aws/aws	22.128s
FAIL
make: *** [testacc] Error 1

See the discussion in #12080 for details.

What would be useful would be to update the validateWafMetricName function to check all the constraints on the metric_name attribute:

The name can contain only alphanumeric characters (A-Z, a-z, 0-9), with maximum length 128 and minimum length one. It can't contain whitespace or metric names reserved for AWS WAF, including "All" and "Default_Action."

and to use it for the aws_wafregional_rule and aws_wafregional_web_acl resources.
You could use the approach suggested in #8424 and do something like

var validateWafMetricName = validation.All(
	validation.StringLenBetween(1, 128),
	validation.StringMatch(regexp.MustCompile(`^[0-9A-Za-z]+$`), "must contain only alphanumeric characters"),
	StringNotInSlice([]string{"ALL", "Default_Action"}, false), // To implement :)
)

This can be unit tested via make test.

@bflad
Copy link
Contributor

bflad commented Apr 23, 2020

Hi @Y-Tian 👋 Thank you for submitting this. Since we haven't heard back from you about the feedback provided above, we are going to opt to close this for now. If you wish to implement the suggestions, please submit a new pull request and we'll be happy to re-review. 👍

@bflad bflad closed this Apr 23, 2020
@ghost
Copy link

ghost commented May 23, 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 May 23, 2020
@breathingdust breathingdust removed the needs-triage Waiting for first response or review from a maintainer. label Sep 17, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
service/waf Issues and PRs that pertain to the waf service. size/XS Managed by automation to categorize the size of a PR.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

WAF aws_waf_rule resource does not allow underscores in metric_name
4 participants