Skip to content

Commit

Permalink
fix the roles in mongodbatlas_database_user resource
Browse files Browse the repository at this point in the history
  • Loading branch information
akshaykarle committed Jan 10, 2018
1 parent 62eddd1 commit ff38d2e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
10 changes: 6 additions & 4 deletions examples/cluster.tf
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,10 @@ resource "mongodbatlas_database_user" "test" {
password = "${var.database_user_test_password}"
database = "admin"
group = "${var.mongodb_atlas_group_id}"
roles = [{
name = "read"
database = "admin"
}]
roles = [
{
name = "read"
database = "admin"
}
]
}
7 changes: 4 additions & 3 deletions mongodbatlas/database_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func resourceDatabaseUserCreate(d *schema.ResourceData, meta interface{}) error
DatabaseName: d.Get("database").(string),
}

readRolesFromSchema(params.Roles, d.Get("roles").([]interface{}))
params.Roles = readRolesFromSchema(d.Get("roles").([]interface{}))

databaseUser, _, err := client.DatabaseUsers.Create(d.Get("group").(string), &params)
if err != nil {
Expand Down Expand Up @@ -117,7 +117,7 @@ func resourceDatabaseUserUpdate(d *schema.ResourceData, meta interface{}) error
requestUpdate = true
}
if d.HasChange("roles") {
readRolesFromSchema(c.Roles, d.Get("roles").([]interface{}))
c.Roles = readRolesFromSchema(d.Get("roles").([]interface{}))
requestUpdate = true
}

Expand All @@ -143,7 +143,7 @@ func resourceDatabaseUserDelete(d *schema.ResourceData, meta interface{}) error
return nil
}

func readRolesFromSchema(roles []mongodb.Role, rolesMap []interface{}) {
func readRolesFromSchema(rolesMap []interface{}) (roles []mongodb.Role) {
roles = make([]mongodb.Role, len(rolesMap))
for i, r := range rolesMap {
roleMap := r.(map[string]interface{})
Expand All @@ -154,4 +154,5 @@ func readRolesFromSchema(roles []mongodb.Role, rolesMap []interface{}) {
CollectionName: roleMap["collection"].(string),
}
}
return roles
}

0 comments on commit ff38d2e

Please sign in to comment.