Skip to content

Commit

Permalink
Merge pull request #19703 from kromol/b-cloudwatch-event-target-input…
Browse files Browse the repository at this point in the history
…-paths-max-items

r/aws_cloudwatch_event_target - fix input transformer input paths validation
  • Loading branch information
anGie44 authored Jun 8, 2021
2 parents 90fe052 + 43192bb commit 575fc2f
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 26 deletions.
3 changes: 3 additions & 0 deletions .changelog/19703.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
resource/aws_cloudwatch_event_target: Increase the maximum allowed value for the `input_transformer` `input_paths` argument to 100
```
2 changes: 1 addition & 1 deletion aws/resource_aws_cloudwatch_event_target.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ func resourceAwsCloudWatchEventTarget() *schema.Resource {
Optional: true,
Elem: &schema.Schema{Type: schema.TypeString},
ValidateFunc: validation.All(
MapMaxItems(10),
MapMaxItems(100),
MapKeysDoNotMatch(regexp.MustCompile(`^AWS.*$`), "input_path must not start with \"AWS\""),
),
},
Expand Down
33 changes: 9 additions & 24 deletions aws/resource_aws_cloudwatch_event_target_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -573,31 +573,16 @@ func TestAccAWSCloudWatchEventTarget_input_transformer(t *testing.T) {
var v events.Target
rName := acctest.RandomWithPrefix("tf_input_transformer")

tooManyInputPaths := []string{
"account",
"count",
"eventFirstSeen",
"eventLastSeen",
"Finding_ID",
"Finding_Type",
"instanceId",
"port",
"region",
"severity",
"time",
tooManyInputPaths := make([]string, 101)
for i := range tooManyInputPaths {
tooManyInputPaths[i] = fmt.Sprintf("InvalidField_%d", i)
}
validInputPaths := []string{
"account",
"count",
"eventFirstSeen",
"eventLastSeen",
"Finding_ID",
"Finding_Type",
"instanceId",
"region",
"severity",
"time",

validInputPaths := make([]string, 100)
for i := range validInputPaths {
validInputPaths[i] = fmt.Sprintf("ValidField_%d", i)
}

var expectedInputTemplate strings.Builder
fmt.Fprintf(&expectedInputTemplate, `{
"detail-type": "Scheduled Event",
Expand Down Expand Up @@ -626,7 +611,7 @@ func TestAccAWSCloudWatchEventTarget_input_transformer(t *testing.T) {
testAccCheckCloudWatchEventTargetExists(resourceName, &v),
resource.TestCheckResourceAttr(resourceName, "input_transformer.#", "1"),
resource.TestCheckResourceAttr(resourceName, "input_transformer.0.input_paths.%", strconv.Itoa(len(validInputPaths))),
resource.TestCheckResourceAttr(resourceName, "input_transformer.0.input_paths.time", "$.time"),
resource.TestCheckResourceAttr(resourceName, "input_transformer.0.input_paths.ValidField_99", "$.ValidField_99"),
resource.TestCheckResourceAttr(resourceName, "input_transformer.0.input_template", expectedInputTemplate.String()),
),
},
Expand Down
2 changes: 1 addition & 1 deletion website/docs/r/cloudwatch_event_target.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ For more information, see [Task Networking](https://docs.aws.amazon.com/AmazonEC
`input_transformer` support the following:

* `input_paths` - (Optional) Key value pairs specified in the form of JSONPath (for example, time = $.time)
* You can have as many as 10 key-value pairs.
* You can have as many as 100 key-value pairs.
* You must use JSON dot notation, not bracket notation.
* The keys can't start with "AWS".

Expand Down

0 comments on commit 575fc2f

Please sign in to comment.