Skip to content

Commit d132a64

Browse files
authored
fix: update correctly user role when collectionName is removed (#1471)
* fix: remove collectionName from user role doesn't work * remove computed attribute and check optionality for the collection_name field. * fix test expectations (as it should be).
1 parent 0694a78 commit d132a64

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

mongodbatlas/fw_resource_mongodbatlas_database_user.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,6 @@ func (r *DatabaseUserRS) Schema(ctx context.Context, req resource.SchemaRequest,
165165
Attributes: map[string]schema.Attribute{
166166
"collection_name": schema.StringAttribute{
167167
Optional: true,
168-
Computed: true,
169168
},
170169
"database_name": schema.StringAttribute{
171170
Required: true,
@@ -455,9 +454,12 @@ func newTFRolesModel(roles []matlas.Role) []tfRoleModel {
455454
out := make([]tfRoleModel, len(roles))
456455
for i, v := range roles {
457456
out[i] = tfRoleModel{
458-
RoleName: types.StringValue(v.RoleName),
459-
DatabaseName: types.StringValue(v.DatabaseName),
460-
CollectionName: types.StringValue(v.CollectionName),
457+
RoleName: types.StringValue(v.RoleName),
458+
DatabaseName: types.StringValue(v.DatabaseName),
459+
}
460+
461+
if v.CollectionName != "" {
462+
out[i].CollectionName = types.StringValue(v.CollectionName)
461463
}
462464
}
463465

mongodbatlas/fw_resource_mongodbatlas_database_user_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,8 @@ func TestAccConfigRSDatabaseUser_withRoles(t *testing.T) {
308308
resource.TestCheckResourceAttr(resourceName, "password", password),
309309
resource.TestCheckResourceAttr(resourceName, "auth_database_name", "admin"),
310310
resource.TestCheckResourceAttr(resourceName, "roles.#", "2"),
311+
resource.TestCheckResourceAttr(resourceName, "roles.0.collection_name", "stir"),
312+
resource.TestCheckResourceAttr(resourceName, "roles.1.collection_name", "unpledged"),
311313
),
312314
},
313315
{

0 commit comments

Comments
 (0)