diff --git a/.changes/unreleased/BUG FIXES-20230706-172842.yaml b/.changes/unreleased/BUG FIXES-20230706-172842.yaml new file mode 100644 index 0000000..28e0f99 --- /dev/null +++ b/.changes/unreleased/BUG FIXES-20230706-172842.yaml @@ -0,0 +1,6 @@ +kind: BUG FIXES +body: 'datasource/timeouts: Prevented `Value Conversion Error` with terraform-plugin-framework + 1.3.0 and later' +time: 2023-07-06T17:28:42.871268-04:00 +custom: + Issue: "72" diff --git a/.changes/unreleased/BUG FIXES-20230706-172907.yaml b/.changes/unreleased/BUG FIXES-20230706-172907.yaml new file mode 100644 index 0000000..0232d36 --- /dev/null +++ b/.changes/unreleased/BUG FIXES-20230706-172907.yaml @@ -0,0 +1,6 @@ +kind: BUG FIXES +body: 'resource/timeouts: Prevented `Value Conversion Error` with terraform-plugin-framework + 1.3.0 and later' +time: 2023-07-06T17:29:07.283097-04:00 +custom: + Issue: "72" diff --git a/datasource/timeouts/timeouts.go b/datasource/timeouts/timeouts.go index 8cdc3fc..b9049cf 100644 --- a/datasource/timeouts/timeouts.go +++ b/datasource/timeouts/timeouts.go @@ -11,13 +11,33 @@ import ( "github.com/hashicorp/terraform-plugin-framework/attr" "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/types" + "github.com/hashicorp/terraform-plugin-framework/types/basetypes" "github.com/hashicorp/terraform-plugin-go/tftypes" "github.com/hashicorp/terraform-plugin-log/tflog" ) +var ( + _ basetypes.ObjectTypable = Type{} + _ basetypes.ObjectValuable = Value{} +) + // Type is an attribute type that represents timeouts. type Type struct { - types.ObjectType + basetypes.ObjectType +} + +// String returns a human-readable representation of the type. +func (t Type) String() string { + return "timeouts.Type" +} + +// ValueFromObject returns a Value given a basetypes.ObjectValue. +func (t Type) ValueFromObject(_ context.Context, in basetypes.ObjectValue) (basetypes.ObjectValuable, diag.Diagnostics) { + value := Value{ + Object: in, + } + + return value, nil } // ValueFromTerraform returns a Value given a tftypes.Value. @@ -39,7 +59,13 @@ func (t Type) ValueFromTerraform(ctx context.Context, in tftypes.Value) (attr.Va }, err } -// Equal returns true if `candidate` is also an Type and has the same +// ValueType returns the associated Value type for debugging. +func (t Type) ValueType(context.Context) attr.Value { + // It does not need to be a fully valid implementation of the type. + return Value{} +} + +// Equal returns true if `candidate` is also a Type and has the same // AttributeTypes. func (t Type) Equal(candidate attr.Type) bool { other, ok := candidate.(Type) @@ -67,6 +93,11 @@ func (t Value) Equal(c attr.Value) bool { return t.Object.Equal(other.Object) } +// ToObjectValue returns the underlying ObjectValue. +func (v Value) ToObjectValue(_ context.Context) (basetypes.ObjectValue, diag.Diagnostics) { + return v.Object, nil +} + // Type returns a Type with the same attribute types as `t`. func (t Value) Type(ctx context.Context) attr.Type { return Type{ diff --git a/resource/timeouts/timeouts.go b/resource/timeouts/timeouts.go index 86c8872..bd1be82 100644 --- a/resource/timeouts/timeouts.go +++ b/resource/timeouts/timeouts.go @@ -11,13 +11,33 @@ import ( "github.com/hashicorp/terraform-plugin-framework/attr" "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/types" + "github.com/hashicorp/terraform-plugin-framework/types/basetypes" "github.com/hashicorp/terraform-plugin-go/tftypes" "github.com/hashicorp/terraform-plugin-log/tflog" ) +var ( + _ basetypes.ObjectTypable = Type{} + _ basetypes.ObjectValuable = Value{} +) + // Type is an attribute type that represents timeouts. type Type struct { - types.ObjectType + basetypes.ObjectType +} + +// String returns a human-readable representation of the type. +func (t Type) String() string { + return "timeouts.Type" +} + +// ValueFromObject returns a Value given a basetypes.ObjectValue. +func (t Type) ValueFromObject(_ context.Context, in basetypes.ObjectValue) (basetypes.ObjectValuable, diag.Diagnostics) { + value := Value{ + Object: in, + } + + return value, nil } // ValueFromTerraform returns a Value given a tftypes.Value. @@ -39,6 +59,12 @@ func (t Type) ValueFromTerraform(ctx context.Context, in tftypes.Value) (attr.Va }, err } +// ValueType returns the associated Value type for debugging. +func (t Type) ValueType(context.Context) attr.Value { + // It does not need to be a fully valid implementation of the type. + return Value{} +} + // Equal returns true if `candidate` is also a Type and has the same // AttributeTypes. func (t Type) Equal(candidate attr.Type) bool { @@ -67,6 +93,11 @@ func (t Value) Equal(c attr.Value) bool { return t.Object.Equal(other.Object) } +// ToObjectValue returns the underlying ObjectValue. +func (v Value) ToObjectValue(_ context.Context) (basetypes.ObjectValue, diag.Diagnostics) { + return v.Object, nil +} + // Type returns a Type with the same attribute types as `t`. func (t Value) Type(ctx context.Context) attr.Type { return Type{