@@ -5,14 +5,14 @@ import (
5
5
"fmt"
6
6
7
7
"go.mongodb.org/atlas-sdk/v20231115002/admin"
8
- matlas "go.mongodb.org/atlas/mongodbatlas"
9
8
10
9
"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
11
10
"github.com/hashicorp/terraform-plugin-framework/datasource"
12
11
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
13
12
"github.com/hashicorp/terraform-plugin-framework/path"
14
13
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
15
14
"github.com/hashicorp/terraform-plugin-framework/types"
15
+ "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion"
16
16
"github.com/mongodb/terraform-provider-mongodbatlas/internal/config"
17
17
)
18
18
@@ -144,7 +144,6 @@ func (d *projectDS) Schema(ctx context.Context, req datasource.SchemaRequest, re
144
144
145
145
func (d * projectDS ) Read (ctx context.Context , req datasource.ReadRequest , resp * datasource.ReadResponse ) {
146
146
var projectState tfProjectDSModel
147
- conn := d .Client .Atlas
148
147
connV2 := d .Client .AtlasV2
149
148
150
149
resp .Diagnostics .Append (req .Config .Get (ctx , & projectState )... )
@@ -156,28 +155,28 @@ func (d *projectDS) Read(ctx context.Context, req datasource.ReadRequest, resp *
156
155
157
156
var (
158
157
err error
159
- project * matlas. Project
158
+ project * admin. Group
160
159
)
161
160
162
161
if ! projectState .ProjectID .IsNull () {
163
162
projectID := projectState .ProjectID .ValueString ()
164
- project , _ , err = conn . Projects . GetOneProject (ctx , projectID )
163
+ project , _ , err = connV2 . ProjectsApi . GetProject (ctx , projectID ). Execute ( )
165
164
if err != nil {
166
165
resp .Diagnostics .AddError ("error when getting project from Atlas" , fmt .Sprintf (ErrorProjectRead , projectID , err .Error ()))
167
166
return
168
167
}
169
168
} else {
170
169
name := projectState .Name .ValueString ()
171
- project , _ , err = conn . Projects . GetOneProjectByName (ctx , name )
170
+ project , _ , err = connV2 . ProjectsApi . GetProjectByName (ctx , name ). Execute ( )
172
171
if err != nil {
173
172
resp .Diagnostics .AddError ("error when getting project from Atlas" , fmt .Sprintf (ErrorProjectRead , name , err .Error ()))
174
173
return
175
174
}
176
175
}
177
176
178
- atlasTeams , atlasLimits , atlasProjectSettings , err := getProjectPropsFromAPI (ctx , conn , connV2 , project .ID )
177
+ atlasTeams , atlasLimits , atlasProjectSettings , err := getProjectPropsFromAPI (ctx , connV2 , project .GetId () )
179
178
if err != nil {
180
- resp .Diagnostics .AddError ("error when getting project properties" , fmt .Sprintf (ErrorProjectRead , project .ID , err .Error ()))
179
+ resp .Diagnostics .AddError ("error when getting project properties" , fmt .Sprintf (ErrorProjectRead , project .GetId () , err .Error ()))
181
180
return
182
181
}
183
182
@@ -189,15 +188,15 @@ func (d *projectDS) Read(ctx context.Context, req datasource.ReadRequest, resp *
189
188
}
190
189
}
191
190
192
- func newTFProjectDataSourceModel (ctx context.Context , project * matlas. Project ,
193
- teams * matlas. TeamsAssigned , projectSettings * matlas. ProjectSettings , limits []admin.DataFederationLimit ) tfProjectDSModel {
191
+ func newTFProjectDataSourceModel (ctx context.Context , project * admin. Group ,
192
+ teams * admin. PaginatedTeamRole , projectSettings * admin. GroupSettings , limits []admin.DataFederationLimit ) tfProjectDSModel {
194
193
return tfProjectDSModel {
195
- ID : types .StringValue (project .ID ),
196
- ProjectID : types .StringValue (project .ID ),
194
+ ID : types .StringValue (project .GetId () ),
195
+ ProjectID : types .StringValue (project .GetId () ),
197
196
Name : types .StringValue (project .Name ),
198
- OrgID : types .StringValue (project .OrgID ),
199
- ClusterCount : types .Int64Value (int64 ( project .ClusterCount ) ),
200
- Created : types .StringValue (project .Created ),
197
+ OrgID : types .StringValue (project .OrgId ),
198
+ ClusterCount : types .Int64Value (project .ClusterCount ),
199
+ Created : types .StringValue (conversion . TimeToString ( project .Created ) ),
201
200
IsCollectDatabaseSpecificsStatisticsEnabled : types .BoolValue (* projectSettings .IsCollectDatabaseSpecificsStatisticsEnabled ),
202
201
IsDataExplorerEnabled : types .BoolValue (* projectSettings .IsDataExplorerEnabled ),
203
202
IsExtendedStorageSizesEnabled : types .BoolValue (* projectSettings .IsExtendedStorageSizesEnabled ),
@@ -209,8 +208,8 @@ func newTFProjectDataSourceModel(ctx context.Context, project *matlas.Project,
209
208
}
210
209
}
211
210
212
- func newTFTeamsDataSourceModel (ctx context.Context , atlasTeams * matlas. TeamsAssigned ) []* tfTeamDSModel {
213
- if atlasTeams .TotalCount == 0 {
211
+ func newTFTeamsDataSourceModel (ctx context.Context , atlasTeams * admin. PaginatedTeamRole ) []* tfTeamDSModel {
212
+ if atlasTeams .GetTotalCount () == 0 {
214
213
return nil
215
214
}
216
215
teams := make ([]* tfTeamDSModel , len (atlasTeams .Results ))
@@ -219,7 +218,7 @@ func newTFTeamsDataSourceModel(ctx context.Context, atlasTeams *matlas.TeamsAssi
219
218
roleNames , _ := types .ListValueFrom (ctx , types .StringType , atlasTeam .RoleNames )
220
219
221
220
teams [i ] = & tfTeamDSModel {
222
- TeamID : types .StringValue (atlasTeam .TeamID ),
221
+ TeamID : types .StringValue (atlasTeam .GetTeamId () ),
223
222
RoleNames : roleNames ,
224
223
}
225
224
}
0 commit comments