Skip to content

Commit

Permalink
add validations
Browse files Browse the repository at this point in the history
  • Loading branch information
DrFaust92 committed Sep 10, 2021
1 parent 13c394e commit 6196205
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 26 deletions.
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

0 comments on commit 6196205

Please sign in to comment.