Skip to content

Commit

Permalink
Merge pull request #5740 from mgarstecki/allow_empty_role_permissions…
Browse files Browse the repository at this point in the history
…_boundary

Allow empty permissions boundary field in AWS role.
  • Loading branch information
bflad authored Aug 31, 2018
2 parents 876ecaf + 179c3b7 commit a446de8
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
2 changes: 1 addition & 1 deletion aws/resource_aws_iam_role.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func resourceAwsIamRole() *schema.Resource {
"permissions_boundary": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.StringLenBetween(20, 2048),
ValidateFunc: validateMaxLength(2048),
},

"description": {
Expand Down
29 changes: 29 additions & 0 deletions aws/resource_aws_iam_role_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ func TestAccAWSIAMRole_PermissionsBoundary(t *testing.T) {
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSRoleExists(resourceName, &role),
resource.TestCheckResourceAttr(resourceName, "permissions_boundary", permissionsBoundary1),
testAccCheckAWSRolePermissionsBoundary(&role, permissionsBoundary1),
),
},
// Test update
Expand All @@ -250,6 +251,7 @@ func TestAccAWSIAMRole_PermissionsBoundary(t *testing.T) {
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSRoleExists(resourceName, &role),
resource.TestCheckResourceAttr(resourceName, "permissions_boundary", permissionsBoundary2),
testAccCheckAWSRolePermissionsBoundary(&role, permissionsBoundary2),
),
},
// Test import
Expand All @@ -265,6 +267,7 @@ func TestAccAWSIAMRole_PermissionsBoundary(t *testing.T) {
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSRoleExists(resourceName, &role),
resource.TestCheckResourceAttr(resourceName, "permissions_boundary", ""),
testAccCheckAWSRolePermissionsBoundary(&role, ""),
),
},
// Test addition
Expand All @@ -273,6 +276,16 @@ func TestAccAWSIAMRole_PermissionsBoundary(t *testing.T) {
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSRoleExists(resourceName, &role),
resource.TestCheckResourceAttr(resourceName, "permissions_boundary", permissionsBoundary1),
testAccCheckAWSRolePermissionsBoundary(&role, permissionsBoundary1),
),
},
// Test empty value
{
Config: testAccCheckIAMRoleConfig_PermissionsBoundary(rName, ""),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSRoleExists(resourceName, &role),
resource.TestCheckResourceAttr(resourceName, "permissions_boundary", ""),
testAccCheckAWSRolePermissionsBoundary(&role, ""),
),
},
},
Expand Down Expand Up @@ -399,6 +412,22 @@ func testAccAddAwsIAMRolePolicy(n string) resource.TestCheckFunc {
}
}

func testAccCheckAWSRolePermissionsBoundary(getRoleOutput *iam.GetRoleOutput, expectedPermissionsBoundaryArn string) resource.TestCheckFunc {
return func(s *terraform.State) error {
actualPermissionsBoundaryArn := ""

if getRoleOutput.Role.PermissionsBoundary != nil {
actualPermissionsBoundaryArn = *getRoleOutput.Role.PermissionsBoundary.PermissionsBoundaryArn
}

if actualPermissionsBoundaryArn != expectedPermissionsBoundaryArn {
return fmt.Errorf("PermissionsBoundary: '%q', expected '%q'.", actualPermissionsBoundaryArn, expectedPermissionsBoundaryArn)
}

return nil
}
}

func testAccCheckIAMRoleConfig_MaxSessionDuration(rName string, maxSessionDuration int) string {
return fmt.Sprintf(`
resource "aws_iam_role" "test" {
Expand Down

0 comments on commit a446de8

Please sign in to comment.