@@ -99,16 +99,6 @@ func (*flexibleBoardResource) Schema(_ context.Context, _ resource.SchemaRequest
99
99
stringplanmodifier .UseStateForUnknown (),
100
100
},
101
101
},
102
- "layout_generation" : schema.StringAttribute {
103
- Computed : true ,
104
- Required : false ,
105
- Optional : true ,
106
- Default : stringdefault .StaticString ("manual" ),
107
- Description : "Allows the board layout to be generated based on positions when set to 'manual'. When set to 'auto', the board layout will be auto generated." ,
108
- PlanModifiers : []planmodifier.String {
109
- stringplanmodifier .UseStateForUnknown (),
110
- },
111
- },
112
102
"tags" : tagsSchema (),
113
103
},
114
104
Blocks : map [string ]schema.Block {
@@ -527,7 +517,7 @@ func (*flexibleBoardResource) UpgradeState(ctx context.Context) map[int64]resour
527
517
},
528
518
},
529
519
StateUpgrader : func (ctx context.Context , req resource.UpgradeStateRequest , resp * resource.UpgradeStateResponse ) {
530
- var oldState models.FlexibleBoardResourceModelV0
520
+ var oldState models.FlexibleBoardResourceModel
531
521
resp .Diagnostics .Append (req .State .Get (ctx , & oldState )... )
532
522
if resp .Diagnostics .HasError () {
533
523
return
@@ -538,7 +528,7 @@ func (*flexibleBoardResource) UpgradeState(ctx context.Context) map[int64]resour
538
528
}
539
529
540
530
// convert the old state to the new state
541
- var statePanels []models.BoardPanelModelV0
531
+ var statePanels []models.FlexibleBoardPanelModelV0
542
532
resp .Diagnostics .Append (oldState .Panels .ElementsAs (ctx , & statePanels , false )... )
543
533
if resp .Diagnostics .HasError () {
544
534
return
@@ -559,16 +549,20 @@ func (*flexibleBoardResource) UpgradeState(ctx context.Context) map[int64]resour
559
549
return
560
550
}
561
551
562
- attrs := map [string ]attr.Value {}
563
- attrs ["x_coordinate" ] = oldStylePositions [0 ].XCoordinate
564
- attrs ["y_coordinate" ] = oldStylePositions [0 ].YCoordinate
565
- attrs ["height" ] = oldStylePositions [0 ].Height
566
- attrs ["width" ] = oldStylePositions [0 ].Width
552
+ if len (oldStylePositions ) == 0 {
553
+ upgradedPanel .Position = types .ObjectNull (models .BoardPanelPositionModelAttrType )
554
+ } else {
555
+ attrs := map [string ]attr.Value {}
556
+ attrs ["x_coordinate" ] = oldStylePositions [0 ].XCoordinate
557
+ attrs ["y_coordinate" ] = oldStylePositions [0 ].YCoordinate
558
+ attrs ["height" ] = oldStylePositions [0 ].Height
559
+ attrs ["width" ] = oldStylePositions [0 ].Width
567
560
568
- obj , d := types .ObjectValue (models .BoardPanelPositionModelAttrType , attrs )
569
- resp .Diagnostics .Append (d ... )
561
+ obj , d := types .ObjectValue (models .BoardPanelPositionModelAttrType , attrs )
562
+ resp .Diagnostics .Append (d ... )
570
563
571
- upgradedPanel .Position = obj
564
+ upgradedPanel .Position = obj
565
+ }
572
566
} else {
573
567
upgradedPanel .Position = types .ObjectNull (models .BoardPanelPositionModelAttrType )
574
568
}
@@ -583,13 +577,12 @@ func (*flexibleBoardResource) UpgradeState(ctx context.Context) map[int64]resour
583
577
resp .Diagnostics .Append (diags ... )
584
578
585
579
newState := models.FlexibleBoardResourceModel {
586
- ID : oldState .ID ,
587
- Name : oldState .Name ,
588
- Description : oldState .Description ,
589
- URL : oldState .URL ,
590
- Panels : finalPanels ,
591
- Tags : oldState .Tags ,
592
- LayoutGeneration : types .StringValue ("manual" ),
580
+ ID : oldState .ID ,
581
+ Name : oldState .Name ,
582
+ Description : oldState .Description ,
583
+ URL : oldState .URL ,
584
+ Panels : finalPanels ,
585
+ Tags : oldState .Tags ,
593
586
}
594
587
resp .Diagnostics .Append (resp .State .Set (ctx , newState )... )
595
588
},
@@ -611,13 +604,14 @@ func (r *flexibleBoardResource) Create(ctx context.Context, req resource.CreateR
611
604
}
612
605
613
606
panelFromConfig := expandBoardPanels (ctx , plan .Panels , & resp .Diagnostics )
607
+ finalPanels , layoutGeneration := setAPIDefaultsAndDetermineLayoutGeneration (panelFromConfig )
614
608
createRequest := & client.Board {
615
609
Name : plan .Name .ValueString (),
616
610
Description : plan .Description .ValueString (),
617
611
BoardType : client .BoardTypeFlexible ,
618
- Panels : removeDefaultNegativeNumbers ( panelFromConfig ) ,
612
+ Panels : finalPanels ,
619
613
Tags : planTags ,
620
- LayoutGeneration : client . LayoutGeneration ( plan . LayoutGeneration . ValueString ()) ,
614
+ LayoutGeneration : layoutGeneration ,
621
615
}
622
616
623
617
if resp .Diagnostics .HasError () {
@@ -634,7 +628,7 @@ func (r *flexibleBoardResource) Create(ctx context.Context, req resource.CreateR
634
628
state .Name = types .StringValue (board .Name )
635
629
state .Description = types .StringValue (board .Description )
636
630
state .URL = types .StringValue (board .Links .BoardURL )
637
- state .LayoutGeneration = plan .LayoutGeneration
631
+ // state.LayoutGeneration = plan.LayoutGeneration
638
632
639
633
if len (board .Panels ) == 0 {
640
634
state .Panels = types .ListNull (types.ObjectType {AttrTypes : models .BoardPanelModelAttrType })
@@ -767,14 +761,15 @@ func (r *flexibleBoardResource) Update(ctx context.Context, req resource.UpdateR
767
761
}
768
762
769
763
panelConfig := expandBoardPanels (ctx , plan .Panels , & resp .Diagnostics )
764
+ finalPanels , layoutGeneration := setAPIDefaultsAndDetermineLayoutGeneration (panelConfig )
770
765
updateRequest := & client.Board {
771
766
ID : plan .ID .ValueString (),
772
767
Name : plan .Name .ValueString (),
773
768
Description : plan .Description .ValueString (),
774
769
BoardType : client .BoardTypeFlexible ,
775
- Panels : removeDefaultNegativeNumbers ( panelConfig ) ,
770
+ Panels : finalPanels ,
776
771
Tags : planTags ,
777
- LayoutGeneration : client . LayoutGeneration ( plan . LayoutGeneration . ValueString ()) ,
772
+ LayoutGeneration : layoutGeneration ,
778
773
}
779
774
if resp .Diagnostics .HasError () {
780
775
return
@@ -790,7 +785,6 @@ func (r *flexibleBoardResource) Update(ctx context.Context, req resource.UpdateR
790
785
state .Name = types .StringValue (board .Name )
791
786
state .Description = types .StringValue (board .Description )
792
787
state .URL = types .StringValue (board .Links .BoardURL )
793
- state .LayoutGeneration = plan .LayoutGeneration
794
788
795
789
if len (board .Panels ) == 0 {
796
790
state .Panels = types .ListNull (types.ObjectType {AttrTypes : models .BoardPanelModelAttrType })
@@ -1179,17 +1173,20 @@ func flattenBoardSloPanel(
1179
1173
return result
1180
1174
}
1181
1175
1182
- // we use negative numbers to indicate that the panel position was never set.
1176
+ // setAPIDefaultsAndDetermineLayoutGeneration removes negative numbers. we use negative numbers to indicate that the panel position was never set.
1183
1177
// This is a workaround for the various limitations that terraform v5 protocol presents.
1184
1178
// The API will set default panel positions based on panel type. We decided not to write
1185
1179
// position to state when the panel position is not set.
1186
- func removeDefaultNegativeNumbers (panels []client.BoardPanel ) []client.BoardPanel {
1180
+ // It returns layout generation "auto" if all panels have no positions.
1181
+ func setAPIDefaultsAndDetermineLayoutGeneration (panels []client.BoardPanel ) ([]client.BoardPanel , client.LayoutGeneration ) {
1187
1182
if len (panels ) == 0 {
1188
- return panels
1183
+ return panels , client . LayoutGenerationAuto
1189
1184
}
1190
1185
resp := make ([]client.BoardPanel , len (panels ))
1191
1186
copy (resp , panels )
1192
1187
1188
+ blankCount := 0
1189
+
1193
1190
for i := range resp {
1194
1191
if resp [i ].PanelPosition .X == - 1 && resp [i ].PanelPosition .Y == - 1 {
1195
1192
resp [i ].PanelPosition .X = 0
@@ -1201,7 +1198,15 @@ func removeDefaultNegativeNumbers(panels []client.BoardPanel) []client.BoardPane
1201
1198
if resp [i ].PanelPosition .Height == - 1 {
1202
1199
resp [i ].PanelPosition .Height = 0
1203
1200
}
1201
+
1202
+ if resp [i ].IsBlank () {
1203
+ blankCount ++
1204
+ }
1205
+ }
1206
+
1207
+ if blankCount == len (resp ) {
1208
+ return resp , client .LayoutGenerationAuto
1204
1209
}
1205
1210
1206
- return resp
1211
+ return resp , client . LayoutGenerationManual
1207
1212
}
0 commit comments