provider/aws: Add validation for aws_iam_role_policy.name

This commit is contained in:
Radek Simko 2015-06-29 16:16:48 +01:00
parent da1cac623d
commit fed64b4fbd
1 changed files with 14 additions and 0 deletions

View File

@ -3,6 +3,7 @@ package aws
import ( import (
"fmt" "fmt"
"net/url" "net/url"
"regexp"
"strings" "strings"
"github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws"
@ -30,6 +31,19 @@ func resourceAwsIamRolePolicy() *schema.Resource {
Type: schema.TypeString, Type: schema.TypeString,
Required: true, Required: true,
ForceNew: true, ForceNew: true,
ValidateFunc: func(v interface{}, k string) (ws []string, errors []error) {
// https://github.com/boto/botocore/blob/2485f5c/botocore/data/iam/2010-05-08/service-2.json#L8291-L8296
value := v.(string)
if len(value) > 128 {
errors = append(errors, fmt.Errorf(
"%q cannot be longer than 128 characters", k))
}
if !regexp.MustCompile("^[\\w+=,.@-]+$").MatchString(value) {
errors = append(errors, fmt.Errorf(
"%q must match [\\w+=,.@-]", k))
}
return
},
}, },
"role": &schema.Schema{ "role": &schema.Schema{
Type: schema.TypeString, Type: schema.TypeString,