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

Enhancement/cloudwatch event target adding validation #15669

Merged
merged 4 commits into from
Oct 20, 2020
Merged

Enhancement/cloudwatch event target adding validation #15669

merged 4 commits into from
Oct 20, 2020

Conversation

philnichol
Copy link
Contributor

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 #10912
Closes #15653

Release note for CHANGELOG:

NONE

Output from acceptance testing:

$  TF_ACC=1 go test ./aws -v -count 1 -parallel 4 -run=TestAccAWSCloudWatchEventTarget_input_transformer -timeout 60m
=== RUN   TestAccAWSCloudWatchEventTarget_input_transformer
=== PAUSE TestAccAWSCloudWatchEventTarget_input_transformer
=== CONT  TestAccAWSCloudWatchEventTarget_input_transformer
--- PASS: TestAccAWSCloudWatchEventTarget_input_transformer (39.24s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	41.304s

@gdavison hope you don't mind I went ahead and submitted this!

Added validation for max number of input_paths (10) and validation that they don't start with "AWS".
Updated Acc test to include 10 input_paths.

@philnichol philnichol requested a review from a team October 15, 2020 20:03
@ghost ghost added size/M Managed by automation to categorize the size of a PR. documentation Introduces or discusses updates to documentation. service/cloudwatchevents tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure. labels Oct 15, 2020
@github-actions github-actions bot added the needs-triage Waiting for first response or review from a maintainer. label Oct 15, 2020
@gdavison gdavison removed the needs-triage Waiting for first response or review from a maintainer. label Oct 15, 2020
@gdavison gdavison self-assigned this Oct 15, 2020
Copy link
Contributor

@gdavison gdavison 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, @philnichol, it's looking great! I've got one additional test I'd like to see and a couple nitpicks.
The new validators would be great to also propose for the Terraform Plugin SDK.

aws/resource_aws_cloudwatch_event_target.go Outdated Show resolved Hide resolved
Comment on lines 2470 to 2484
func MapLenBetween(min, max int) schema.SchemaValidateFunc {
return func(i interface{}, k string) (warnings []string, errors []error) {
m, ok := i.(map[string]interface{})
if !ok {
errors = append(errors, fmt.Errorf("expected type of %s to be map", k))
return warnings, errors
}

if len(m) < min || len(m) > max {
errors = append(errors, fmt.Errorf("expected length of %s to be in the range (%d - %d), got %d", k, min, max, len(m)))
}

return warnings, errors
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

In this case, I would just check the maximum size, since there isn't really a lower limit. You could call it MapMaxLen() or match it with the MaxItems field for TypeList and TypeSet and call it MapMaxItems().

This would be a great addition to the Terraform Plugin SDK

Comment on lines 2486 to 2502
func MapKeyNotMatch(r *regexp.Regexp, message string) schema.SchemaValidateFunc {
return func(i interface{}, k string) (warnings []string, errors []error) {
m, ok := i.(map[string]interface{})
if !ok {
errors = append(errors, fmt.Errorf("expected type of %s to be map", k))
return warnings, errors
}

for key := range m {
if ok := r.MatchString(key); ok {
errors = append(errors, fmt.Errorf("%s: %s: %s", k, message, key))
}
}

return warnings, errors
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

A picky naming thing: many of the validation functions read a bit more smoothly, like StringDoesNotMatch(), StringDoesNotContainAny(), or StringIsNotWhiteSpace(). Maybe a name like MapKeyDoesNotMatch().

This would also be a great addition to the Terraform Plugin SDK

Copy link
Contributor Author

Choose a reason for hiding this comment

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

makes sense, have renamed to MapKeysDoNotMatch.
Will look into raising a proposal in the SDK plugin

aws/resource_aws_cloudwatch_event_target_test.go Outdated Show resolved Hide resolved
@philnichol
Copy link
Contributor Author

reran full ACC tests, the batch step appears to be failing before and after my changes so I assume it's unrelated? Happy to raise an issue if this is news.

$ TF_ACC=1 go test ./aws -v -count 1 -parallel 4 -run=TestAccAWSCloudWatchEventTarget_ -timeout 60m
=== RUN   TestAccAWSCloudWatchEventTarget_basic
=== PAUSE TestAccAWSCloudWatchEventTarget_basic
=== RUN   TestAccAWSCloudWatchEventTarget_missingTargetId
=== PAUSE TestAccAWSCloudWatchEventTarget_missingTargetId
=== RUN   TestAccAWSCloudWatchEventTarget_full
=== PAUSE TestAccAWSCloudWatchEventTarget_full
=== RUN   TestAccAWSCloudWatchEventTarget_ssmDocument
=== PAUSE TestAccAWSCloudWatchEventTarget_ssmDocument
=== RUN   TestAccAWSCloudWatchEventTarget_ecs
=== PAUSE TestAccAWSCloudWatchEventTarget_ecs
=== RUN   TestAccAWSCloudWatchEventTarget_ecsWithBlankTaskCount
=== PAUSE TestAccAWSCloudWatchEventTarget_ecsWithBlankTaskCount
=== RUN   TestAccAWSCloudWatchEventTarget_batch
=== PAUSE TestAccAWSCloudWatchEventTarget_batch
=== RUN   TestAccAWSCloudWatchEventTarget_kinesis
=== PAUSE TestAccAWSCloudWatchEventTarget_kinesis
=== RUN   TestAccAWSCloudWatchEventTarget_sqs
=== PAUSE TestAccAWSCloudWatchEventTarget_sqs
=== RUN   TestAccAWSCloudWatchEventTarget_input_transformer
=== PAUSE TestAccAWSCloudWatchEventTarget_input_transformer
=== CONT  TestAccAWSCloudWatchEventTarget_basic
=== CONT  TestAccAWSCloudWatchEventTarget_batch
=== CONT  TestAccAWSCloudWatchEventTarget_input_transformer
=== CONT  TestAccAWSCloudWatchEventTarget_sqs
--- PASS: TestAccAWSCloudWatchEventTarget_sqs (43.91s)
=== CONT  TestAccAWSCloudWatchEventTarget_kinesis
--- PASS: TestAccAWSCloudWatchEventTarget_basic (57.80s)
=== CONT  TestAccAWSCloudWatchEventTarget_ssmDocument
=== CONT  TestAccAWSCloudWatchEventTarget_batch
    resource_aws_cloudwatch_event_target_test.go:283: After applying this test step, the plan was not empty.
        stdout:


        An execution plan has been generated and is shown below.
        Resource actions are indicated with the following symbols:
          ~ update in-place
        -/+ destroy and then create replacement

        Terraform will perform the following actions:

          # aws_batch_job_definition.batch_job_definition must be replaced
        -/+ resource "aws_batch_job_definition" "batch_job_definition" {
              ~ arn                  = "arn:aws:batch:eu-west-1:887702914428:job-definition/tf_batch_target-5829695721356721392:1" -> (known after apply)
              ~ container_properties = jsonencode(
                  ~ {
                        command              = [
                            "ls",
                            "-la",
                        ]
                        environment          = []
                        image                = "busybox"
                        memory               = 512
                        mountPoints          = []
                      - resourceRequirements = [] -> null
                      - secrets              = [] -> null
                        ulimits              = []
                        vcpus                = 1
                        volumes              = []
                    }
                )
              ~ id                   = "arn:aws:batch:eu-west-1:887702914428:job-definition/tf_batch_target-5829695721356721392:1" -> (known after apply)
                name                 = "tf_batch_target-5829695721356721392"
              ~ revision             = 1 -> (known after apply)
                type                 = "container"
            }

          # aws_cloudwatch_event_target.test will be updated in-place
          ~ resource "aws_cloudwatch_event_target" "test" {
                arn       = "arn:aws:batch:eu-west-1:887702914428:job-queue/tf_batch_target-5829695721356721392"
                id        = "tf_batch_target-5829695721356721392-terraform-20201017154859657400000005"
                role_arn  = "arn:aws:iam::887702914428:role/event_tf_batch_target-5829695721356721392"
                rule      = "tf_batch_target-5829695721356721392"
                target_id = "terraform-20201017154859657400000005"

              ~ batch_target {
                    array_size     = 0
                    job_attempts   = 0
                  ~ job_definition = "arn:aws:batch:eu-west-1:887702914428:job-definition/tf_batch_target-5829695721356721392:1" -> (known after apply)
                    job_name       = "tf_batch_target-5829695721356721392"
                }
            }

        Plan: 1 to add, 1 to change, 1 to destroy.
--- PASS: TestAccAWSCloudWatchEventTarget_input_transformer (67.75s)
=== CONT  TestAccAWSCloudWatchEventTarget_ecsWithBlankTaskCount
--- PASS: TestAccAWSCloudWatchEventTarget_ssmDocument (23.40s)
=== CONT  TestAccAWSCloudWatchEventTarget_ecs
--- PASS: TestAccAWSCloudWatchEventTarget_ecsWithBlankTaskCount (36.55s)
=== CONT  TestAccAWSCloudWatchEventTarget_full
--- PASS: TestAccAWSCloudWatchEventTarget_kinesis (64.48s)
=== CONT  TestAccAWSCloudWatchEventTarget_missingTargetId
--- PASS: TestAccAWSCloudWatchEventTarget_ecs (32.22s)
--- PASS: TestAccAWSCloudWatchEventTarget_missingTargetId (19.91s)
--- PASS: TestAccAWSCloudWatchEventTarget_full (57.76s)
--- FAIL: TestAccAWSCloudWatchEventTarget_batch (167.33s)
FAIL
FAIL	github.com/terraform-providers/terraform-provider-aws/aws	170.132s
FAIL

@philnichol philnichol requested a review from gdavison October 17, 2020 16:17
@gdavison
Copy link
Contributor

I'm not seeing the error in TestAccAWSCloudWatchEventTarget_batch on my end.

Copy link
Contributor

@gdavison gdavison left a comment

Choose a reason for hiding this comment

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

LGTM 🚀

--- PASS: TestAccAWSCloudWatchEventTarget_sqs (26.59s)
--- PASS: TestAccAWSCloudWatchEventTarget_missingTargetId (26.69s)
--- PASS: TestAccAWSCloudWatchEventTarget_ssmDocument (29.44s)
--- PASS: TestAccAWSCloudWatchEventTarget_ecs (36.17s)
--- PASS: TestAccAWSCloudWatchEventTarget_ecsWithBlankTaskCount (37.09s)
--- PASS: TestAccAWSCloudWatchEventTarget_basic (38.35s)
--- PASS: TestAccAWSCloudWatchEventTarget_input_transformer (47.98s)
--- PASS: TestAccAWSCloudWatchEventTarget_kinesis (64.50s)
--- PASS: TestAccAWSCloudWatchEventTarget_full (65.33s)
--- PASS: TestAccAWSCloudWatchEventTarget_batch (94.51s)

@gdavison gdavison added this to the v3.12.0 milestone Oct 19, 2020
@gdavison gdavison merged commit 6a66a25 into hashicorp:master Oct 20, 2020
@philnichol philnichol deleted the e-adding-validation-cw-event-target branch October 20, 2020 21:08
gdavison added a commit that referenced this pull request Oct 20, 2020
@ghost
Copy link

ghost commented Oct 22, 2020

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

For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template for triage. Thanks!

@ghost
Copy link

ghost commented Nov 20, 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 as resolved and limited conversation to collaborators Nov 20, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
documentation Introduces or discusses updates to documentation. size/M Managed by automation to categorize the size of a PR. tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add validator for aws_cloudwatch_event_target input_transformer.input_paths maximum size
2 participants