From fed64b4fbd9ed6fb754fef5bf86b348d0a13f4a8 Mon Sep 17 00:00:00 2001 From: Radek Simko Date: Mon, 29 Jun 2015 16:16:48 +0100 Subject: [PATCH] provider/aws: Add validation for aws_iam_role_policy.name --- .../providers/aws/resource_aws_iam_role_policy.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/builtin/providers/aws/resource_aws_iam_role_policy.go b/builtin/providers/aws/resource_aws_iam_role_policy.go index a219d7f24511..1424bb62194f 100644 --- a/builtin/providers/aws/resource_aws_iam_role_policy.go +++ b/builtin/providers/aws/resource_aws_iam_role_policy.go @@ -3,6 +3,7 @@ package aws import ( "fmt" "net/url" + "regexp" "strings" "github.com/aws/aws-sdk-go/aws" @@ -30,6 +31,19 @@ func resourceAwsIamRolePolicy() *schema.Resource { Type: schema.TypeString, Required: 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{ Type: schema.TypeString,