@@ -221,16 +221,7 @@ func (r *environmentResource) Create(ctx context.Context, req resource.CreateReq
221
221
return
222
222
}
223
223
224
- resp .Diagnostics .Append (fwflex .Flatten (ctx , output , & state , fwflex .WithIgnoredFieldNames ([]string {"UserParameters" }))... )
225
- if resp .Diagnostics .HasError () {
226
- return
227
- }
228
-
229
- state .AccountIdentifier = fwflex .StringToFramework (ctx , out .AwsAccountId )
230
- state .AccountRegion = fwflex .StringToFramework (ctx , out .AwsAccountRegion )
231
- state .BlueprintIdentifier = fwflex .StringToFramework (ctx , out .EnvironmentBlueprintId )
232
-
233
- populateUserParameters (ctx , & state .UserParameters , output .UserParameters , & resp .Diagnostics )
224
+ flattenEnvironment (ctx , output , & state , & resp .Diagnostics )
234
225
if resp .Diagnostics .HasError () {
235
226
return
236
227
}
@@ -263,25 +254,7 @@ func (r *environmentResource) Read(ctx context.Context, req resource.ReadRequest
263
254
return
264
255
}
265
256
266
- resp .Diagnostics .Append (fwflex .Flatten (ctx , out , & state , fwflex .WithIgnoredFieldNamesAppend ("UserParameters" ),
267
- fwflex .WithFieldNamePrefix ("Environment" ),
268
- )... )
269
-
270
- if resp .Diagnostics .HasError () {
271
- return
272
- }
273
-
274
- state .AccountIdentifier = fwflex .StringToFramework (ctx , out .AwsAccountId )
275
- state .AccountRegion = fwflex .StringToFramework (ctx , out .AwsAccountRegion )
276
- state .BlueprintIdentifier = fwflex .StringToFramework (ctx , out .EnvironmentBlueprintId )
277
- state .ProjectIdentifier = fwflex .StringToFramework (ctx , out .ProjectId )
278
- state .ProfileIdentifier = fwflex .StringToFramework (ctx , out .EnvironmentProfileId )
279
-
280
- if state .UserParameters .IsNull () { // Import
281
- importUserParameters (ctx , & state .UserParameters , out .UserParameters , & resp .Diagnostics )
282
- } else {
283
- populateUserParameters (ctx , & state .UserParameters , out .UserParameters , & resp .Diagnostics )
284
- }
257
+ flattenEnvironment (ctx , out , & state , & resp .Diagnostics )
285
258
if resp .Diagnostics .HasError () {
286
259
return
287
260
}
@@ -355,16 +328,7 @@ func (r *environmentResource) Update(ctx context.Context, req resource.UpdateReq
355
328
return
356
329
}
357
330
358
- resp .Diagnostics .Append (fwflex .Flatten (ctx , output , & plan , fwflex .WithIgnoredFieldNames ([]string {"UserParameters" }))... )
359
- if resp .Diagnostics .HasError () {
360
- return
361
- }
362
-
363
- plan .AccountIdentifier = fwflex .StringToFramework (ctx , output .AwsAccountId )
364
- plan .AccountRegion = fwflex .StringToFramework (ctx , output .AwsAccountRegion )
365
- plan .BlueprintIdentifier = fwflex .StringToFramework (ctx , output .EnvironmentBlueprintId )
366
-
367
- populateUserParameters (ctx , & plan .UserParameters , output .UserParameters , & resp .Diagnostics )
331
+ flattenEnvironment (ctx , output , & plan , & resp .Diagnostics )
368
332
if resp .Diagnostics .HasError () {
369
333
return
370
334
}
@@ -549,6 +513,22 @@ type environmentResourceModel struct {
549
513
UserParameters fwtypes.ListNestedObjectValueOf [resourceUserParametersData ] `tfsdk:"user_parameters"`
550
514
}
551
515
516
+ func flattenEnvironment (ctx context.Context , apiObject * datazone.GetEnvironmentOutput , model * environmentResourceModel , diags * diag.Diagnostics ) {
517
+ diags .Append (fwflex .Flatten (ctx , apiObject , model , fwflex .WithIgnoredFieldNamesAppend ("UserParameters" ))... )
518
+
519
+ model .AccountIdentifier = fwflex .StringToFramework (ctx , apiObject .AwsAccountId )
520
+ model .AccountRegion = fwflex .StringToFramework (ctx , apiObject .AwsAccountRegion )
521
+ model .BlueprintIdentifier = fwflex .StringToFramework (ctx , apiObject .EnvironmentBlueprintId )
522
+ model .ProfileIdentifier = fwflex .StringToFramework (ctx , apiObject .EnvironmentProfileId )
523
+ model .ProjectIdentifier = fwflex .StringToFramework (ctx , apiObject .ProjectId )
524
+
525
+ if model .UserParameters .IsNull () { // Import
526
+ importUserParameters (ctx , & model .UserParameters , apiObject .UserParameters , diags )
527
+ } else {
528
+ populateUserParameters (ctx , & model .UserParameters , apiObject .UserParameters , diags )
529
+ }
530
+ }
531
+
552
532
type resourceLastDeployment struct {
553
533
DeploymentId types.String `tfsdk:"deployment_id"`
554
534
DeploymentStatus types.String `tfsdk:"deployment_status"`
0 commit comments