Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changes/unreleased/BUG FIXES-20230706-172842.yaml
Original file line number Diff line number Diff line change
@@ -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"
6 changes: 6 additions & 0 deletions .changes/unreleased/BUG FIXES-20230706-172907.yaml
Original file line number Diff line number Diff line change
@@ -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"
35 changes: 33 additions & 2 deletions datasource/timeouts/timeouts.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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)
Expand Down Expand Up @@ -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{
Expand Down
33 changes: 32 additions & 1 deletion resource/timeouts/timeouts.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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 {
Expand Down Expand Up @@ -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{
Expand Down