@@ -8,12 +8,12 @@ import (
88 "github.com/hashicorp/terraform-plugin-sdk/v2/helper/id"
99 "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
1010 "github.com/mongodb/terraform-provider-mongodbatlas/internal/config"
11- matlas "go.mongodb.org/atlas/mongodbatlas "
11+ "go.mongodb.org/atlas-sdk/v20231115005/admin "
1212)
1313
1414func PluralDataSource () * schema.Resource {
1515 return & schema.Resource {
16- ReadContext : dataSourceMongoDBAtlasCustomDBRolesRead ,
16+ ReadContext : dataSourcePluralRead ,
1717 Schema : map [string ]* schema.Schema {
1818 "project_id" : {
1919 Type : schema .TypeString ,
@@ -83,16 +83,16 @@ func PluralDataSource() *schema.Resource {
8383 }
8484}
8585
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
8888 projectID := d .Get ("project_id" ).(string )
8989
90- customDBRoles , _ , err := conn . CustomDBRoles . List (ctx , projectID , nil )
90+ customDBRoles , _ , err := connV2 . CustomDatabaseRolesApi . ListCustomDatabaseRoles (ctx , projectID ). Execute ( )
9191 if err != nil {
9292 return diag .FromErr (fmt .Errorf ("error getting custom db roles information: %s" , err ))
9393 }
9494
95- if err := d .Set ("results" , flattenCustomDBRoles (* customDBRoles )); err != nil {
95+ if err := d .Set ("results" , flattenCustomDBRoles (customDBRoles )); err != nil {
9696 return diag .FromErr (fmt .Errorf ("error setting `results for custom db roles: %s" , err ))
9797 }
9898
@@ -101,20 +101,14 @@ func dataSourceMongoDBAtlasCustomDBRolesRead(ctx context.Context, d *schema.Reso
101101 return nil
102102}
103103
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 ()),
116111 }
117112 }
118-
119113 return customDBRolesMap
120114}
0 commit comments