|
| 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