@@ -8,12 +8,12 @@ import (
8
8
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/id"
9
9
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
10
10
"github.com/mongodb/terraform-provider-mongodbatlas/internal/config"
11
- matlas "go.mongodb.org/atlas/mongodbatlas "
11
+ "go.mongodb.org/atlas-sdk/v20231115005/admin "
12
12
)
13
13
14
14
func PluralDataSource () * schema.Resource {
15
15
return & schema.Resource {
16
- ReadContext : dataSourceMongoDBAtlasCustomDBRolesRead ,
16
+ ReadContext : dataSourcePluralRead ,
17
17
Schema : map [string ]* schema.Schema {
18
18
"project_id" : {
19
19
Type : schema .TypeString ,
@@ -83,16 +83,16 @@ func PluralDataSource() *schema.Resource {
83
83
}
84
84
}
85
85
86
- func dataSourceMongoDBAtlasCustomDBRolesRead (ctx context.Context , d * schema.ResourceData , meta any ) diag.Diagnostics {
87
- conn := meta .(* config.MongoDBClient ).Atlas
86
+ func dataSourcePluralRead (ctx context.Context , d * schema.ResourceData , meta any ) diag.Diagnostics {
87
+ connV2 := meta .(* config.MongoDBClient ).AtlasV2
88
88
projectID := d .Get ("project_id" ).(string )
89
89
90
- customDBRoles , _ , err := conn . CustomDBRoles . List (ctx , projectID , nil )
90
+ customDBRoles , _ , err := connV2 . CustomDatabaseRolesApi . ListCustomDatabaseRoles (ctx , projectID ). Execute ( )
91
91
if err != nil {
92
92
return diag .FromErr (fmt .Errorf ("error getting custom db roles information: %s" , err ))
93
93
}
94
94
95
- if err := d .Set ("results" , flattenCustomDBRoles (* customDBRoles )); err != nil {
95
+ if err := d .Set ("results" , flattenCustomDBRoles (customDBRoles )); err != nil {
96
96
return diag .FromErr (fmt .Errorf ("error setting `results for custom db roles: %s" , err ))
97
97
}
98
98
@@ -101,20 +101,14 @@ func dataSourceMongoDBAtlasCustomDBRolesRead(ctx context.Context, d *schema.Reso
101
101
return nil
102
102
}
103
103
104
- func flattenCustomDBRoles (customDBRoles []matlas.CustomDBRole ) []map [string ]any {
105
- var customDBRolesMap []map [string ]any
106
-
107
- if len (customDBRoles ) > 0 {
108
- customDBRolesMap = make ([]map [string ]any , len (customDBRoles ))
109
-
110
- for k , customDBRole := range customDBRoles {
111
- customDBRolesMap [k ] = map [string ]any {
112
- "role_name" : customDBRole .RoleName ,
113
- "actions" : flattenActions (customDBRole .Actions ),
114
- "inherited_roles" : flattenInheritedRoles (customDBRole .InheritedRoles ),
115
- }
104
+ func flattenCustomDBRoles (customDBRoles []admin.UserCustomDBRole ) []map [string ]any {
105
+ customDBRolesMap := make ([]map [string ]any , len (customDBRoles ))
106
+ for k , customDBRole := range customDBRoles {
107
+ customDBRolesMap [k ] = map [string ]any {
108
+ "role_name" : customDBRole .RoleName ,
109
+ "actions" : flattenActions (customDBRole .GetActions ()),
110
+ "inherited_roles" : flattenInheritedRoles (customDBRole .GetInheritedRoles ()),
116
111
}
117
112
}
118
-
119
113
return customDBRolesMap
120
114
}
0 commit comments