@@ -244,23 +244,13 @@ func (data *DeploymentResource) ReadFromResponse(
244
244
data .SchedulerSize = types .StringPointerValue ((* string )(deployment .SchedulerSize ))
245
245
data .IsDevelopmentMode = types .BoolPointerValue (deployment .IsDevelopmentMode )
246
246
data .IsHighAvailability = types .BoolPointerValue (deployment .IsHighAvailability )
247
-
248
- // Currently, the scaling status and spec are only available in development mode
249
- // However, there is a bug in the API where the scaling status and spec are returned even if the deployment is not in development mode for updated deployments
250
- // This is a workaround to handle the bug until the API is fixed
251
- // Issue here: https://github.com/astronomer/astro/issues/21073
252
- if deployment .IsDevelopmentMode != nil && * deployment .IsDevelopmentMode {
253
- data .ScalingStatus , diags = ScalingStatusTypesObject (ctx , deployment .ScalingStatus )
254
- if diags .HasError () {
255
- return diags
256
- }
257
- data .ScalingSpec , diags = ScalingSpecTypesObject (ctx , deployment .ScalingSpec )
258
- if diags .HasError () {
259
- return diags
260
- }
261
- } else {
262
- data .ScalingStatus = types .ObjectNull (schemas .ScalingStatusAttributeTypes ())
263
- data .ScalingSpec = types .ObjectNull (schemas .ScalingSpecAttributeTypes ())
247
+ data .ScalingStatus , diags = ScalingStatusTypesObject (ctx , deployment .ScalingStatus )
248
+ if diags .HasError () {
249
+ return diags
250
+ }
251
+ data .ScalingSpec , diags = ScalingSpecTypesObject (ctx , deployment .ScalingSpec )
252
+ if diags .HasError () {
253
+ return diags
264
254
}
265
255
266
256
return nil
@@ -351,23 +341,13 @@ func (data *DeploymentDataSource) ReadFromResponse(
351
341
data .SchedulerSize = types .StringPointerValue ((* string )(deployment .SchedulerSize ))
352
342
data .IsDevelopmentMode = types .BoolPointerValue (deployment .IsDevelopmentMode )
353
343
data .IsHighAvailability = types .BoolPointerValue (deployment .IsHighAvailability )
354
-
355
- // Currently, the scaling status and spec are only available in development mode
356
- // However, there is a bug in the API where the scaling status and spec are returned even if the deployment is not in development mode for updated deployments
357
- // This is a workaround to handle the bug until the API is fixed
358
- // Issue here: https://github.com/astronomer/astro/issues/21073
359
- if deployment .IsDevelopmentMode != nil && * deployment .IsDevelopmentMode {
360
- data .ScalingStatus , diags = ScalingStatusTypesObject (ctx , deployment .ScalingStatus )
361
- if diags .HasError () {
362
- return diags
363
- }
364
- data .ScalingSpec , diags = ScalingSpecTypesObject (ctx , deployment .ScalingSpec )
365
- if diags .HasError () {
366
- return diags
367
- }
368
- } else {
369
- data .ScalingStatus = types .ObjectNull (schemas .ScalingStatusAttributeTypes ())
370
- data .ScalingSpec = types .ObjectNull (schemas .ScalingSpecAttributeTypes ())
344
+ data .ScalingStatus , diags = ScalingStatusTypesObject (ctx , deployment .ScalingStatus )
345
+ if diags .HasError () {
346
+ return diags
347
+ }
348
+ data .ScalingSpec , diags = ScalingSpecTypesObject (ctx , deployment .ScalingSpec )
349
+ if diags .HasError () {
350
+ return diags
371
351
}
372
352
373
353
return nil
@@ -459,11 +439,11 @@ func WorkerQueueDataSourceTypesObject(
459
439
}
460
440
461
441
type DeploymentScalingSpec struct {
462
- HibernationSpec HibernationSpec `tfsdk:"hibernation_spec"`
442
+ HibernationSpec types. Object `tfsdk:"hibernation_spec"`
463
443
}
464
444
465
445
type DeploymentStatus struct {
466
- HibernationStatus HibernationStatus `tfsdk:"hibernation_status"`
446
+ HibernationStatus types. Object `tfsdk:"hibernation_status"`
467
447
}
468
448
469
449
type HibernationStatus struct {
@@ -474,8 +454,8 @@ type HibernationStatus struct {
474
454
}
475
455
476
456
type HibernationSpec struct {
477
- Override HibernationSpecOverride `tfsdk:"override"`
478
- Schedules [] HibernationSchedule `tfsdk:"schedules"`
457
+ Override types. Object `tfsdk:"override"`
458
+ Schedules types. Set `tfsdk:"schedules"`
479
459
}
480
460
481
461
type HibernationSpecOverride struct {
@@ -491,54 +471,108 @@ type HibernationSchedule struct {
491
471
WakeAtCron types.String `tfsdk:"wake_at_cron"`
492
472
}
493
473
474
+ func HibernationStatusTypesObject (
475
+ ctx context.Context ,
476
+ hibernationStatus * platform.DeploymentHibernationStatus ,
477
+ ) (types.Object , diag.Diagnostics ) {
478
+ if hibernationStatus == nil {
479
+ return types .ObjectNull (schemas .HibernationStatusAttributeTypes ()), nil
480
+ }
481
+
482
+ obj := HibernationStatus {
483
+ IsHibernating : types .BoolValue (hibernationStatus .IsHibernating ),
484
+ NextEventType : types .StringPointerValue ((* string )(hibernationStatus .NextEventType )),
485
+ NextEventAt : types .StringPointerValue (hibernationStatus .NextEventAt ),
486
+ Reason : types .StringPointerValue (hibernationStatus .Reason ),
487
+ }
488
+ return types .ObjectValueFrom (ctx , schemas .HibernationStatusAttributeTypes (), obj )
489
+ }
490
+
491
+ func HibernationOverrideTypesObject (
492
+ ctx context.Context ,
493
+ hibernationOverride * platform.DeploymentHibernationOverride ,
494
+ ) (types.Object , diag.Diagnostics ) {
495
+ if hibernationOverride == nil {
496
+ return types .ObjectNull (schemas .HibernationOverrideAttributeTypes ()), nil
497
+ }
498
+ obj := HibernationSpecOverride {
499
+ IsHibernating : types .BoolPointerValue (hibernationOverride .IsHibernating ),
500
+ IsActive : types .BoolPointerValue (hibernationOverride .IsActive ),
501
+ }
502
+ if hibernationOverride .OverrideUntil != nil {
503
+ obj .OverrideUntil = types .StringValue (hibernationOverride .OverrideUntil .Format (time .RFC3339 ))
504
+ }
505
+ return types .ObjectValueFrom (ctx , schemas .HibernationOverrideAttributeTypes (), obj )
506
+ }
507
+
508
+ func HibernationScheduleTypesObject (
509
+ ctx context.Context ,
510
+ schedule platform.DeploymentHibernationSchedule ,
511
+ ) (types.Object , diag.Diagnostics ) {
512
+ obj := HibernationSchedule {
513
+ Description : types .StringPointerValue (schedule .Description ),
514
+ HibernateAtCron : types .StringValue (schedule .HibernateAtCron ),
515
+ IsEnabled : types .BoolValue (schedule .IsEnabled ),
516
+ WakeAtCron : types .StringValue (schedule .WakeAtCron ),
517
+ }
518
+ return types .ObjectValueFrom (ctx , schemas .HibernationScheduleAttributeTypes (), obj )
519
+ }
520
+
521
+ func HibernationSpecTypesObject (
522
+ ctx context.Context ,
523
+ hibernationSpec * platform.DeploymentHibernationSpec ,
524
+ ) (types.Object , diag.Diagnostics ) {
525
+ if hibernationSpec == nil || (hibernationSpec .Override == nil && hibernationSpec .Schedules == nil ) {
526
+ return types .ObjectNull (schemas .HibernationSpecAttributeTypes ()), nil
527
+ }
528
+
529
+ override , diags := HibernationOverrideTypesObject (ctx , hibernationSpec .Override )
530
+ if diags .HasError () {
531
+ return types .ObjectNull (schemas .HibernationSpecAttributeTypes ()), diags
532
+ }
533
+ schedules , diags := utils .ObjectSet (ctx , hibernationSpec .Schedules , schemas .HibernationScheduleAttributeTypes (), HibernationScheduleTypesObject )
534
+ if diags .HasError () {
535
+ return types .ObjectNull (schemas .HibernationSpecAttributeTypes ()), diags
536
+ }
537
+ obj := HibernationSpec {
538
+ Override : override ,
539
+ Schedules : schedules ,
540
+ }
541
+ return types .ObjectValueFrom (ctx , schemas .HibernationSpecAttributeTypes (), obj )
542
+ }
543
+
494
544
func ScalingStatusTypesObject (
495
545
ctx context.Context ,
496
546
scalingStatus * platform.DeploymentScalingStatus ,
497
547
) (types.Object , diag.Diagnostics ) {
498
- if scalingStatus != nil && scalingStatus .HibernationStatus != nil {
499
- obj := DeploymentStatus {
500
- HibernationStatus : HibernationStatus {
501
- IsHibernating : types .BoolValue (scalingStatus .HibernationStatus .IsHibernating ),
502
- NextEventType : types .StringPointerValue ((* string )(scalingStatus .HibernationStatus .NextEventType )),
503
- NextEventAt : types .StringPointerValue (scalingStatus .HibernationStatus .NextEventAt ),
504
- Reason : types .StringPointerValue (scalingStatus .HibernationStatus .Reason ),
505
- },
506
- }
507
- return types .ObjectValueFrom (ctx , schemas .ScalingStatusAttributeTypes (), obj )
548
+ if scalingStatus == nil {
549
+ return types .ObjectNull (schemas .ScalingStatusAttributeTypes ()), nil
550
+ }
551
+
552
+ hibernationStatus , diags := HibernationStatusTypesObject (ctx , scalingStatus .HibernationStatus )
553
+ if diags .HasError () {
554
+ return types .ObjectNull (schemas .ScalingStatusAttributeTypes ()), diags
508
555
}
509
- return types .ObjectNull (schemas .ScalingStatusAttributeTypes ()), nil
556
+ obj := DeploymentStatus {
557
+ HibernationStatus : hibernationStatus ,
558
+ }
559
+ return types .ObjectValueFrom (ctx , schemas .ScalingStatusAttributeTypes (), obj )
510
560
}
511
561
512
562
func ScalingSpecTypesObject (
513
563
ctx context.Context ,
514
564
scalingSpec * platform.DeploymentScalingSpec ,
515
565
) (types.Object , diag.Diagnostics ) {
516
- if scalingSpec != nil && scalingSpec .HibernationSpec != nil && (scalingSpec .HibernationSpec .Override != nil || scalingSpec .HibernationSpec .Schedules != nil ) {
517
- obj := DeploymentScalingSpec {
518
- HibernationSpec : HibernationSpec {},
519
- }
520
- if scalingSpec .HibernationSpec .Override != nil {
521
- obj .HibernationSpec .Override = HibernationSpecOverride {
522
- IsHibernating : types .BoolPointerValue (scalingSpec .HibernationSpec .Override .IsHibernating ),
523
- IsActive : types .BoolPointerValue (scalingSpec .HibernationSpec .Override .IsActive ),
524
- }
525
- if scalingSpec .HibernationSpec .Override .OverrideUntil != nil {
526
- obj .HibernationSpec .Override .OverrideUntil = types .StringValue (scalingSpec .HibernationSpec .Override .OverrideUntil .Format (time .RFC3339 ))
527
- }
528
- }
529
- if scalingSpec .HibernationSpec .Schedules != nil {
530
- schedules := make ([]HibernationSchedule , 0 , len (* scalingSpec .HibernationSpec .Schedules ))
531
- for _ , schedule := range * scalingSpec .HibernationSpec .Schedules {
532
- schedules = append (schedules , HibernationSchedule {
533
- Description : types .StringPointerValue (schedule .Description ),
534
- HibernateAtCron : types .StringValue (schedule .HibernateAtCron ),
535
- IsEnabled : types .BoolValue (schedule .IsEnabled ),
536
- WakeAtCron : types .StringValue (schedule .WakeAtCron ),
537
- })
538
- }
539
- obj .HibernationSpec .Schedules = schedules
540
- }
541
- return types .ObjectValueFrom (ctx , schemas .ScalingSpecAttributeTypes (), obj )
566
+ if scalingSpec == nil {
567
+ return types .ObjectNull (schemas .ScalingSpecAttributeTypes ()), nil
568
+ }
569
+
570
+ hibernationSpec , diags := HibernationSpecTypesObject (ctx , scalingSpec .HibernationSpec )
571
+ if diags .HasError () {
572
+ return types .ObjectNull (schemas .ScalingSpecAttributeTypes ()), diags
573
+ }
574
+ obj := DeploymentScalingSpec {
575
+ HibernationSpec : hibernationSpec ,
542
576
}
543
- return types .ObjectNull ( schemas .ScalingSpecAttributeTypes ()), nil
577
+ return types .ObjectValueFrom ( ctx , schemas .ScalingSpecAttributeTypes (), obj )
544
578
}
0 commit comments