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

Issue 16973 - allow for ARNs and partner event bus names #18383

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion aws/validators.go
Original file line number Diff line number Diff line change
Expand Up @@ -2393,15 +2393,18 @@ func validateRoute53ResolverName(v interface{}, k string) (ws []string, errors [
return
}

//custom event bus names are still subject to this validation
var validateCloudWatchEventCustomEventBusName = validation.All(
validation.StringLenBetween(1, 256),
validation.StringMatch(regexp.MustCompile(`^[a-zA-Z0-9._\-]+$`), ""),
validation.StringDoesNotMatch(regexp.MustCompile(`^default$`), "cannot be 'default'"),
)

//partner names or references to the bus name can be ARNs or include slashes in the name
//see https://docs.aws.amazon.com/eventbridge/latest/APIReference/API_PutRule.html#API_PutRule_RequestSyntax
var validateCloudWatchEventBusName = validation.All(
validation.StringLenBetween(1, 256),
validation.StringMatch(regexp.MustCompile(`^[a-zA-Z0-9._\-/]+$`), ""),
validation.StringMatch(regexp.MustCompile(`^(arn:aws[\w-]*:events:[a-z]{2}-[a-z]+-[\w-]+:[0-9]{12}:event-bus\/)?[/\.\-_A-Za-z0-9]+$`), ""),
)

var validateCloudWatchEventArchiveName = validation.All(
Expand Down
47 changes: 47 additions & 0 deletions aws/validators_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3219,6 +3219,53 @@ func TestCloudWatchEventCustomEventBusName(t *testing.T) {
}
}

func TestCloudWatchEventBusName(t *testing.T) {
cases := []struct {
Value string
IsValid bool
}{
{
Value: "",
IsValid: false,
},
{
Value: acctest.RandStringFromCharSet(256, acctest.CharSetAlpha),
IsValid: true,
},
{
Value: acctest.RandStringFromCharSet(257, acctest.CharSetAlpha),
IsValid: false,
},
{
Value: "aws.partner/test/test",
IsValid: true,
},
{
//this seems like it would be wrong, but AWS documentation states this is allowed for partner busses
// see - https://docs.aws.amazon.com/eventbridge/latest/APIReference/API_PutRule.html#API_PutRule_RequestSyntax
Value: "/test0._1-",
IsValid: true,
},
{
Value: "test0._1-",
IsValid: true,
},
{
Value: "arn:aws:events:us-east-1:123456789012:event-bus/something-custom/subpath", // lintignore:AWSAT003,AWSAT005
IsValid: true,
},
}
for _, tc := range cases {
_, errors := validateCloudWatchEventBusName(tc.Value, "aws_cloudwatch_event_bus")
isValid := len(errors) == 0
if tc.IsValid && !isValid {
t.Errorf("expected %q to return valid, but did not", tc.Value)
} else if !tc.IsValid && isValid {
t.Errorf("expected %q to not return valid, but did", tc.Value)
}
}
}

func TestValidateServiceDiscoveryNamespaceName(t *testing.T) {
validNames := []string{
"ValidName",
Expand Down