@@ -8,13 +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
-
12
- matlas "go.mongodb.org/atlas/mongodbatlas"
11
+ "go.mongodb.org/atlas-sdk/v20240530002/admin"
13
12
)
14
13
15
14
func PluralDataSource () * schema.Resource {
16
15
return & schema.Resource {
17
- ReadContext : dataSourceMongoDBAtlasProjectAPIKeysRead ,
16
+ ReadContext : pluralDataSourceRead ,
18
17
Schema : map [string ]* schema.Schema {
19
18
"project_id" : {
20
19
Type : schema .TypeString ,
@@ -75,22 +74,19 @@ func PluralDataSource() *schema.Resource {
75
74
}
76
75
}
77
76
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 )
85
81
86
82
projectID := d .Get ("project_id" ).(string )
87
83
88
- apiKeys , _ , err := conn . ProjectAPIKeys . List (ctx , projectID , options )
84
+ apiKeys , _ , err := connV2 . ProgrammaticAPIKeysApi . ListProjectApiKeys (ctx , projectID ). PageNum ( pageNum ). ItemsPerPage ( itemsPerPage ). Execute ( )
89
85
if err != nil {
90
86
return diag .FromErr (fmt .Errorf ("error getting api keys information: %s" , err ))
91
87
}
92
88
93
- results , err := flattenProjectAPIKeys (ctx , conn , projectID , apiKeys )
89
+ results , err := flattenProjectAPIKeys (ctx , connV2 , apiKeys . GetResults () )
94
90
if err != nil {
95
91
diag .FromErr (fmt .Errorf ("error setting `results`: %s" , err ))
96
92
}
@@ -104,7 +100,7 @@ func dataSourceMongoDBAtlasProjectAPIKeysRead(ctx context.Context, d *schema.Res
104
100
return nil
105
101
}
106
102
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 ) {
108
104
var results []map [string ]any
109
105
110
106
if len (apiKeys ) == 0 {
@@ -114,13 +110,13 @@ func flattenProjectAPIKeys(ctx context.Context, conn *matlas.Client, projectID s
114
110
results = make ([]map [string ]any , len (apiKeys ))
115
111
for k , apiKey := range apiKeys {
116
112
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 () ,
121
117
}
122
118
123
- projectAssignment , err := newProjectAssignment (ctx , conn , apiKey .ID )
119
+ projectAssignment , err := newProjectAssignment (ctx , connV2 , apiKey .GetId () )
124
120
if err != nil {
125
121
return nil , err
126
122
}
0 commit comments