Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

r/iam_role - add plan time validations #19532

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/19532.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/aws_iam_role: Add plan time validation for `path`, `permissions_boundary`, `managed_policy_arns`.
```
17 changes: 10 additions & 7 deletions aws/resource_aws_iam_role.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,17 @@ func resourceAwsIamRole() *schema.Resource {
},

"path": {
Type: schema.TypeString,
Optional: true,
Default: "/",
ForceNew: true,
Type: schema.TypeString,
Optional: true,
Default: "/",
ForceNew: true,
ValidateFunc: validation.StringLenBetween(1, 512),
},

"permissions_boundary": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.StringLenBetween(0, 2048),
ValidateFunc: validateArn,
},

"description": {
Expand Down Expand Up @@ -141,8 +142,10 @@ func resourceAwsIamRole() *schema.Resource {
Type: schema.TypeSet,
Optional: true,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
Set: schema.HashString,
Elem: &schema.Schema{
Type: schema.TypeString,
ValidateFunc: validateArn,
},
},
},

Expand Down
2 changes: 1 addition & 1 deletion aws/resource_aws_iam_role_policy_attachment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func TestAccAWSRolePolicyAttachment_disappears_Role(t *testing.T) {
testAccCheckAWSRolePolicyAttachmentExists(resourceName, 1, &attachedRolePolicies),
// DeleteConflict: Cannot delete entity, must detach all policies first.
testAccCheckAWSIAMRolePolicyAttachmentDisappears(resourceName),
testAccCheckAWSRoleDisappears(&role),
testAccCheckResourceDisappears(testAccProvider, resourceAwsIamRole(), iamRoleResourceName),
),
ExpectNonEmptyPlan: true,
},
Expand Down
19 changes: 1 addition & 18 deletions aws/resource_aws_iam_role_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ func TestAccAWSIAMRole_disappears(t *testing.T) {
Config: testAccAWSIAMRoleConfig(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSRoleExists(resourceName, &role),
testAccCheckAWSRoleDisappears(&role),
testAccCheckResourceDisappears(testAccProvider, resourceAwsIamRole(), resourceName),
),
ExpectNonEmptyPlan: true,
},
Expand Down Expand Up @@ -953,23 +953,6 @@ func testAccCheckAWSRoleExists(n string, res *iam.GetRoleOutput) resource.TestCh
}
}

func testAccCheckAWSRoleDisappears(getRoleOutput *iam.GetRoleOutput) resource.TestCheckFunc {
return func(s *terraform.State) error {
iamconn := testAccProvider.Meta().(*AWSClient).iamconn

roleName := aws.StringValue(getRoleOutput.Role.RoleName)

_, err := iamconn.DeleteRole(&iam.DeleteRoleInput{
RoleName: aws.String(roleName),
})
if err != nil {
return fmt.Errorf("error deleting role %q: %s", roleName, err)
}

return nil
}
}

func testAccCheckAWSRoleGeneratedNamePrefix(resource, prefix string) resource.TestCheckFunc {
return func(s *terraform.State) error {
r, ok := s.RootModule().Resources[resource]
Expand Down