-
Notifications
You must be signed in to change notification settings - Fork 9.2k
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
Enhancement/cloudwatch event target adding validation #15669
Conversation
There was a problem hiding this 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/validators.go
Outdated
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 | ||
} | ||
} |
There was a problem hiding this comment.
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
aws/validators.go
Outdated
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 | ||
} | ||
} |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
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.
|
I'm not seeing the error in |
There was a problem hiding this 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)
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! |
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! |
Community Note
Relates #10912
Closes #15653
Release note for CHANGELOG:
Output from acceptance testing:
@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.