@@ -8,13 +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-
12- matlas "go.mongodb.org/atlas/mongodbatlas"
11+ "go.mongodb.org/atlas-sdk/v20240530002/admin"
1312)
1413
1514func PluralDataSource () * schema.Resource {
1615 return & schema.Resource {
17- ReadContext : dataSourceMongoDBAtlasProjectAPIKeysRead ,
16+ ReadContext : pluralDataSourceRead ,
1817 Schema : map [string ]* schema.Schema {
1918 "project_id" : {
2019 Type : schema .TypeString ,
@@ -75,22 +74,19 @@ func PluralDataSource() *schema.Resource {
7574 }
7675}
7776
78- func dataSourceMongoDBAtlasProjectAPIKeysRead (ctx context.Context , d * schema.ResourceData , meta any ) diag.Diagnostics {
79- // Get client connection.
80- conn := meta .(* config.MongoDBClient ).Atlas
81- options := & matlas.ListOptions {
82- PageNum : d .Get ("page_num" ).(int ),
83- ItemsPerPage : d .Get ("items_per_page" ).(int ),
84- }
77+ func pluralDataSourceRead (ctx context.Context , d * schema.ResourceData , meta any ) diag.Diagnostics {
78+ connV2 := meta .(* config.MongoDBClient ).AtlasV2
79+ pageNum := d .Get ("page_num" ).(int )
80+ itemsPerPage := d .Get ("items_per_page" ).(int )
8581
8682 projectID := d .Get ("project_id" ).(string )
8783
88- apiKeys , _ , err := conn . ProjectAPIKeys . List (ctx , projectID , options )
84+ apiKeys , _ , err := connV2 . ProgrammaticAPIKeysApi . ListProjectApiKeys (ctx , projectID ). PageNum ( pageNum ). ItemsPerPage ( itemsPerPage ). Execute ( )
8985 if err != nil {
9086 return diag .FromErr (fmt .Errorf ("error getting api keys information: %s" , err ))
9187 }
9288
93- results , err := flattenProjectAPIKeys (ctx , conn , projectID , apiKeys )
89+ results , err := flattenProjectAPIKeys (ctx , connV2 , apiKeys . GetResults () )
9490 if err != nil {
9591 diag .FromErr (fmt .Errorf ("error setting `results`: %s" , err ))
9692 }
@@ -104,7 +100,7 @@ func dataSourceMongoDBAtlasProjectAPIKeysRead(ctx context.Context, d *schema.Res
104100 return nil
105101}
106102
107- func flattenProjectAPIKeys (ctx context.Context , conn * matlas. Client , projectID string , apiKeys []matlas. APIKey ) ([]map [string ]any , error ) {
103+ func flattenProjectAPIKeys (ctx context.Context , connV2 * admin. APIClient , apiKeys []admin. ApiKeyUserDetails ) ([]map [string ]any , error ) {
108104 var results []map [string ]any
109105
110106 if len (apiKeys ) == 0 {
@@ -114,13 +110,13 @@ func flattenProjectAPIKeys(ctx context.Context, conn *matlas.Client, projectID s
114110 results = make ([]map [string ]any , len (apiKeys ))
115111 for k , apiKey := range apiKeys {
116112 results [k ] = map [string ]any {
117- "api_key_id" : apiKey .ID ,
118- "description" : apiKey .Desc ,
119- "public_key" : apiKey .PublicKey ,
120- "private_key" : apiKey .PrivateKey ,
113+ "api_key_id" : apiKey .GetId () ,
114+ "description" : apiKey .GetDesc () ,
115+ "public_key" : apiKey .GetPublicKey () ,
116+ "private_key" : apiKey .GetPrivateKey () ,
121117 }
122118
123- projectAssignment , err := newProjectAssignment (ctx , conn , apiKey .ID )
119+ projectAssignment , err := newProjectAssignment (ctx , connV2 , apiKey .GetId () )
124120 if err != nil {
125121 return nil , err
126122 }
0 commit comments