From 3901827b4043beda9c49f845c22c881422705a9b Mon Sep 17 00:00:00 2001 From: Paul Stack Date: Wed, 24 Aug 2016 21:28:41 +0100 Subject: [PATCH] provider/aws: Validate `aws_iam_policy_attachment` Name parameter to stop being empty (#8441) * provider/aws: Validate `aws_iam_policy_attachment` Name parameter to stop being empty Fixes #8368 ``` % make testacc TEST=./builtin/providers/aws TESTARGS='-run=TestAccAWSPolicyAttachment_' ==> Checking that code complies with gofmt requirements... /Users/stacko/Code/go/bin/stringer go generate $(go list ./... | grep -v /terraform/vendor/) 2016/08/24 11:46:01 Generated command/internal_plugin_list.go TF_ACC=1 go test ./builtin/providers/aws -v -run=TestAccAWSPolicyAttachment_ -timeout 120m === RUN TestAccAWSPolicyAttachment_basic --- PASS: TestAccAWSPolicyAttachment_basic (44.67s) === RUN TestAccAWSPolicyAttachment_paginatedEntities --- PASS: TestAccAWSPolicyAttachment_paginatedEntities (161.68s) PASS ok github.com/hashicorp/terraform/builtin/providers/aws 206.379s ``` * Update resource_aws_iam_policy_attachment.go --- .../providers/aws/resource_aws_iam_policy_attachment.go | 7 +++++++ .../providers/aws/r/iam_policy_attachment.html.markdown | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/builtin/providers/aws/resource_aws_iam_policy_attachment.go b/builtin/providers/aws/resource_aws_iam_policy_attachment.go index cf639b98c..adbd81b20 100644 --- a/builtin/providers/aws/resource_aws_iam_policy_attachment.go +++ b/builtin/providers/aws/resource_aws_iam_policy_attachment.go @@ -25,6 +25,13 @@ func resourceAwsIamPolicyAttachment() *schema.Resource { Type: schema.TypeString, Required: true, ForceNew: true, + ValidateFunc: func(v interface{}, k string) (ws []string, errors []error) { + if v.(string) == "" { + errors = append(errors, fmt.Errorf( + "%q cannot be an empty string", k)) + } + return + }, }, "users": &schema.Schema{ Type: schema.TypeSet, diff --git a/website/source/docs/providers/aws/r/iam_policy_attachment.html.markdown b/website/source/docs/providers/aws/r/iam_policy_attachment.html.markdown index a34fe242a..791311226 100644 --- a/website/source/docs/providers/aws/r/iam_policy_attachment.html.markdown +++ b/website/source/docs/providers/aws/r/iam_policy_attachment.html.markdown @@ -42,7 +42,7 @@ resource "aws_iam_policy_attachment" "test-attach" { The following arguments are supported: -* `name` (Required) - The name of the policy. +* `name` (Required) - The name of the policy. This cannot be an empty string. * `users` (Optional) - The user(s) the policy should be applied to * `roles` (Optional) - The role(s) the policy should be applied to * `groups` (Optional) - The group(s) the policy should be applied to