provider/aws: Reworked validateArn function to handle empty values (#10833)
This commit is contained in:
parent
bdad7c2784
commit
5dbc66012e
|
@ -32,10 +32,11 @@ func resourceAwsAmiCopy() *schema.Resource {
|
|||
}
|
||||
|
||||
resourceSchema["kms_key_id"] = &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
ForceNew: true,
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
ForceNew: true,
|
||||
ValidateFunc: validateArn,
|
||||
}
|
||||
|
||||
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) {
|
||||
value := v.(string)
|
||||
|
||||
if value == "" {
|
||||
return
|
||||
}
|
||||
|
||||
// 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})?:(.*)$`
|
||||
if !regexp.MustCompile(pattern).MatchString(value) {
|
||||
|
|
|
@ -189,6 +189,12 @@ func TestValidateAwsAccountId(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{
|
||||
"arn:aws:elasticbeanstalk:us-east-1:123456789012:environment/My App/MyEnvironment", // Beanstalk
|
||||
"arn:aws:iam::123456789012:user/David", // IAM User
|
||||
|
|
Loading…
Reference in New Issue