@@ -4,11 +4,8 @@ import (
4
4
"context"
5
5
"log"
6
6
"os"
7
- "regexp"
8
- "time"
9
7
10
8
"github.com/hashicorp/terraform-plugin-framework-validators/listvalidator"
11
- "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
12
9
"github.com/hashicorp/terraform-plugin-framework/attr"
13
10
"github.com/hashicorp/terraform-plugin-framework/datasource"
14
11
"github.com/hashicorp/terraform-plugin-framework/diag"
@@ -24,7 +21,6 @@ import (
24
21
"github.com/hashicorp/terraform-plugin-mux/tf6muxserver"
25
22
26
23
"github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion"
27
- "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/validate"
28
24
"github.com/mongodb/terraform-provider-mongodbatlas/internal/config"
29
25
"github.com/mongodb/terraform-provider-mongodbatlas/internal/service/advancedcluster"
30
26
"github.com/mongodb/terraform-provider-mongodbatlas/internal/service/alertconfiguration"
@@ -92,27 +88,11 @@ type tfMongodbAtlasProviderModel struct {
92
88
}
93
89
94
90
type tfAssumeRoleModel struct {
95
- PolicyARNs types.Set `tfsdk:"policy_arns"`
96
- TransitiveTagKeys types.Set `tfsdk:"transitive_tag_keys"`
97
- Tags types.Map `tfsdk:"tags"`
98
- Duration types.String `tfsdk:"duration"`
99
- ExternalID types.String `tfsdk:"external_id"`
100
- Policy types.String `tfsdk:"policy"`
101
- RoleARN types.String `tfsdk:"role_arn"`
102
- SessionName types.String `tfsdk:"session_name"`
103
- SourceIdentity types.String `tfsdk:"source_identity"`
91
+ RoleARN types.String `tfsdk:"role_arn"`
104
92
}
105
93
106
94
var AssumeRoleType = types.ObjectType {AttrTypes : map [string ]attr.Type {
107
- "policy_arns" : types.SetType {ElemType : types .StringType },
108
- "transitive_tag_keys" : types.SetType {ElemType : types .StringType },
109
- "tags" : types.MapType {ElemType : types .StringType },
110
- "duration" : types .StringType ,
111
- "external_id" : types .StringType ,
112
- "policy" : types .StringType ,
113
- "role_arn" : types .StringType ,
114
- "session_name" : types .StringType ,
115
- "source_identity" : types .StringType ,
95
+ "role_arn" : types .StringType ,
116
96
}}
117
97
118
98
func (p * MongodbtlasProvider ) Metadata (ctx context.Context , req provider.MetadataRequest , resp * provider.MetadataResponse ) {
@@ -211,63 +191,10 @@ var fwAssumeRoleSchema = schema.ListNestedBlock{
211
191
Validators : []validator.List {listvalidator .SizeAtMost (1 )},
212
192
NestedObject : schema.NestedBlockObject {
213
193
Attributes : map [string ]schema.Attribute {
214
- "duration" : schema.StringAttribute {
215
- Optional : true ,
216
- Description : "The duration, between 15 minutes and 12 hours, of the role session. Valid time units are ns, us (or µs), ms, s, h, or m." ,
217
- Validators : []validator.String {
218
- validate .ValidDurationBetween (15 , 12 * 60 ),
219
- },
220
- },
221
- "external_id" : schema.StringAttribute {
222
- Optional : true ,
223
- Description : "A unique identifier that might be required when you assume a role in another account." ,
224
- Validators : []validator.String {
225
- stringvalidator .LengthBetween (2 , 1224 ),
226
- stringvalidator .RegexMatches (regexp .MustCompile (`[\w+=,.@:/\-]*` ), "" ),
227
- },
228
- },
229
- "policy" : schema.StringAttribute {
230
- Optional : true ,
231
- Description : "IAM Policy JSON describing further restricting permissions for the IAM Role being assumed." ,
232
- Validators : []validator.String {
233
- validate .StringIsJSON (),
234
- },
235
- },
236
- "policy_arns" : schema.SetAttribute {
237
- ElementType : types .StringType ,
238
- Optional : true ,
239
- Description : "Amazon Resource Names (ARNs) of IAM Policies describing further restricting permissions for the IAM Role being assumed." ,
240
- },
241
194
"role_arn" : schema.StringAttribute {
242
195
Optional : true ,
243
196
Description : "Amazon Resource Name (ARN) of an IAM Role to assume prior to making API calls." ,
244
197
},
245
- "session_name" : schema.StringAttribute {
246
- Optional : true ,
247
- Description : "An identifier for the assumed role session." ,
248
- Validators : []validator.String {
249
- stringvalidator .LengthBetween (2 , 64 ),
250
- stringvalidator .RegexMatches (regexp .MustCompile (`[\w+=,.@\-]*` ), "" ),
251
- },
252
- },
253
- "source_identity" : schema.StringAttribute {
254
- Optional : true ,
255
- Description : "Source identity specified by the principal assuming the role." ,
256
- Validators : []validator.String {
257
- stringvalidator .LengthBetween (2 , 64 ),
258
- stringvalidator .RegexMatches (regexp .MustCompile (`[\w+=,.@\-]*` ), "" ),
259
- },
260
- },
261
- "tags" : schema.MapAttribute {
262
- ElementType : types .StringType ,
263
- Optional : true ,
264
- Description : "Assume role session tags." ,
265
- },
266
- "transitive_tag_keys" : schema.SetAttribute {
267
- ElementType : types .StringType ,
268
- Optional : true ,
269
- Description : "Assume role session tag keys to pass to any subsequent sessions." ,
270
- },
271
198
},
272
199
},
273
200
}
@@ -300,7 +227,7 @@ func (p *MongodbtlasProvider) Configure(ctx context.Context, req provider.Config
300
227
data .AssumeRole .ElementsAs (ctx , & assumeRoles , true )
301
228
awsRoleDefined := len (assumeRoles ) > 0
302
229
if awsRoleDefined {
303
- cfg .AssumeRole = parseTfModel ( ctx , & assumeRoles [0 ])
230
+ cfg .AssumeRoleARN = assumeRoles [0 ]. RoleARN . ValueString ( )
304
231
secret := data .SecretName .ValueString ()
305
232
region := conversion .MongoDBRegionToAWSRegion (data .Region .ValueString ())
306
233
awsAccessKeyID := data .AwsAccessKeyID .ValueString ()
@@ -329,37 +256,6 @@ func (p *MongodbtlasProvider) Configure(ctx context.Context, req provider.Config
329
256
resp .ResourceData = client
330
257
}
331
258
332
- // parseTfModel extracts the values from tfAssumeRoleModel creating a new instance of our internal model AssumeRole used in Config
333
- func parseTfModel (ctx context.Context , tfAssumeRoleModel * tfAssumeRoleModel ) * config.AssumeRole {
334
- assumeRole := config.AssumeRole {}
335
-
336
- if ! tfAssumeRoleModel .Duration .IsNull () {
337
- duration , _ := time .ParseDuration (tfAssumeRoleModel .Duration .ValueString ())
338
- assumeRole .Duration = duration
339
- }
340
-
341
- assumeRole .ExternalID = tfAssumeRoleModel .ExternalID .ValueString ()
342
- assumeRole .Policy = tfAssumeRoleModel .Policy .ValueString ()
343
-
344
- if ! tfAssumeRoleModel .PolicyARNs .IsNull () {
345
- var policiesARNs []string
346
- tfAssumeRoleModel .PolicyARNs .ElementsAs (ctx , & policiesARNs , true )
347
- assumeRole .PolicyARNs = policiesARNs
348
- }
349
-
350
- assumeRole .RoleARN = tfAssumeRoleModel .RoleARN .ValueString ()
351
- assumeRole .SessionName = tfAssumeRoleModel .SessionName .ValueString ()
352
- assumeRole .SourceIdentity = tfAssumeRoleModel .SourceIdentity .ValueString ()
353
-
354
- if ! tfAssumeRoleModel .TransitiveTagKeys .IsNull () {
355
- var transitiveTagKeys []string
356
- tfAssumeRoleModel .TransitiveTagKeys .ElementsAs (ctx , & transitiveTagKeys , true )
357
- assumeRole .TransitiveTagKeys = transitiveTagKeys
358
- }
359
-
360
- return & assumeRole
361
- }
362
-
363
259
func setDefaultValuesWithValidations (ctx context.Context , data * tfMongodbAtlasProviderModel , resp * provider.ConfigureResponse ) tfMongodbAtlasProviderModel {
364
260
if mongodbgovCloud := data .IsMongodbGovCloud .ValueBool (); mongodbgovCloud {
365
261
if ! isGovBaseURLConfiguredForProvider (data ) {
@@ -384,10 +280,7 @@ func setDefaultValuesWithValidations(ctx context.Context, data *tfMongodbAtlasPr
384
280
var diags diag.Diagnostics
385
281
data .AssumeRole , diags = types .ListValueFrom (ctx , AssumeRoleType , []tfAssumeRoleModel {
386
282
{
387
- Tags : types .MapNull (types .StringType ),
388
- PolicyARNs : types .SetNull (types .StringType ),
389
- TransitiveTagKeys : types .SetNull (types .StringType ),
390
- RoleARN : types .StringValue (assumeRoleArn ),
283
+ RoleARN : types .StringValue (assumeRoleArn ),
391
284
},
392
285
})
393
286
if diags .HasError () {
0 commit comments