@@ -17,11 +17,9 @@ import (
17
17
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
18
18
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
19
19
"github.com/hashicorp/terraform-plugin-framework/types"
20
- "github.com/hashicorp/terraform-plugin-framework/types/basetypes"
21
20
22
21
"github.com/honeycombio/terraform-provider-honeycombio/client"
23
22
"github.com/honeycombio/terraform-provider-honeycombio/internal/helper"
24
- "github.com/honeycombio/terraform-provider-honeycombio/internal/helper/validation"
25
23
"github.com/honeycombio/terraform-provider-honeycombio/internal/models"
26
24
)
27
25
@@ -101,9 +99,6 @@ func (*flexibleBoardResource) Schema(_ context.Context, _ resource.SchemaRequest
101
99
Blocks : map [string ]schema.Block {
102
100
"panel" : schema.ListNestedBlock {
103
101
Description : "List of panels to render on the board." ,
104
- Validators : []validator.List {
105
- validation .RequireConsistentPanelPositions (),
106
- },
107
102
NestedObject : schema.NestedBlockObject {
108
103
Attributes : map [string ]schema.Attribute {
109
104
"type" : schema.StringAttribute {
@@ -125,6 +120,7 @@ func (*flexibleBoardResource) Schema(_ context.Context, _ resource.SchemaRequest
125
120
Description : "The X coordinate of the panel." ,
126
121
Validators : []validator.Int64 {
127
122
int64validator .AtLeast (0 ),
123
+ int64validator .AlsoRequires (path .MatchRelative ().AtParent ().AtName ("y_coordinate" )),
128
124
},
129
125
},
130
126
"y_coordinate" : schema.Int64Attribute {
@@ -134,6 +130,7 @@ func (*flexibleBoardResource) Schema(_ context.Context, _ resource.SchemaRequest
134
130
Description : "The Y coordinate of the panel." ,
135
131
Validators : []validator.Int64 {
136
132
int64validator .AtLeast (0 ),
133
+ int64validator .AlsoRequires (path .MatchRelative ().AtParent ().AtName ("x_coordinate" )),
137
134
},
138
135
},
139
136
"height" : schema.Int64Attribute {
@@ -155,9 +152,6 @@ func (*flexibleBoardResource) Schema(_ context.Context, _ resource.SchemaRequest
155
152
},
156
153
},
157
154
},
158
- Validators : []validator.Object {
159
- validation .RequireBothCoordinates (),
160
- },
161
155
},
162
156
"slo_panel" : schema.ListNestedBlock {
163
157
Description : "A Service Level Objective(SLO) panel to be displayed on the Board." ,
@@ -580,26 +574,31 @@ func expandBoardPanels(
580
574
// This is a workaround for the limitations of the terraform v5 protocol.
581
575
func expandPanelPosition (
582
576
ctx context.Context ,
583
- panelPosition types.Object ,
577
+ panelPosition types.List ,
584
578
diags * diag.Diagnostics ,
585
579
) client.BoardPanelPosition {
586
580
if panelPosition .IsNull () || panelPosition .IsUnknown () {
587
581
return client.BoardPanelPosition {
588
- X : - 1 ,
589
- Y : - 1 ,
590
- Width : - 1 ,
591
- Height : - 1 ,
582
+ X : - 1 ,
583
+ Y : - 1 ,
592
584
}
593
585
}
594
586
595
- var position models.BoardPanelPositionModel
596
- diags .Append (panelPosition .As (ctx , & position , basetypes.ObjectAsOptions {})... )
587
+ var position []models.BoardPanelPositionModel
588
+ diags .Append (panelPosition .ElementsAs (ctx , & position , false )... )
589
+
590
+ if len (position ) == 0 {
591
+ return client.BoardPanelPosition {
592
+ X : - 1 ,
593
+ Y : - 1 ,
594
+ }
595
+ }
597
596
598
597
return client.BoardPanelPosition {
599
- X : int (position .XCoordinate .ValueInt64 ()),
600
- Y : int (position .YCoordinate .ValueInt64 ()),
601
- Height : int (position .Height .ValueInt64 ()),
602
- Width : int (position .Width .ValueInt64 ()),
598
+ X : int (position [ 0 ] .XCoordinate .ValueInt64 ()),
599
+ Y : int (position [ 0 ] .YCoordinate .ValueInt64 ()),
600
+ Height : int (position [ 0 ] .Height .ValueInt64 ()),
601
+ Width : int (position [ 0 ] .Width .ValueInt64 ()),
603
602
}
604
603
}
605
604
@@ -717,38 +716,33 @@ func flattenBoardPanel(
717
716
}
718
717
719
718
func flattenBoardPanelPosition (
720
- _ context.Context ,
719
+ ctx context.Context ,
721
720
position client.BoardPanelPosition ,
722
721
diags * diag.Diagnostics ,
723
722
statePosition client.BoardPanelPosition ,
724
- ) types.Object {
723
+ ) types.List {
725
724
// we use negative numbers to indicate that the panel position was never set. We use this to not write to state when panel position is not set.
726
725
// This is a workaround for the various limitations that terraform v5 protocol presents.
727
726
// Without this workaround, whenever the API generates a default position, terraform would complain about a schema mismatch between config and applied results.
728
- if statePosition .Height == - 1 && statePosition .Width == - 1 && statePosition .X == - 1 && statePosition .Y == - 1 {
729
- return types .ObjectNull (models .BoardPanelPositionModelAttrType )
730
- }
731
- x := position .X
732
- y := position .Y
733
- width := position .Width
734
- height := position .Height
735
-
736
- attrs := map [string ]attr.Value {}
737
- if statePosition .X != - 1 && statePosition .Y != - 1 {
738
- attrs ["x_coordinate" ] = types .Int64Value (int64 (x ))
739
- attrs ["y_coordinate" ] = types .Int64Value (int64 (y ))
740
- }
741
- if statePosition .Width != - 1 {
742
- attrs ["width" ] = types .Int64Value (int64 (width ))
743
- }
744
- if statePosition .Height != - 1 {
745
- attrs ["height" ] = types .Int64Value (int64 (height ))
746
- }
727
+ if statePosition .Height == 0 && statePosition .Width == 0 && statePosition .X == - 1 && statePosition .Y == - 1 {
728
+ return types .ListNull (types.ObjectType {AttrTypes : models .BoardPanelPositionModelAttrType })
729
+ }
730
+ obj , d := types .ObjectValue (models .BoardPanelPositionModelAttrType , map [string ]attr.Value {
731
+ "x_coordinate" : types .Int64Value (int64 (position .X )),
732
+ "y_coordinate" : types .Int64Value (int64 (position .Y )),
733
+ "height" : types .Int64Value (int64 (position .Height )),
734
+ "width" : types .Int64Value (int64 (position .Width )),
735
+ })
736
+ diags .Append (d ... )
747
737
748
- obj , d := types .ObjectValue (models .BoardPanelPositionModelAttrType , attrs )
738
+ result , d := types .ListValueFrom (
739
+ ctx ,
740
+ types.ObjectType {AttrTypes : models .BoardPanelPositionModelAttrType },
741
+ []attr.Value {obj },
742
+ )
749
743
diags .Append (d ... )
750
744
751
- return obj
745
+ return result
752
746
}
753
747
754
748
func flattenBoardQueryPanel (
@@ -883,12 +877,6 @@ func removeDefaultNegativeNumbers(panels []client.BoardPanel) []client.BoardPane
883
877
resp [i ].PanelPosition .X = 0
884
878
resp [i ].PanelPosition .Y = 0
885
879
}
886
- if resp [i ].PanelPosition .Width == - 1 {
887
- resp [i ].PanelPosition .Width = 0
888
- }
889
- if resp [i ].PanelPosition .Height == - 1 {
890
- resp [i ].PanelPosition .Height = 0
891
- }
892
880
}
893
881
894
882
return resp
0 commit comments