Skip to content

Commit 7e47d3c

Browse files
Fix Fleet Management pipeline unordered matchers (#2079)
1 parent 33580f1 commit 7e47d3c

16 files changed

+529
-629
lines changed

internal/resources/fleetmanagement/generic_list_type.go

-81
This file was deleted.

internal/resources/fleetmanagement/generic_list_type_test.go

-64
This file was deleted.

internal/resources/fleetmanagement/generic_list_value.go

-80
This file was deleted.

internal/resources/fleetmanagement/generic_list_value_test.go

-66
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
package fleetmanagement
2+
3+
import (
4+
"context"
5+
"fmt"
6+
7+
"github.com/hashicorp/terraform-plugin-framework/attr"
8+
"github.com/hashicorp/terraform-plugin-framework/diag"
9+
"github.com/hashicorp/terraform-plugin-framework/types"
10+
"github.com/hashicorp/terraform-plugin-framework/types/basetypes"
11+
"github.com/hashicorp/terraform-plugin-go/tftypes"
12+
)
13+
14+
var (
15+
_ basetypes.ListTypable = listOfPrometheusMatcherType{}
16+
)
17+
18+
var (
19+
ListOfPrometheusMatcherType = listOfPrometheusMatcherType{
20+
ListType: basetypes.ListType{
21+
ElemType: types.StringType,
22+
},
23+
}
24+
)
25+
26+
type listOfPrometheusMatcherType struct {
27+
basetypes.ListType
28+
}
29+
30+
func (t listOfPrometheusMatcherType) Equal(o attr.Type) bool {
31+
other, ok := o.(listOfPrometheusMatcherType)
32+
if !ok {
33+
return false
34+
}
35+
36+
return t.ListType.Equal(other.ListType)
37+
}
38+
39+
func (t listOfPrometheusMatcherType) String() string {
40+
return "ListOfPrometheusMatcherType"
41+
}
42+
43+
func (t listOfPrometheusMatcherType) ValueFromList(ctx context.Context, in basetypes.ListValue) (basetypes.ListValuable, diag.Diagnostics) {
44+
if in.IsNull() {
45+
return NewListOfPrometheusMatcherValueNull(), nil
46+
}
47+
48+
if in.IsUnknown() {
49+
return NewListOfPrometheusMatcherValueUnknown(), nil
50+
}
51+
52+
return NewListOfPrometheusMatcherValue(in.Elements())
53+
}
54+
55+
func (t listOfPrometheusMatcherType) ValueFromTerraform(ctx context.Context, in tftypes.Value) (attr.Value, error) {
56+
attrValue, err := t.ListType.ValueFromTerraform(ctx, in)
57+
if err != nil {
58+
return nil, err
59+
}
60+
61+
listValue, ok := attrValue.(basetypes.ListValue)
62+
if !ok {
63+
return nil, fmt.Errorf("unexpected value type of %T", attrValue)
64+
}
65+
66+
listValuable, diags := t.ValueFromList(ctx, listValue)
67+
if diags.HasError() {
68+
return nil, fmt.Errorf("unexpected error converting ListValue to ListValuable: %v", diags)
69+
}
70+
71+
return listValuable, nil
72+
}
73+
74+
func (t listOfPrometheusMatcherType) ValueType(ctx context.Context) attr.Value {
75+
return ListOfPrometheusMatcherValue{}
76+
}

0 commit comments

Comments
 (0)