Skip to content

Commit

Permalink
Merge pull request #148 from evan-cleary/fix-user-role
Browse files Browse the repository at this point in the history
fix: Fix user role creation and descriptions
  • Loading branch information
jbristowe authored Apr 1, 2021
2 parents db11f63 + a7980fa commit 7122201
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
24 changes: 24 additions & 0 deletions octopusdeploy/resource_user_role_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,36 @@ func TestAccUserRoleBasic(t *testing.T) {
})
}

func TestAccUserRolePermissions(t *testing.T) {
localName := acctest.RandStringFromCharSet(20, acctest.CharSetAlpha)
name := acctest.RandStringFromCharSet(16, acctest.CharSetAlpha)

resource.Test(t, resource.TestCase{
CheckDestroy: testAccUserRoleCheckDestroy,
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testUserRolePermissions(localName, name),
},
},
})
}

func testUserRoleMinimum(localName string, name string) string {
return fmt.Sprintf(`resource "octopusdeploy_user_role" "%s" {
name = "%s"
}`, localName, name)
}

func testUserRolePermissions(localName string, name string) string {
return fmt.Sprintf(`resource "octopusdeploy_user_role" "%s" {
name = "%s"
granted_space_permissions = ["AccountCreate"]
granted_system_permissions = ["SpaceView"]
}`, localName, name)
}

func testAccUserRoleCheckDestroy(s *terraform.State) error {
client := testAccProvider.Meta().(*octopusdeploy.Client)
for _, rs := range s.RootModule().Resources {
Expand Down
12 changes: 7 additions & 5 deletions octopusdeploy/schema_user_role.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,27 +21,27 @@ func expandUserRole(d *schema.ResourceData) *octopusdeploy.UserRole {
}

if v, ok := d.GetOk("granted_space_permissions"); ok {
userRole.GrantedSpacePermissions = v.([]string)
userRole.GrantedSpacePermissions = getSliceFromTerraformTypeList(v)
}

if v, ok := d.GetOk("granted_system_permissions"); ok {
userRole.GrantedSystemPermissions = v.([]string)
userRole.GrantedSystemPermissions = getSliceFromTerraformTypeList(v)
}

if v, ok := d.GetOk("name"); ok {
userRole.Name = v.(string)
}

if v, ok := d.GetOk("space_permission_descriptions"); ok {
userRole.SpacePermissionDescriptions = v.([]string)
userRole.SpacePermissionDescriptions = getSliceFromTerraformTypeList(v)
}

if v, ok := d.GetOk("supported_restrictions"); ok {
userRole.SupportedRestrictions = v.([]string)
userRole.SupportedRestrictions = getSliceFromTerraformTypeList(v)
}

if v, ok := d.GetOk("system_permission_descriptions"); ok {
userRole.SystemPermissionDescriptions = v.([]string)
userRole.SystemPermissionDescriptions = getSliceFromTerraformTypeList(v)
}

return userRole
Expand Down Expand Up @@ -106,6 +106,7 @@ func getUserRoleSchema() map[string]*schema.Schema {
"id": getIDSchema(),
"name": getNameSchema(true),
"space_permission_descriptions": {
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
Optional: true,
Type: schema.TypeList,
Expand All @@ -116,6 +117,7 @@ func getUserRoleSchema() map[string]*schema.Schema {
Type: schema.TypeList,
},
"system_permission_descriptions": {
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
Optional: true,
Type: schema.TypeList,
Expand Down

0 comments on commit 7122201

Please sign in to comment.