Skip to content

Commit 24ec006

Browse files
remove layout_generation field exposure
1 parent 9d93585 commit 24ec006

File tree

5 files changed

+53
-66
lines changed

5 files changed

+53
-66
lines changed

client/board.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,10 @@ type BoardPanel struct {
8484
SLOPanel *BoardSLOPanel `json:"slo_panel,omitempty"`
8585
}
8686

87+
func (b *BoardPanel) IsBlank() bool {
88+
return b.PanelPosition.X == 0 && b.PanelPosition.Y == 0 && b.PanelPosition.Height == 0 && b.PanelPosition.Width == 0
89+
}
90+
8791
type BoardPanelType string
8892

8993
const (

docs/resources/flexible_board.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,6 @@ resource "honeycombio_flexible_board" "overview" {
8787
project = "secret"
8888
}
8989
90-
layout_generation = "auto"
91-
9290
panel {
9391
type = "query"
9492
@@ -125,7 +123,6 @@ The following arguments are supported for flexible boards:
125123
- `description` - (Optional) Description of the board. Supports Markdown.
126124
- `panel` - (Optional) zero or more configurations blocks
127125
- `tags` - (Optional) Map of up to ten (10) tags to assign to the resource.
128-
- `layout_generation` - (Optional) Determines how the board layout is generated. When set to `manual`, the layout depends on positions set by user. When `auto` the layout is autogenerated. Defaults to `manual`.
129126

130127
Each board configuration may have zero or more `panel` blocks which accept the following arguments:
131128

internal/models/flexible_board.go

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,12 @@ import (
66
)
77

88
type FlexibleBoardResourceModel struct {
9-
ID types.String `tfsdk:"id"`
10-
Name types.String `tfsdk:"name"`
11-
Description types.String `tfsdk:"description"`
12-
URL types.String `tfsdk:"board_url"`
13-
Panels types.List `tfsdk:"panel"`
14-
Tags types.Map `tfsdk:"tags"`
15-
LayoutGeneration types.String `tfsdk:"layout_generation"`
9+
ID types.String `tfsdk:"id"`
10+
Name types.String `tfsdk:"name"`
11+
Description types.String `tfsdk:"description"`
12+
URL types.String `tfsdk:"board_url"`
13+
Panels types.List `tfsdk:"panel"`
14+
Tags types.Map `tfsdk:"tags"`
1615
}
1716

1817
type BoardPanelModel struct {
@@ -118,21 +117,9 @@ var ChartSettingsModelAttrType = map[string]attr.Type{
118117
// This is the old version of the BoardPanelModel
119118
// It was used to store the board panel in a list of objects
120119
// This is no longer used, but is kept here for backwards compatibility
121-
type BoardPanelModelV0 struct {
120+
type FlexibleBoardPanelModelV0 struct {
122121
PanelType types.String `tfsdk:"type"`
123122
Position types.List `tfsdk:"position"`
124123
QueryPanel types.List `tfsdk:"query_panel"`
125124
SLOPanel types.List `tfsdk:"slo_panel"`
126125
}
127-
128-
// This is the old version of the FlexibleBoardResourceModel
129-
// It was used without layout_generation field.
130-
// This is no longer used, but is kept here for backwards compatibility
131-
type FlexibleBoardResourceModelV0 struct {
132-
ID types.String `tfsdk:"id"`
133-
Name types.String `tfsdk:"name"`
134-
Description types.String `tfsdk:"description"`
135-
URL types.String `tfsdk:"board_url"`
136-
Panels types.List `tfsdk:"panel"`
137-
Tags types.Map `tfsdk:"tags"`
138-
}

internal/provider/flexible_board_resource.go

Lines changed: 42 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -99,16 +99,6 @@ func (*flexibleBoardResource) Schema(_ context.Context, _ resource.SchemaRequest
9999
stringplanmodifier.UseStateForUnknown(),
100100
},
101101
},
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-
},
112102
"tags": tagsSchema(),
113103
},
114104
Blocks: map[string]schema.Block{
@@ -527,7 +517,7 @@ func (*flexibleBoardResource) UpgradeState(ctx context.Context) map[int64]resour
527517
},
528518
},
529519
StateUpgrader: func(ctx context.Context, req resource.UpgradeStateRequest, resp *resource.UpgradeStateResponse) {
530-
var oldState models.FlexibleBoardResourceModelV0
520+
var oldState models.FlexibleBoardResourceModel
531521
resp.Diagnostics.Append(req.State.Get(ctx, &oldState)...)
532522
if resp.Diagnostics.HasError() {
533523
return
@@ -538,7 +528,7 @@ func (*flexibleBoardResource) UpgradeState(ctx context.Context) map[int64]resour
538528
}
539529

540530
// convert the old state to the new state
541-
var statePanels []models.BoardPanelModelV0
531+
var statePanels []models.FlexibleBoardPanelModelV0
542532
resp.Diagnostics.Append(oldState.Panels.ElementsAs(ctx, &statePanels, false)...)
543533
if resp.Diagnostics.HasError() {
544534
return
@@ -559,16 +549,20 @@ func (*flexibleBoardResource) UpgradeState(ctx context.Context) map[int64]resour
559549
return
560550
}
561551

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
567560

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...)
570563

571-
upgradedPanel.Position = obj
564+
upgradedPanel.Position = obj
565+
}
572566
} else {
573567
upgradedPanel.Position = types.ObjectNull(models.BoardPanelPositionModelAttrType)
574568
}
@@ -583,13 +577,12 @@ func (*flexibleBoardResource) UpgradeState(ctx context.Context) map[int64]resour
583577
resp.Diagnostics.Append(diags...)
584578

585579
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,
593586
}
594587
resp.Diagnostics.Append(resp.State.Set(ctx, newState)...)
595588
},
@@ -611,13 +604,14 @@ func (r *flexibleBoardResource) Create(ctx context.Context, req resource.CreateR
611604
}
612605

613606
panelFromConfig := expandBoardPanels(ctx, plan.Panels, &resp.Diagnostics)
607+
finalPanels, layoutGeneration := setAPIDefaultsAndDetermineLayoutGeneration(panelFromConfig)
614608
createRequest := &client.Board{
615609
Name: plan.Name.ValueString(),
616610
Description: plan.Description.ValueString(),
617611
BoardType: client.BoardTypeFlexible,
618-
Panels: removeDefaultNegativeNumbers(panelFromConfig),
612+
Panels: finalPanels,
619613
Tags: planTags,
620-
LayoutGeneration: client.LayoutGeneration(plan.LayoutGeneration.ValueString()),
614+
LayoutGeneration: layoutGeneration,
621615
}
622616

623617
if resp.Diagnostics.HasError() {
@@ -634,7 +628,7 @@ func (r *flexibleBoardResource) Create(ctx context.Context, req resource.CreateR
634628
state.Name = types.StringValue(board.Name)
635629
state.Description = types.StringValue(board.Description)
636630
state.URL = types.StringValue(board.Links.BoardURL)
637-
state.LayoutGeneration = plan.LayoutGeneration
631+
// state.LayoutGeneration = plan.LayoutGeneration
638632

639633
if len(board.Panels) == 0 {
640634
state.Panels = types.ListNull(types.ObjectType{AttrTypes: models.BoardPanelModelAttrType})
@@ -767,14 +761,15 @@ func (r *flexibleBoardResource) Update(ctx context.Context, req resource.UpdateR
767761
}
768762

769763
panelConfig := expandBoardPanels(ctx, plan.Panels, &resp.Diagnostics)
764+
finalPanels, layoutGeneration := setAPIDefaultsAndDetermineLayoutGeneration(panelConfig)
770765
updateRequest := &client.Board{
771766
ID: plan.ID.ValueString(),
772767
Name: plan.Name.ValueString(),
773768
Description: plan.Description.ValueString(),
774769
BoardType: client.BoardTypeFlexible,
775-
Panels: removeDefaultNegativeNumbers(panelConfig),
770+
Panels: finalPanels,
776771
Tags: planTags,
777-
LayoutGeneration: client.LayoutGeneration(plan.LayoutGeneration.ValueString()),
772+
LayoutGeneration: layoutGeneration,
778773
}
779774
if resp.Diagnostics.HasError() {
780775
return
@@ -790,7 +785,6 @@ func (r *flexibleBoardResource) Update(ctx context.Context, req resource.UpdateR
790785
state.Name = types.StringValue(board.Name)
791786
state.Description = types.StringValue(board.Description)
792787
state.URL = types.StringValue(board.Links.BoardURL)
793-
state.LayoutGeneration = plan.LayoutGeneration
794788

795789
if len(board.Panels) == 0 {
796790
state.Panels = types.ListNull(types.ObjectType{AttrTypes: models.BoardPanelModelAttrType})
@@ -1179,17 +1173,20 @@ func flattenBoardSloPanel(
11791173
return result
11801174
}
11811175

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.
11831177
// This is a workaround for the various limitations that terraform v5 protocol presents.
11841178
// The API will set default panel positions based on panel type. We decided not to write
11851179
// 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) {
11871182
if len(panels) == 0 {
1188-
return panels
1183+
return panels, client.LayoutGenerationAuto
11891184
}
11901185
resp := make([]client.BoardPanel, len(panels))
11911186
copy(resp, panels)
11921187

1188+
blankCount := 0
1189+
11931190
for i := range resp {
11941191
if resp[i].PanelPosition.X == -1 && resp[i].PanelPosition.Y == -1 {
11951192
resp[i].PanelPosition.X = 0
@@ -1201,7 +1198,15 @@ func removeDefaultNegativeNumbers(panels []client.BoardPanel) []client.BoardPane
12011198
if resp[i].PanelPosition.Height == -1 {
12021199
resp[i].PanelPosition.Height = 0
12031200
}
1201+
1202+
if resp[i].IsBlank() {
1203+
blankCount++
1204+
}
1205+
}
1206+
1207+
if blankCount == len(resp) {
1208+
return resp, client.LayoutGenerationAuto
12041209
}
12051210

1206-
return resp
1211+
return resp, client.LayoutGenerationManual
12071212
}

internal/provider/flexible_board_resource_test.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ func TestAccHoneycombioFlexibleBoard(t *testing.T) {
7676
resource.TestCheckResourceAttr("honeycombio_flexible_board.test", "panel.1.position.width", "6"),
7777
resource.TestCheckResourceAttr("honeycombio_flexible_board.test", "panel.1.position.x_coordinate", "0"),
7878
resource.TestCheckResourceAttr("honeycombio_flexible_board.test", "panel.1.position.y_coordinate", "3"),
79-
resource.TestCheckResourceAttr("honeycombio_flexible_board.test", "layout_generation", "manual"),
8079
),
8180
},
8281
// remove board's panels, add tags
@@ -99,7 +98,6 @@ resource "honeycombio_flexible_board" "test" {
9998
resource.TestCheckResourceAttr("honeycombio_flexible_board.test", "tags.%", "2"),
10099
resource.TestCheckResourceAttr("honeycombio_flexible_board.test", "tags.team", "blue"),
101100
resource.TestCheckResourceAttr("honeycombio_flexible_board.test", "tags.env", "dev"),
102-
resource.TestCheckResourceAttr("honeycombio_flexible_board.test", "layout_generation", "manual"),
103101
),
104102
},
105103
// now add a query panel with no position (auto generated positions), update tags, and ensure the board is updated
@@ -129,7 +127,6 @@ resource "honeycombio_flexible_board" "test" {
129127
tags = {
130128
team = "green"
131129
}
132-
layout_generation = "auto"
133130
panel {
134131
type = "query"
135132
query_panel {
@@ -163,7 +160,6 @@ resource "honeycombio_flexible_board" "test" {
163160
resource.TestCheckNoResourceAttr("honeycombio_flexible_board.test", "panel.0.position.width"),
164161
resource.TestCheckNoResourceAttr("honeycombio_flexible_board.test", "panel.0.position.x_coordinate"),
165162
resource.TestCheckNoResourceAttr("honeycombio_flexible_board.test", "panel.0.position.y_coordinate"),
166-
resource.TestCheckResourceAttr("honeycombio_flexible_board.test", "layout_generation", "auto"),
167163
),
168164
},
169165
// now add an SLO panel, remove chart settings from the query panel, remove tags and update from generated positions to provided positions
@@ -244,7 +240,6 @@ resource "honeycombio_flexible_board" "test" {
244240
resource.TestCheckResourceAttr("honeycombio_flexible_board.test", "panel.1.position.x_coordinate", "3"),
245241
resource.TestCheckResourceAttr("honeycombio_flexible_board.test", "panel.1.position.y_coordinate", "0"),
246242
resource.TestCheckResourceAttr("honeycombio_flexible_board.test", "tags.%", "0"),
247-
resource.TestCheckResourceAttr("honeycombio_flexible_board.test", "layout_generation", "manual"),
248243
),
249244
},
250245
// re-order the panels and remove viz settings for the query panel
@@ -318,7 +313,6 @@ resource "honeycombio_flexible_board" "test" {
318313
// ensure x and y coordinates are dynamically generated when only height and width are provided
319314
resource.TestCheckResourceAttrSet("honeycombio_flexible_board.test", "panel.1.position.x_coordinate"),
320315
resource.TestCheckResourceAttrSet("honeycombio_flexible_board.test", "panel.1.position.y_coordinate"),
321-
resource.TestCheckResourceAttr("honeycombio_flexible_board.test", "layout_generation", "manual"),
322316
),
323317
},
324318
},

0 commit comments

Comments
 (0)