provider/aws: Reworked validateArn function to handle empty values (#10833)
This commit is contained in:
parent
bdad7c2784
commit
5dbc66012e
|
@ -36,6 +36,7 @@ func resourceAwsAmiCopy() *schema.Resource {
|
||||||
Optional: true,
|
Optional: true,
|
||||||
Computed: true,
|
Computed: true,
|
||||||
ForceNew: true,
|
ForceNew: true,
|
||||||
|
ValidateFunc: validateArn,
|
||||||
}
|
}
|
||||||
|
|
||||||
return &schema.Resource{
|
return &schema.Resource{
|
||||||
|
|
|
@ -292,6 +292,10 @@ func validateAwsAccountId(v interface{}, k string) (ws []string, errors []error)
|
||||||
func validateArn(v interface{}, k string) (ws []string, errors []error) {
|
func validateArn(v interface{}, k string) (ws []string, errors []error) {
|
||||||
value := v.(string)
|
value := v.(string)
|
||||||
|
|
||||||
|
if value == "" {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// http://docs.aws.amazon.com/lambda/latest/dg/API_AddPermission.html
|
// http://docs.aws.amazon.com/lambda/latest/dg/API_AddPermission.html
|
||||||
pattern := `^arn:aws:([a-zA-Z0-9\-])+:([a-z]{2}-[a-z]+-\d{1})?:(\d{12})?:(.*)$`
|
pattern := `^arn:aws:([a-zA-Z0-9\-])+:([a-z]{2}-[a-z]+-\d{1})?:(\d{12})?:(.*)$`
|
||||||
if !regexp.MustCompile(pattern).MatchString(value) {
|
if !regexp.MustCompile(pattern).MatchString(value) {
|
||||||
|
|
|
@ -189,6 +189,12 @@ func TestValidateAwsAccountId(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestValidateArn(t *testing.T) {
|
func TestValidateArn(t *testing.T) {
|
||||||
|
v := ""
|
||||||
|
_, errors := validateArn(v, "arn")
|
||||||
|
if len(errors) != 0 {
|
||||||
|
t.Fatalf("%q should not be validated as an ARN: %q", v, errors)
|
||||||
|
}
|
||||||
|
|
||||||
validNames := []string{
|
validNames := []string{
|
||||||
"arn:aws:elasticbeanstalk:us-east-1:123456789012:environment/My App/MyEnvironment", // Beanstalk
|
"arn:aws:elasticbeanstalk:us-east-1:123456789012:environment/My App/MyEnvironment", // Beanstalk
|
||||||
"arn:aws:iam::123456789012:user/David", // IAM User
|
"arn:aws:iam::123456789012:user/David", // IAM User
|
||||||
|
|
Loading…
Reference in New Issue