diff --git a/examples/cluster.tf b/examples/cluster.tf index 4f81f56b..b8ee6d85 100644 --- a/examples/cluster.tf +++ b/examples/cluster.tf @@ -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" + } + ] } diff --git a/mongodbatlas/database_user.go b/mongodbatlas/database_user.go index 4fb7cd51..649e291f 100644 --- a/mongodbatlas/database_user.go +++ b/mongodbatlas/database_user.go @@ -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), ¶ms) if err != nil { @@ -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 } @@ -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{}) @@ -154,4 +154,5 @@ func readRolesFromSchema(roles []mongodb.Role, rolesMap []interface{}) { CollectionName: roleMap["collection"].(string), } } + return roles }