From 37e9bc3cbba753eab5c8c9ea46225487692717e7 Mon Sep 17 00:00:00 2001 From: Brian Flad Date: Tue, 25 Oct 2022 13:10:22 -0400 Subject: [PATCH] types: Remove Attrs, AttrTypes, Elems, ElemTypes, Null, Unknown, and Value fields Reference: https://github.com/hashicorp/terraform-plugin-framework/issues/447 Reference: https://github.com/hashicorp/terraform-plugin-framework/pull/502 When the framework type system was originally being developed, the value types were introduced with exported fields which also served as the internal details of whether a value was null, unknown, or a known value of a friendlier Go type. It was known that there was the potential for issues, but the simplified developer experience seemed to outweigh the potential for developer issues. Fast forward a few months, this decision appears to have two consequences that the framework maintainers hear about across various forums. One issue is that the value types directly expose their internal implementation details and support the three states of a Terraform type value: being null, unknown, or a known value. Only one state should ever be set, but provider developers can make a value that is any combination of those states. This makes the framework behavior potentially indeterminate from the provider developer perspective whether, for example, a null AND unknown value becomes null OR unknown as it works its way through the framework. ```go type ThingResourceModel struct{ Computed types.String `tfsdk:"computed"` } func (r ThingResource) Create(ctx context.Context, req resource.CreateResource, resp *resource.CreateResponse) { var data ThingResourceModel resp.Diagnostics.Append(req.Plan.Get(ctx, &data)...) tflog.Trace(ctx, "Data Values", map[string]any{ // Unknown value: types.String{Null: false, Unknown: true, Value: ""} "computed": plan.Computed, }) // Maybe some external API responses here, but showing hardcoded updates for // brevity. This will make the value invalid by enabling Null without // disabling Unknown. data.Computed.Null = true tflog.Trace(ctx, "Data Values", map[string]any{ // Invalid value: types.String{Null: true, Unknown: true, Value: ""} "computed": data.Computed, }) // The invalid value will be either null or unknown, depending on the // type implementation. If unknown, Terraform will error, since unknown // values are never allowed in state. resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) } ``` Another issue is that it is possible to create collection value types that do not match their type definition. This issue is especially more likely with `types.Object` where it is possible to accidentially omit attributes. While the framework handling would eventually catch this issue when dealing with the invalid value, it can be caught sooner. ```go // Invalid value (missing attribute and differing attribute name) types.Object{ AttrTypes: map[string]attr.Type{ "one": types.StringType, "two": types.BoolType, }, Attrs: map[string]attr.Value{ "not_one": types.String{Value: "wrong name"}, }, } ``` Another issue is that the default (zero-value) state for an "unset" value type turns into a known value, which is confusing since these values explicitly support being null. This causes Terraform errors which would surface to practitioners (especially when untested) that provider developers then have to troubleshoot the error message containing Terraform's type system details, potentially discover the reason why it is happening by looking at the framework type source code, then figure out a workable solution. It's not intuitive. ```go type ThingResourceModel struct{ // let's assume this is left unconfigured (null in config and plan) Optional types.String `tfsdk:"optional"` } func (r ThingResource) Create(ctx context.Context, req resource.CreateResource, resp *resource.CreateResponse) { // Providers can opt to use a single variable that is updated based on an // external response, however that logic can be more difficult sometimes, // so it can be easier to split them. Showing the split way to exemplify // the "unset" problem. var plan, state ThingResourceModel resp.Diagnostics.Append(req.Plan.Get(ctx, &plan)...) tflog.Trace(ctx, "Plan Values", map[string]any{ // Null value: types.String{Null: true, Unknown: false, Value: ""} "optional": plan.Optional, }) // Maybe some external API responses here, but intentionally not // doing any state.Optional setting, which might happen if the // external response for that data was null for example. tflog.Trace(ctx, "State Values", map[string]any{ // Zero-value: types.String{Null: false, Unknown: false, Value: ""} "optional": state.Optional, }) // The state zero-value will later cause Terraform to error, such as: // Error: Provider produced inconsistent result after apply // ... expected cty.NullVal(cty.String), got cty.StringVal("") // Since the plan value said it would be null. resp.Diagnostics.Append(resp.State.Set(ctx, &state)...) } ``` This removal of the fields in preference of functions and methods aims to unexport the internal details and treat the value types as immutable once they are created. The zero-value implementations of these values is now null, instead of a known zero-value of the underlying type. While not recommended for production usage without extensive testing, provider developers can opt for `panic()` inducing versions of collection value creations, rather than dealing with `diag.Diagnostics` everywhere. Accessing value information after the migration can be accomplished with the following: | Prior Value Access | New Value Access | |----------------------|--------------------| | `(types.Bool).Value` | `(types.Bool).ValueBool()` | | `(types.Bool).Null` | `(types.Bool).IsNull()` | | `(types.Bool).Unknown` | `(types.Bool).IsUnknown()` | | `(types.Float64).Value` | `(types.Float64).ValueFloat64()` | | `(types.Float64).Null` | `(types.Float64).IsNull()` | | `(types.Float64).Unknown` | `(types.Float64).IsUnknown()` | | `(types.Int64).Value` | `(types.Int64).ValueInt64()` | | `(types.Int64).Null` | `(types.Int64).IsNull()` | | `(types.Int64).Unknown` | `(types.Int64).IsUnknown()` | | `(types.List).Elems` | `(types.List).Elements()` or `(types.List).ElementsAs()` | | `(types.List).ElemType` | `(types.List).ElementType()` | | `(types.List).Null` | `(types.List).IsNull()` | | `(types.List).Unknown` | `(types.List).IsUnknown()` | | `(types.Map).Elems` | `(types.Map).Elements()` or `(types.Map).ElementsAs()` | | `(types.Map).ElemType` | `(types.Map).ElementType()` | | `(types.Map).Null` | `(types.Map).IsNull()` | | `(types.Map).Unknown` | `(types.Map).IsUnknown()` | | `(types.Number).Value` | `(types.Number).ValueBigFloat()` | | `(types.Number).Null` | `(types.Number).IsNull()` | | `(types.Number).Unknown` | `(types.Number).IsUnknown()` | | `(types.Object).Attrs` | `(types.Object).Attributes()` or `(types.Object).As()` | | `(types.Object).AttrTypes` | `(types.Object).AttributeTypes()` | | `(types.Object).Null` | `(types.Object).IsNull()` | | `(types.Object).Unknown` | `(types.Object).IsUnknown()` | | `(types.Set).Elems` | `(types.Set).Elements()` or `(types.Set).ElementsAs()` | | `(types.Set).ElemType` | `(types.Set).ElementType()` | | `(types.Set).Null` | `(types.Set).IsNull()` | | `(types.Set).Unknown` | `(types.Set).IsUnknown()` | | `(types.String).Value` | `(types.String).ValueString()` | | `(types.String).Null` | `(types.String).IsNull()` | | `(types.String).Unknown` | `(types.String).IsUnknown()` | Creating values after the migration can be accomplished with the following: | Prior Value Creation | New Value Creation | |----------------------|--------------------| | `types.Bool{Value: /* value */}` | `types.BoolValue(/* value */)` | | `types.Bool{Null: true}` | `types.BoolNull()` | | `types.Bool{Unknown: true}` | `types.BoolUnknown()` | | `types.Float64{Value: /* value */}` | `types.Float64Value(/* value */)` | | `types.Float64{Null: true}` | `types.Float64Null()` | | `types.Float64{Unknown: true}` | `types.Float64Unknown()` | | `types.Int64{Value: /* value */}` | `types.Int64Value(/* value */)` | | `types.Int64{Null: true}` | `types.Int64Null()` | | `types.Int64{Unknown: true}` | `types.Int64Unknown()` | | `types.List{ElemType: /* element type */, Elems: /* value */}` | `list, diags := types.ListValue(/* element type */, /* value */)` or `list, diags := types.ListValueFrom(context.Context, /* element type */, any)` or `list := types.ListValueMust(/* element type */, /* value */)` | | `types.List{ElemType: /* element type */, Null: true}` | `types.ListNull(/* element type */)` | | `types.List{ElemType: /* element type */, Unknown: true}` | `types.ListUnknown(/* element type */)` | | `types.Map{ElemType: /* element type */, Elems: /* value */}` | `m, diags := types.MapValue(/* element type */, /* value */)` or `m, diags := types.MapValueFrom(context.Context, /* element type */, any)` or `m := types.MapValueMust(/* element type */, /* value */)` | | `types.Map{ElemType: /* element type */, Null: true}` | `types.MapNull(/* element type */)` | | `types.Map{ElemType: /* element type */, Unknown: true}` | `types.MapUnknown(/* element type */)` | | `types.Number{Value: /* value */}` | `types.NumberValue(/* value */)` | | `types.Number{Null: true}` | `types.NumberNull()` | | `types.Number{Unknown: true}` | `types.NumberUnknown()` | | `types.Object{AttrTypes: /* attribute types */, Attrs: /* attribute values */}` | `object, diags := types.ObjectValue(/* attribute types */, /* attribute values */)` or `object, diags := types.ObjectValueFrom(context.Context, /* attribute types */, any)` or `object := types.ObjectValueMust(/* attribute types */, /* attribute values */)` | | `types.Object{AttrTypes: /* attribute types */, Null: true}` | `types.ObjectNull(/* attribute types */)` | | `types.Object{AttrTypes: /* attribute types */, Unknown: true}` | `types.ObjectUnknown(/* attribute types */)` | | `types.Set{ElemType: /* element type */, Elems: /* value */}` | `set, diags := types.SetValue(/* element type */, /* value */)` or `set, diags := types.SetValueFrom(context.Context, /* element type */, any)` or `set := types.SetValueMust(/* element type */, /* value */)` | | `types.Set{ElemType: /* element type */, Null: true}` | `types.SetNull(/* element type */)` | | `types.Set{ElemType: /* element type */, Unknown: true}` | `types.SetUnknown(/* element type */)` | | `types.String{Value: /* value */}` | `types.StringValue(/* value */)` | | `types.String{Null: true}` | `types.StringNull()` | | `types.String{Unknown: true}` | `types.StringUnknown()` | --- .changelog/pending.txt | 47 + attr/value_state.go | 31 + .../fromtftypes/attribute_path_step_test.go | 2 +- internal/fromtftypes/attribute_path_test.go | 2 +- internal/fromtftypes/value_test.go | 96 +- .../fwschemadata/data_get_at_path_test.go | 544 +++--- internal/fwschemadata/data_get_test.go | 524 +++-- .../fwschemadata/data_path_exists_test.go | 6 +- .../fwschemadata/data_path_matches_test.go | 16 +- .../fwschemadata/data_set_at_path_test.go | 76 +- internal/fwschemadata/data_set_test.go | 2 +- internal/fwschemadata/data_value_test.go | 117 +- internal/fwschemadata/tftypes_value_test.go | 6 +- internal/fwserver/attr_value.go | 14 +- .../attribute_plan_modification_test.go | 372 ++-- .../fwserver/block_plan_modification_test.go | 782 ++++---- .../server_applyresourcechange_test.go | 4 +- .../fwserver/server_createresource_test.go | 4 +- .../server_planresourcechange_test.go | 8 +- .../fwserver/server_readdatasource_test.go | 2 +- internal/fwserver/server_readresource_test.go | 2 +- .../server_applyresourcechange_test.go | 4 +- .../server_planresourcechange_test.go | 6 +- .../server_readdatasource_test.go | 2 +- .../proto5server/server_readresource_test.go | 2 +- .../server_applyresourcechange_test.go | 4 +- .../server_planresourcechange_test.go | 6 +- .../server_readdatasource_test.go | 2 +- .../proto6server/server_readresource_test.go | 2 +- internal/reflect/interfaces_test.go | 26 +- internal/reflect/number_test.go | 116 +- internal/reflect/pointer_test.go | 22 +- internal/reflect/primitive_test.go | 30 +- internal/reflect/struct_test.go | 208 +- .../testing/planmodifiers/planmodifiers.go | 2 +- internal/testing/types/number.go | 6 +- internal/testing/types/string.go | 6 +- .../totftypes/attribute_path_step_test.go | 2 +- ...pression_step_attribute_name_exact_test.go | 4 +- ...xpression_step_element_key_int_any_test.go | 4 +- ...ression_step_element_key_int_exact_test.go | 4 +- ...ession_step_element_key_string_any_test.go | 4 +- ...sion_step_element_key_string_exact_test.go | 4 +- ...ression_step_element_key_value_any_test.go | 4 +- ...ssion_step_element_key_value_exact_test.go | 78 +- path/expression_step_parent_test.go | 4 +- path/expression_steps_test.go | 60 +- path/expression_test.go | 50 +- path/expressions_test.go | 8 +- path/path_step_attribute_name_test.go | 2 +- path/path_step_element_key_int_test.go | 2 +- path/path_step_element_key_string_test.go | 2 +- path/path_step_element_key_value_test.go | 72 +- path/path_steps_test.go | 34 +- path/path_test.go | 30 +- path/paths_test.go | 8 +- resource/plan_modifiers_test.go | 218 +-- tfsdk/config_test.go | 4 +- tfsdk/convert_test.go | 10 +- tfsdk/plan_test.go | 4 +- tfsdk/schema_test.go | 48 +- tfsdk/state_test.go | 4 +- tfsdk/value_as_test.go | 202 +- tfsdk/value_from_test.go | 190 +- types/bool.go | 116 +- types/bool_test.go | 430 +---- types/float64.go | 114 +- types/float64_test.go | 308 +-- types/int64.go | 117 +- types/int64_test.go | 302 +-- types/list.go | 189 +- types/list_test.go | 674 +------ types/map.go | 192 +- types/map_test.go | 675 +------ types/number.go | 127 +- types/number_test.go | 329 +--- types/object.go | 209 +- types/object_test.go | 1719 ++++------------- types/set.go | 180 +- types/set_test.go | 674 +------ types/string.go | 116 +- types/string_test.go | 299 +-- types/value_state.go | 42 - .../framework/migrating/resources/import.mdx | 2 - website/docs/plugin/framework/paths.mdx | 32 +- 85 files changed, 2936 insertions(+), 8067 deletions(-) create mode 100644 .changelog/pending.txt create mode 100644 attr/value_state.go delete mode 100644 types/value_state.go diff --git a/.changelog/pending.txt b/.changelog/pending.txt new file mode 100644 index 000000000..04eca722a --- /dev/null +++ b/.changelog/pending.txt @@ -0,0 +1,47 @@ +```release-note:breaking-change +types: The `Bool` type `Null`, `Unknown`, and `Value` fields have been removed. Use the `BoolNull()`, `BoolUnknown()`, and `BoolValue()` creation functions and `IsNull()`, `IsUnknown()`, and `ValueBool()` methods instead. +``` + +```release-note:breaking-change +types: The `Float64` type `Null`, `Unknown`, and `Value` fields have been removed. Use the `Float64Null()`, `Float64Unknown()`, and `Float64Value()` creation functions and `IsNull()`, `IsUnknown()`, and `ValueFloat64()` methods instead. +``` + +```release-note:breaking-change +types: The `Int64` type `Null`, `Unknown`, and `Value` fields have been removed. Use the `Int64Null()`, `Int64Unknown()`, and `Int64Value()` creation functions and `IsNull()`, `IsUnknown()`, and `ValueInt64()` methods instead. +``` + +```release-note:breaking-change +types: The `List` type `Elems`, `ElemType`, `Null`, and `Unknown` fields have been removed. Use the `ListNull()`, `ListUnknown()`, `ListValue()`, and `ListValueMust()` creation functions and `Elements()`, `ElementsAs()`, `ElementType()`, `IsNull()`, and `IsUnknown()` methods instead. +``` + +```release-note:breaking-change +types: The `Map` type `Elems`, `ElemType`, `Null`, and `Unknown` fields have been removed. Use the `MapNull()`, `MapUnknown()`, `MapValue()`, and `MapValueMust()` creation functions and `Elements()`, `ElementsAs()`, `ElementType()`, `IsNull()`, and `IsUnknown()` methods instead. +``` + +```release-note:breaking-change +types: The `Number` type `Null`, `Unknown`, and `Value` fields have been removed. Use the `NumberNull()`, `NumberUnknown()`, and `NumberValue()` creation functions and `IsNull()`, `IsUnknown()`, and `ValueBigFloat()` methods instead. +``` + +```release-note:breaking-change +types: The `Object` type `Attrs`, `AttrTypes`, `Null`, and `Unknown` fields have been removed. Use the `ObjectNull()`, `ObjectUnknown()`, `ObjectValue()`, and `ObjectValueMust()` creation functions and `As()`, `Attributes()`, `AttributeTypes()`, `IsNull()`, and `IsUnknown()` methods instead. +``` + +```release-note:breaking-change +types: The `Set` type `Elems`, `ElemType`, `Null`, and `Unknown` fields have been removed. Use the `SetNull()`, `SetUnknown()`, `SetValue()`, and `SetValueMust()` creation functions and `Elements()`, `ElementsAs()`, `ElementType()`, `IsNull()`, and `IsUnknown()` methods instead. +``` + +```release-note:breaking-change +types: The `String` type `Null`, `Unknown`, and `Value` fields have been removed. Use the `StringNull()`, `StringUnknown()`, and `StringValue()` creation functions and `IsNull()`, `IsUnknown()`, and `ValueString()` methods instead. +``` + +```release-note:enhancement +attr: Added `ValueState` type, which custom types can use to consistently represent the three possible value states (known, null, and unknown) +``` + +```release-note:bug +types: Prevented Terraform errors where the zero-value for any `attr.Value` types such as `String` would be a known value instead of null +``` + +```release-note:bug +types: Prevented indeterminate behavior for any `attr.Value` types where they could be any combination of null, unknown, and/or known +``` diff --git a/attr/value_state.go b/attr/value_state.go new file mode 100644 index 000000000..10798f691 --- /dev/null +++ b/attr/value_state.go @@ -0,0 +1,31 @@ +package attr + +import "fmt" + +const ( + // ValueStateNull represents a value which is null. + // + // This value is 0 so it is the zero-value for types implementations. + ValueStateNull ValueState = 0 + + // ValueStateUnknown represents a value which is unknown. + ValueStateUnknown ValueState = 1 + + // ValueStateKnown represents a value which is known (not null or unknown). + ValueStateKnown ValueState = 2 +) + +type ValueState uint8 + +func (s ValueState) String() string { + switch s { + case ValueStateKnown: + return "known" + case ValueStateNull: + return "null" + case ValueStateUnknown: + return "unknown" + default: + panic(fmt.Sprintf("unhandled ValueState in String: %d", s)) + } +} diff --git a/internal/fromtftypes/attribute_path_step_test.go b/internal/fromtftypes/attribute_path_step_test.go index 39b5494be..c052317f9 100644 --- a/internal/fromtftypes/attribute_path_step_test.go +++ b/internal/fromtftypes/attribute_path_step_test.go @@ -43,7 +43,7 @@ func TestAttributePathStep(t *testing.T) { "PathStepElementKeyValue": { tfType: tftypes.ElementKeyValue(tftypes.NewValue(tftypes.String, "test")), attrType: types.StringType, - expected: path.PathStepElementKeyValue{Value: types.String{Value: "test"}}, + expected: path.PathStepElementKeyValue{Value: types.StringValue("test")}, }, "PathStepElementKeyValue-error": { tfType: tftypes.ElementKeyValue(tftypes.NewValue(tftypes.String, "test")), diff --git a/internal/fromtftypes/attribute_path_test.go b/internal/fromtftypes/attribute_path_test.go index 192f108f5..2b5587e8d 100644 --- a/internal/fromtftypes/attribute_path_test.go +++ b/internal/fromtftypes/attribute_path_test.go @@ -88,7 +88,7 @@ func TestAttributePath(t *testing.T) { }, }, }, - expected: path.Root("test").AtSetValue(types.String{Value: "test-value"}), + expected: path.Root("test").AtSetValue(types.StringValue("test-value")), }, "AttributeName-ElementKeyValue-value-conversion-error": { tfType: tftypes.NewAttributePath().WithAttributeName("test").WithElementKeyValue(tftypes.NewValue(tftypes.String, "test-value")), diff --git a/internal/fromtftypes/value_test.go b/internal/fromtftypes/value_test.go index 2ea227f76..f3cc01dfc 100644 --- a/internal/fromtftypes/value_test.go +++ b/internal/fromtftypes/value_test.go @@ -27,7 +27,7 @@ func TestValue(t *testing.T) { "empty-tftype": { tfType: tftypes.Value{}, attrType: types.BoolType, - expected: types.Bool{Null: true}, + expected: types.BoolNull(), }, "nil-attr-type": { tfType: tftypes.Value{}, @@ -44,47 +44,47 @@ func TestValue(t *testing.T) { "bool-null": { tfType: tftypes.NewValue(tftypes.Bool, nil), attrType: types.BoolType, - expected: types.Bool{Null: true}, + expected: types.BoolNull(), }, "bool-unknown": { tfType: tftypes.NewValue(tftypes.Bool, tftypes.UnknownValue), attrType: types.BoolType, - expected: types.Bool{Unknown: true}, + expected: types.BoolUnknown(), }, "bool-value": { tfType: tftypes.NewValue(tftypes.Bool, true), attrType: types.BoolType, - expected: types.Bool{Value: true}, + expected: types.BoolValue(true), }, "float64-null": { tfType: tftypes.NewValue(tftypes.Number, nil), attrType: types.Float64Type, - expected: types.Float64{Null: true}, + expected: types.Float64Null(), }, "float64-unknown": { tfType: tftypes.NewValue(tftypes.Number, tftypes.UnknownValue), attrType: types.Float64Type, - expected: types.Float64{Unknown: true}, + expected: types.Float64Unknown(), }, "float64-value": { tfType: tftypes.NewValue(tftypes.Number, big.NewFloat(1.2)), attrType: types.Float64Type, - expected: types.Float64{Value: 1.2}, + expected: types.Float64Value(1.2), }, "int64-null": { tfType: tftypes.NewValue(tftypes.Number, nil), attrType: types.Int64Type, - expected: types.Int64{Null: true}, + expected: types.Int64Null(), }, "int64-unknown": { tfType: tftypes.NewValue(tftypes.Number, tftypes.UnknownValue), attrType: types.Int64Type, - expected: types.Int64{Unknown: true}, + expected: types.Int64Unknown(), }, "int64-value": { tfType: tftypes.NewValue(tftypes.Number, 123), attrType: types.Int64Type, - expected: types.Int64{Value: 123}, + expected: types.Int64Value(123), }, "list-null": { tfType: tftypes.NewValue( @@ -96,10 +96,7 @@ func TestValue(t *testing.T) { attrType: types.ListType{ ElemType: types.StringType, }, - expected: types.List{ - ElemType: types.StringType, - Null: true, - }, + expected: types.ListNull(types.StringType), }, "list-unknown": { tfType: tftypes.NewValue( @@ -111,10 +108,7 @@ func TestValue(t *testing.T) { attrType: types.ListType{ ElemType: types.StringType, }, - expected: types.List{ - ElemType: types.StringType, - Unknown: true, - }, + expected: types.ListUnknown(types.StringType), }, "list-value": { tfType: tftypes.NewValue( @@ -128,27 +122,27 @@ func TestValue(t *testing.T) { attrType: types.ListType{ ElemType: types.StringType, }, - expected: types.List{ - ElemType: types.StringType, - Elems: []attr.Value{ - types.String{Value: "test-value"}, + expected: types.ListValueMust( + types.StringType, + []attr.Value{ + types.StringValue("test-value"), }, - }, + ), }, "number-null": { tfType: tftypes.NewValue(tftypes.Number, nil), attrType: types.NumberType, - expected: types.Number{Null: true}, + expected: types.NumberNull(), }, "number-unknown": { tfType: tftypes.NewValue(tftypes.Number, tftypes.UnknownValue), attrType: types.NumberType, - expected: types.Number{Unknown: true}, + expected: types.NumberUnknown(), }, "number-value": { tfType: tftypes.NewValue(tftypes.Number, big.NewFloat(1.2)), attrType: types.NumberType, - expected: types.Number{Value: big.NewFloat(1.2)}, + expected: types.NumberValue(big.NewFloat(1.2)), }, "object-null": { tfType: tftypes.NewValue( @@ -164,12 +158,11 @@ func TestValue(t *testing.T) { "test_attr": types.StringType, }, }, - expected: types.Object{ - AttrTypes: map[string]attr.Type{ + expected: types.ObjectNull( + map[string]attr.Type{ "test_attr": types.StringType, }, - Null: true, - }, + ), }, "object-unknown": { tfType: tftypes.NewValue( @@ -185,12 +178,11 @@ func TestValue(t *testing.T) { "test_attr": types.StringType, }, }, - expected: types.Object{ - AttrTypes: map[string]attr.Type{ + expected: types.ObjectUnknown( + map[string]attr.Type{ "test_attr": types.StringType, }, - Unknown: true, - }, + ), }, "object-value": { tfType: tftypes.NewValue( @@ -208,14 +200,14 @@ func TestValue(t *testing.T) { "test_attr": types.StringType, }, }, - expected: types.Object{ - AttrTypes: map[string]attr.Type{ + expected: types.ObjectValueMust( + map[string]attr.Type{ "test_attr": types.StringType, }, - Attrs: map[string]attr.Value{ - "test_attr": types.String{Value: "test-value"}, + map[string]attr.Value{ + "test_attr": types.StringValue("test-value"), }, - }, + ), }, "set-null": { tfType: tftypes.NewValue( @@ -227,10 +219,7 @@ func TestValue(t *testing.T) { attrType: types.SetType{ ElemType: types.StringType, }, - expected: types.Set{ - ElemType: types.StringType, - Null: true, - }, + expected: types.SetNull(types.StringType), }, "set-unknown": { tfType: tftypes.NewValue( @@ -242,10 +231,7 @@ func TestValue(t *testing.T) { attrType: types.SetType{ ElemType: types.StringType, }, - expected: types.Set{ - ElemType: types.StringType, - Unknown: true, - }, + expected: types.SetUnknown(types.StringType), }, "set-value": { tfType: tftypes.NewValue( @@ -259,27 +245,27 @@ func TestValue(t *testing.T) { attrType: types.SetType{ ElemType: types.StringType, }, - expected: types.Set{ - ElemType: types.StringType, - Elems: []attr.Value{ - types.String{Value: "test-value"}, + expected: types.SetValueMust( + types.StringType, + []attr.Value{ + types.StringValue("test-value"), }, - }, + ), }, "string-null": { tfType: tftypes.NewValue(tftypes.String, nil), attrType: types.StringType, - expected: types.String{Null: true}, + expected: types.StringNull(), }, "string-unknown": { tfType: tftypes.NewValue(tftypes.String, tftypes.UnknownValue), attrType: types.StringType, - expected: types.String{Unknown: true}, + expected: types.StringUnknown(), }, "string-value": { tfType: tftypes.NewValue(tftypes.String, "test-value"), attrType: types.StringType, - expected: types.String{Value: "test-value"}, + expected: types.StringValue("test-value"), }, } diff --git a/internal/fwschemadata/data_get_at_path_test.go b/internal/fwschemadata/data_get_at_path_test.go index f36ff3a8a..8a12ee9b2 100644 --- a/internal/fwschemadata/data_get_at_path_test.go +++ b/internal/fwschemadata/data_get_at_path_test.go @@ -125,7 +125,7 @@ func TestDataGetAtPath(t *testing.T) { target: new(testtypes.String), expected: &testtypes.String{ CreatedBy: testtypes.StringTypeWithValidateError{}, - InternalString: types.String{Value: ""}, + InternalString: types.StringNull(), }, expectedDiags: diag.Diagnostics{ testtypes.TestErrorDiagnostic(path.Root("string")), @@ -156,7 +156,7 @@ func TestDataGetAtPath(t *testing.T) { target: new(testtypes.String), expected: &testtypes.String{ CreatedBy: testtypes.StringTypeWithValidateWarning{}, - InternalString: types.String{Value: "test"}, + InternalString: types.StringValue("test"), }, expectedDiags: diag.Diagnostics{ testtypes.TestWarningDiagnostic(path.Root("string")), @@ -185,7 +185,7 @@ func TestDataGetAtPath(t *testing.T) { }, path: path.Root("bool"), target: new(types.Bool), - expected: &types.Bool{Null: true}, + expected: pointer(types.BoolNull()), }, "BoolType-types.Bool-unknown": { data: fwschemadata.Data{ @@ -210,7 +210,7 @@ func TestDataGetAtPath(t *testing.T) { }, path: path.Root("bool"), target: new(types.Bool), - expected: &types.Bool{Unknown: true}, + expected: pointer(types.BoolUnknown()), }, "BoolType-types.Bool-value": { data: fwschemadata.Data{ @@ -235,7 +235,7 @@ func TestDataGetAtPath(t *testing.T) { }, path: path.Root("bool"), target: new(types.Bool), - expected: &types.Bool{Value: true}, + expected: pointer(types.BoolValue(true)), }, "BoolType-*bool-null": { data: fwschemadata.Data{ @@ -437,7 +437,7 @@ func TestDataGetAtPath(t *testing.T) { }, path: path.Root("float64"), target: new(types.Float64), - expected: &types.Float64{Null: true}, + expected: pointer(types.Float64Null()), }, "Float64Type-types.Float64-unknown": { data: fwschemadata.Data{ @@ -462,7 +462,7 @@ func TestDataGetAtPath(t *testing.T) { }, path: path.Root("float64"), target: new(types.Float64), - expected: &types.Float64{Unknown: true}, + expected: pointer(types.Float64Unknown()), }, "Float64Type-types.Float64-value": { data: fwschemadata.Data{ @@ -487,7 +487,7 @@ func TestDataGetAtPath(t *testing.T) { }, path: path.Root("float64"), target: new(types.Float64), - expected: &types.Float64{Value: 1.2}, + expected: pointer(types.Float64Value(1.2)), }, "Float64Type-*float64-null": { data: fwschemadata.Data{ @@ -689,7 +689,7 @@ func TestDataGetAtPath(t *testing.T) { }, path: path.Root("int64"), target: new(types.Int64), - expected: &types.Int64{Null: true}, + expected: pointer(types.Int64Null()), }, "Int64Type-types.Int64-unknown": { data: fwschemadata.Data{ @@ -714,7 +714,7 @@ func TestDataGetAtPath(t *testing.T) { }, path: path.Root("int64"), target: new(types.Int64), - expected: &types.Int64{Unknown: true}, + expected: pointer(types.Int64Unknown()), }, "Int64Type-types.Int64-value": { data: fwschemadata.Data{ @@ -739,7 +739,7 @@ func TestDataGetAtPath(t *testing.T) { }, path: path.Root("int64"), target: new(types.Int64), - expected: &types.Int64{Value: 12}, + expected: pointer(types.Int64Value(12)), }, "Int64Type-*int64-null": { data: fwschemadata.Data{ @@ -961,14 +961,13 @@ func TestDataGetAtPath(t *testing.T) { }, path: path.Root("list"), target: new(types.List), - expected: &types.List{ - ElemType: types.ObjectType{ + expected: pointer(types.ListNull( + types.ObjectType{ AttrTypes: map[string]attr.Type{ "nested_string": types.StringType, }, }, - Null: true, - }, + )), }, "ListBlock-types.List-unknown": { data: fwschemadata.Data{ @@ -1013,14 +1012,13 @@ func TestDataGetAtPath(t *testing.T) { }, path: path.Root("list"), target: new(types.List), - expected: &types.List{ - ElemType: types.ObjectType{ + expected: pointer(types.ListUnknown( + types.ObjectType{ AttrTypes: map[string]attr.Type{ "nested_string": types.StringType, }, }, - Unknown: true, - }, + )), }, "ListBlock-types.List-value": { data: fwschemadata.Data{ @@ -1086,31 +1084,31 @@ func TestDataGetAtPath(t *testing.T) { }, path: path.Root("list"), target: new(types.List), - expected: &types.List{ - ElemType: types.ObjectType{ + expected: pointer(types.ListValueMust( + types.ObjectType{ AttrTypes: map[string]attr.Type{ "nested_string": types.StringType, }, }, - Elems: []attr.Value{ - types.Object{ - AttrTypes: map[string]attr.Type{ + []attr.Value{ + types.ObjectValueMust( + map[string]attr.Type{ "nested_string": types.StringType, }, - Attrs: map[string]attr.Value{ - "nested_string": types.String{Value: "test1"}, + map[string]attr.Value{ + "nested_string": types.StringValue("test1"), }, - }, - types.Object{ - AttrTypes: map[string]attr.Type{ + ), + types.ObjectValueMust( + map[string]attr.Type{ "nested_string": types.StringType, }, - Attrs: map[string]attr.Value{ - "nested_string": types.String{Value: "test2"}, + map[string]attr.Value{ + "nested_string": types.StringValue("test2"), }, - }, + ), }, - }, + )), }, "ListBlock-[]types.Object-null": { data: fwschemadata.Data{ @@ -1276,22 +1274,22 @@ func TestDataGetAtPath(t *testing.T) { path: path.Root("list"), target: new([]types.Object), expected: &[]types.Object{ - { - AttrTypes: map[string]attr.Type{ + types.ObjectValueMust( + map[string]attr.Type{ "nested_string": types.StringType, }, - Attrs: map[string]attr.Value{ - "nested_string": types.String{Value: "test1"}, + map[string]attr.Value{ + "nested_string": types.StringValue("test1"), }, - }, - { - AttrTypes: map[string]attr.Type{ + ), + types.ObjectValueMust( + map[string]attr.Type{ "nested_string": types.StringType, }, - Attrs: map[string]attr.Value{ - "nested_string": types.String{Value: "test2"}, + map[string]attr.Value{ + "nested_string": types.StringValue("test2"), }, - }, + ), }, }, "ListBlock-[]struct-null": { @@ -1470,8 +1468,8 @@ func TestDataGetAtPath(t *testing.T) { expected: &[]struct { NestedString types.String `tfsdk:"nested_string"` }{ - {NestedString: types.String{Value: "test1"}}, - {NestedString: types.String{Value: "test2"}}, + {NestedString: types.StringValue("test1")}, + {NestedString: types.StringValue("test2")}, }, }, "ListNestedAttributes-types.List-null": { @@ -1517,14 +1515,13 @@ func TestDataGetAtPath(t *testing.T) { }, path: path.Root("list"), target: new(types.List), - expected: &types.List{ - ElemType: types.ObjectType{ + expected: pointer(types.ListNull( + types.ObjectType{ AttrTypes: map[string]attr.Type{ "nested_string": types.StringType, }, }, - Null: true, - }, + )), }, "ListNestedAttributes-types.List-unknown": { data: fwschemadata.Data{ @@ -1569,14 +1566,13 @@ func TestDataGetAtPath(t *testing.T) { }, path: path.Root("list"), target: new(types.List), - expected: &types.List{ - ElemType: types.ObjectType{ + expected: pointer(types.ListUnknown( + types.ObjectType{ AttrTypes: map[string]attr.Type{ "nested_string": types.StringType, }, }, - Unknown: true, - }, + )), }, "ListNestedAttributes-types.List-value": { data: fwschemadata.Data{ @@ -1642,31 +1638,31 @@ func TestDataGetAtPath(t *testing.T) { }, path: path.Root("list"), target: new(types.List), - expected: &types.List{ - ElemType: types.ObjectType{ + expected: pointer(types.ListValueMust( + types.ObjectType{ AttrTypes: map[string]attr.Type{ "nested_string": types.StringType, }, }, - Elems: []attr.Value{ - types.Object{ - AttrTypes: map[string]attr.Type{ + []attr.Value{ + types.ObjectValueMust( + map[string]attr.Type{ "nested_string": types.StringType, }, - Attrs: map[string]attr.Value{ - "nested_string": types.String{Value: "test1"}, + map[string]attr.Value{ + "nested_string": types.StringValue("test1"), }, - }, - types.Object{ - AttrTypes: map[string]attr.Type{ + ), + types.ObjectValueMust( + map[string]attr.Type{ "nested_string": types.StringType, }, - Attrs: map[string]attr.Value{ - "nested_string": types.String{Value: "test2"}, + map[string]attr.Value{ + "nested_string": types.StringValue("test2"), }, - }, + ), }, - }, + )), }, "ListNestedAttributes-[]types.Object-null": { data: fwschemadata.Data{ @@ -1832,22 +1828,22 @@ func TestDataGetAtPath(t *testing.T) { path: path.Root("list"), target: new([]types.Object), expected: &[]types.Object{ - { - AttrTypes: map[string]attr.Type{ + types.ObjectValueMust( + map[string]attr.Type{ "nested_string": types.StringType, }, - Attrs: map[string]attr.Value{ - "nested_string": types.String{Value: "test1"}, + map[string]attr.Value{ + "nested_string": types.StringValue("test1"), }, - }, - { - AttrTypes: map[string]attr.Type{ + ), + types.ObjectValueMust( + map[string]attr.Type{ "nested_string": types.StringType, }, - Attrs: map[string]attr.Value{ - "nested_string": types.String{Value: "test2"}, + map[string]attr.Value{ + "nested_string": types.StringValue("test2"), }, - }, + ), }, }, "ListNestedAttributes-[]struct-null": { @@ -2026,8 +2022,8 @@ func TestDataGetAtPath(t *testing.T) { expected: &[]struct { NestedString types.String `tfsdk:"nested_string"` }{ - {NestedString: types.String{Value: "test1"}}, - {NestedString: types.String{Value: "test2"}}, + {NestedString: types.StringValue("test1")}, + {NestedString: types.StringValue("test2")}, }, }, "ListType-types.List-null": { @@ -2060,12 +2056,9 @@ func TestDataGetAtPath(t *testing.T) { }, ), }, - path: path.Root("list"), - target: new(types.List), - expected: &types.List{ - ElemType: types.StringType, - Null: true, - }, + path: path.Root("list"), + target: new(types.List), + expected: pointer(types.ListNull(types.StringType)), }, "ListType-types.List-unknown": { data: fwschemadata.Data{ @@ -2097,12 +2090,9 @@ func TestDataGetAtPath(t *testing.T) { }, ), }, - path: path.Root("list"), - target: new(types.List), - expected: &types.List{ - ElemType: types.StringType, - Unknown: true, - }, + path: path.Root("list"), + target: new(types.List), + expected: pointer(types.ListUnknown(types.StringType)), }, "ListType-types.List-value": { data: fwschemadata.Data{ @@ -2139,13 +2129,13 @@ func TestDataGetAtPath(t *testing.T) { }, path: path.Root("list"), target: new(types.List), - expected: &types.List{ - ElemType: types.StringType, - Elems: []attr.Value{ - types.String{Value: "test1"}, - types.String{Value: "test2"}, + expected: pointer(types.ListValueMust( + types.StringType, + []attr.Value{ + types.StringValue("test1"), + types.StringValue("test2"), }, - }, + )), }, "ListType-[]types.String-null": { data: fwschemadata.Data{ @@ -2260,8 +2250,8 @@ func TestDataGetAtPath(t *testing.T) { path: path.Root("list"), target: new([]types.String), expected: &[]types.String{ - {Value: "test1"}, - {Value: "test2"}, + types.StringValue("test1"), + types.StringValue("test2"), }, }, "ListType-[]string-null": { @@ -2424,14 +2414,13 @@ func TestDataGetAtPath(t *testing.T) { }, path: path.Root("map"), target: new(types.Map), - expected: &types.Map{ - ElemType: types.ObjectType{ + expected: pointer(types.MapNull( + types.ObjectType{ AttrTypes: map[string]attr.Type{ "nested_string": types.StringType, }, }, - Null: true, - }, + )), }, "MapNestedAttributes-types.Map-unknown": { data: fwschemadata.Data{ @@ -2476,14 +2465,13 @@ func TestDataGetAtPath(t *testing.T) { }, path: path.Root("map"), target: new(types.Map), - expected: &types.Map{ - ElemType: types.ObjectType{ + expected: pointer(types.MapUnknown( + types.ObjectType{ AttrTypes: map[string]attr.Type{ "nested_string": types.StringType, }, }, - Unknown: true, - }, + )), }, "MapNestedAttributes-types.Map-value": { data: fwschemadata.Data{ @@ -2549,31 +2537,31 @@ func TestDataGetAtPath(t *testing.T) { }, path: path.Root("map"), target: new(types.Map), - expected: &types.Map{ - ElemType: types.ObjectType{ + expected: pointer(types.MapValueMust( + types.ObjectType{ AttrTypes: map[string]attr.Type{ "nested_string": types.StringType, }, }, - Elems: map[string]attr.Value{ - "key1": types.Object{ - AttrTypes: map[string]attr.Type{ + map[string]attr.Value{ + "key1": types.ObjectValueMust( + map[string]attr.Type{ "nested_string": types.StringType, }, - Attrs: map[string]attr.Value{ - "nested_string": types.String{Value: "value1"}, + map[string]attr.Value{ + "nested_string": types.StringValue("value1"), }, - }, - "key2": types.Object{ - AttrTypes: map[string]attr.Type{ + ), + "key2": types.ObjectValueMust( + map[string]attr.Type{ "nested_string": types.StringType, }, - Attrs: map[string]attr.Value{ - "nested_string": types.String{Value: "value2"}, + map[string]attr.Value{ + "nested_string": types.StringValue("value2"), }, - }, + ), }, - }, + )), }, "MapNestedAttributes-map[string]types.Object-null": { data: fwschemadata.Data{ @@ -2739,22 +2727,22 @@ func TestDataGetAtPath(t *testing.T) { path: path.Root("map"), target: new(map[string]types.Object), expected: &map[string]types.Object{ - "key1": { - AttrTypes: map[string]attr.Type{ + "key1": types.ObjectValueMust( + map[string]attr.Type{ "nested_string": types.StringType, }, - Attrs: map[string]attr.Value{ - "nested_string": types.String{Value: "value1"}, + map[string]attr.Value{ + "nested_string": types.StringValue("value1"), }, - }, - "key2": { - AttrTypes: map[string]attr.Type{ + ), + "key2": types.ObjectValueMust( + map[string]attr.Type{ "nested_string": types.StringType, }, - Attrs: map[string]attr.Value{ - "nested_string": types.String{Value: "value2"}, + map[string]attr.Value{ + "nested_string": types.StringValue("value2"), }, - }, + ), }, }, "MapNestedAttributes-map[string]struct-null": { @@ -2933,8 +2921,8 @@ func TestDataGetAtPath(t *testing.T) { expected: &map[string]struct { NestedString types.String `tfsdk:"nested_string"` }{ - "key1": {NestedString: types.String{Value: "value1"}}, - "key2": {NestedString: types.String{Value: "value2"}}, + "key1": {NestedString: types.StringValue("value1")}, + "key2": {NestedString: types.StringValue("value2")}, }, }, "MapType-types.Map-null": { @@ -2967,12 +2955,9 @@ func TestDataGetAtPath(t *testing.T) { }, ), }, - path: path.Root("map"), - target: new(types.Map), - expected: &types.Map{ - ElemType: types.StringType, - Null: true, - }, + path: path.Root("map"), + target: new(types.Map), + expected: pointer(types.MapNull(types.StringType)), }, "MapType-types.Map-unknown": { data: fwschemadata.Data{ @@ -3004,12 +2989,9 @@ func TestDataGetAtPath(t *testing.T) { }, ), }, - path: path.Root("map"), - target: new(types.Map), - expected: &types.Map{ - ElemType: types.StringType, - Unknown: true, - }, + path: path.Root("map"), + target: new(types.Map), + expected: pointer(types.MapUnknown(types.StringType)), }, "MapType-types.Map-value": { data: fwschemadata.Data{ @@ -3046,13 +3028,13 @@ func TestDataGetAtPath(t *testing.T) { }, path: path.Root("map"), target: new(types.Map), - expected: &types.Map{ - ElemType: types.StringType, - Elems: map[string]attr.Value{ - "key1": types.String{Value: "value1"}, - "key2": types.String{Value: "value2"}, + expected: pointer(types.MapValueMust( + types.StringType, + map[string]attr.Value{ + "key1": types.StringValue("value1"), + "key2": types.StringValue("value2"), }, - }, + )), }, "MapType-map[string]types.String-null": { data: fwschemadata.Data{ @@ -3167,8 +3149,8 @@ func TestDataGetAtPath(t *testing.T) { path: path.Root("map"), target: new(map[string]types.String), expected: &map[string]types.String{ - "key1": {Value: "value1"}, - "key2": {Value: "value2"}, + "key1": types.StringValue("value1"), + "key2": types.StringValue("value2"), }, }, "MapType-map[string]string-null": { @@ -3326,12 +3308,11 @@ func TestDataGetAtPath(t *testing.T) { }, path: path.Root("object"), target: new(types.Object), - expected: &types.Object{ - AttrTypes: map[string]attr.Type{ + expected: pointer(types.ObjectNull( + map[string]attr.Type{ "nested_string": types.StringType, }, - Null: true, - }, + )), }, "ObjectType-types.Object-unknown": { data: fwschemadata.Data{ @@ -3371,12 +3352,11 @@ func TestDataGetAtPath(t *testing.T) { }, path: path.Root("object"), target: new(types.Object), - expected: &types.Object{ - AttrTypes: map[string]attr.Type{ + expected: pointer(types.ObjectUnknown( + map[string]attr.Type{ "nested_string": types.StringType, }, - Unknown: true, - }, + )), }, "ObjectType-types.Object-value": { data: fwschemadata.Data{ @@ -3418,14 +3398,14 @@ func TestDataGetAtPath(t *testing.T) { }, path: path.Root("object"), target: new(types.Object), - expected: &types.Object{ - AttrTypes: map[string]attr.Type{ + expected: pointer(types.ObjectValueMust( + map[string]attr.Type{ "nested_string": types.StringType, }, - Attrs: map[string]attr.Value{ - "nested_string": types.String{Value: "test1"}, + map[string]attr.Value{ + "nested_string": types.StringValue("test1"), }, - }, + )), }, "ObjectType-*struct-null": { data: fwschemadata.Data{ @@ -3569,7 +3549,7 @@ func TestDataGetAtPath(t *testing.T) { expected: pointer(&struct { NestedString types.String `tfsdk:"nested_string"` }{ - NestedString: types.String{Value: "test1"}, + NestedString: types.StringValue("test1"), }), }, "ObjectType-struct-null": { @@ -3727,7 +3707,7 @@ func TestDataGetAtPath(t *testing.T) { expected: &struct { NestedString types.String `tfsdk:"nested_string"` }{ - NestedString: types.String{Value: "test1"}, + NestedString: types.StringValue("test1"), }, }, "SetBlock-types.Set-null": { @@ -3773,14 +3753,13 @@ func TestDataGetAtPath(t *testing.T) { }, path: path.Root("set"), target: new(types.Set), - expected: &types.Set{ - ElemType: types.ObjectType{ + expected: pointer(types.SetNull( + types.ObjectType{ AttrTypes: map[string]attr.Type{ "nested_string": types.StringType, }, }, - Null: true, - }, + )), }, "SetBlock-types.Set-unknown": { data: fwschemadata.Data{ @@ -3825,14 +3804,13 @@ func TestDataGetAtPath(t *testing.T) { }, path: path.Root("set"), target: new(types.Set), - expected: &types.Set{ - ElemType: types.ObjectType{ + expected: pointer(types.SetUnknown( + types.ObjectType{ AttrTypes: map[string]attr.Type{ "nested_string": types.StringType, }, }, - Unknown: true, - }, + )), }, "SetBlock-types.Set-value": { data: fwschemadata.Data{ @@ -3898,31 +3876,31 @@ func TestDataGetAtPath(t *testing.T) { }, path: path.Root("set"), target: new(types.Set), - expected: &types.Set{ - ElemType: types.ObjectType{ + expected: pointer(types.SetValueMust( + types.ObjectType{ AttrTypes: map[string]attr.Type{ "nested_string": types.StringType, }, }, - Elems: []attr.Value{ - types.Object{ - AttrTypes: map[string]attr.Type{ + []attr.Value{ + types.ObjectValueMust( + map[string]attr.Type{ "nested_string": types.StringType, }, - Attrs: map[string]attr.Value{ - "nested_string": types.String{Value: "test1"}, + map[string]attr.Value{ + "nested_string": types.StringValue("test1"), }, - }, - types.Object{ - AttrTypes: map[string]attr.Type{ + ), + types.ObjectValueMust( + map[string]attr.Type{ "nested_string": types.StringType, }, - Attrs: map[string]attr.Value{ - "nested_string": types.String{Value: "test2"}, + map[string]attr.Value{ + "nested_string": types.StringValue("test2"), }, - }, + ), }, - }, + )), }, "SetBlock-[]types.Object-null": { data: fwschemadata.Data{ @@ -4088,22 +4066,22 @@ func TestDataGetAtPath(t *testing.T) { path: path.Root("set"), target: new([]types.Object), expected: &[]types.Object{ - { - AttrTypes: map[string]attr.Type{ + types.ObjectValueMust( + map[string]attr.Type{ "nested_string": types.StringType, }, - Attrs: map[string]attr.Value{ - "nested_string": types.String{Value: "test1"}, + map[string]attr.Value{ + "nested_string": types.StringValue("test1"), }, - }, - { - AttrTypes: map[string]attr.Type{ + ), + types.ObjectValueMust( + map[string]attr.Type{ "nested_string": types.StringType, }, - Attrs: map[string]attr.Value{ - "nested_string": types.String{Value: "test2"}, + map[string]attr.Value{ + "nested_string": types.StringValue("test2"), }, - }, + ), }, }, "SetBlock-[]struct-null": { @@ -4282,8 +4260,8 @@ func TestDataGetAtPath(t *testing.T) { expected: &[]struct { NestedString types.String `tfsdk:"nested_string"` }{ - {NestedString: types.String{Value: "test1"}}, - {NestedString: types.String{Value: "test2"}}, + {NestedString: types.StringValue("test1")}, + {NestedString: types.StringValue("test2")}, }, }, "SetNestedAttributes-types.Set-null": { @@ -4329,14 +4307,13 @@ func TestDataGetAtPath(t *testing.T) { }, path: path.Root("set"), target: new(types.Set), - expected: &types.Set{ - ElemType: types.ObjectType{ + expected: pointer(types.SetNull( + types.ObjectType{ AttrTypes: map[string]attr.Type{ "nested_string": types.StringType, }, }, - Null: true, - }, + )), }, "SetNestedAttributes-types.Set-unknown": { data: fwschemadata.Data{ @@ -4381,14 +4358,13 @@ func TestDataGetAtPath(t *testing.T) { }, path: path.Root("set"), target: new(types.Set), - expected: &types.Set{ - ElemType: types.ObjectType{ + expected: pointer(types.SetUnknown( + types.ObjectType{ AttrTypes: map[string]attr.Type{ "nested_string": types.StringType, }, }, - Unknown: true, - }, + )), }, "SetNestedAttributes-types.Set-value": { data: fwschemadata.Data{ @@ -4454,31 +4430,31 @@ func TestDataGetAtPath(t *testing.T) { }, path: path.Root("set"), target: new(types.Set), - expected: &types.Set{ - ElemType: types.ObjectType{ + expected: pointer(types.SetValueMust( + types.ObjectType{ AttrTypes: map[string]attr.Type{ "nested_string": types.StringType, }, }, - Elems: []attr.Value{ - types.Object{ - AttrTypes: map[string]attr.Type{ + []attr.Value{ + types.ObjectValueMust( + map[string]attr.Type{ "nested_string": types.StringType, }, - Attrs: map[string]attr.Value{ - "nested_string": types.String{Value: "test1"}, + map[string]attr.Value{ + "nested_string": types.StringValue("test1"), }, - }, - types.Object{ - AttrTypes: map[string]attr.Type{ + ), + types.ObjectValueMust( + map[string]attr.Type{ "nested_string": types.StringType, }, - Attrs: map[string]attr.Value{ - "nested_string": types.String{Value: "test2"}, + map[string]attr.Value{ + "nested_string": types.StringValue("test2"), }, - }, + ), }, - }, + )), }, "SetNestedAttributes-[]types.Object-null": { data: fwschemadata.Data{ @@ -4644,22 +4620,22 @@ func TestDataGetAtPath(t *testing.T) { path: path.Root("set"), target: new([]types.Object), expected: &[]types.Object{ - { - AttrTypes: map[string]attr.Type{ + types.ObjectValueMust( + map[string]attr.Type{ "nested_string": types.StringType, }, - Attrs: map[string]attr.Value{ - "nested_string": types.String{Value: "test1"}, + map[string]attr.Value{ + "nested_string": types.StringValue("test1"), }, - }, - { - AttrTypes: map[string]attr.Type{ + ), + types.ObjectValueMust( + map[string]attr.Type{ "nested_string": types.StringType, }, - Attrs: map[string]attr.Value{ - "nested_string": types.String{Value: "test2"}, + map[string]attr.Value{ + "nested_string": types.StringValue("test2"), }, - }, + ), }, }, "SetNestedAttributes-[]struct-null": { @@ -4838,8 +4814,8 @@ func TestDataGetAtPath(t *testing.T) { expected: &[]struct { NestedString types.String `tfsdk:"nested_string"` }{ - {NestedString: types.String{Value: "test1"}}, - {NestedString: types.String{Value: "test2"}}, + {NestedString: types.StringValue("test1")}, + {NestedString: types.StringValue("test2")}, }, }, "SetType-types.Set-null": { @@ -4872,12 +4848,9 @@ func TestDataGetAtPath(t *testing.T) { }, ), }, - path: path.Root("set"), - target: new(types.Set), - expected: &types.Set{ - ElemType: types.StringType, - Null: true, - }, + path: path.Root("set"), + target: new(types.Set), + expected: pointer(types.SetNull(types.StringType)), }, "SetType-types.Set-unknown": { data: fwschemadata.Data{ @@ -4909,12 +4882,9 @@ func TestDataGetAtPath(t *testing.T) { }, ), }, - path: path.Root("set"), - target: new(types.Set), - expected: &types.Set{ - ElemType: types.StringType, - Unknown: true, - }, + path: path.Root("set"), + target: new(types.Set), + expected: pointer(types.SetUnknown(types.StringType)), }, "SetType-types.Set-value": { data: fwschemadata.Data{ @@ -4951,13 +4921,13 @@ func TestDataGetAtPath(t *testing.T) { }, path: path.Root("set"), target: new(types.Set), - expected: &types.Set{ - ElemType: types.StringType, - Elems: []attr.Value{ - types.String{Value: "test1"}, - types.String{Value: "test2"}, + expected: pointer(types.SetValueMust( + types.StringType, + []attr.Value{ + types.StringValue("test1"), + types.StringValue("test2"), }, - }, + )), }, "SetType-[]types.String-null": { data: fwschemadata.Data{ @@ -5072,8 +5042,8 @@ func TestDataGetAtPath(t *testing.T) { path: path.Root("set"), target: new([]types.String), expected: &[]types.String{ - {Value: "test1"}, - {Value: "test2"}, + types.StringValue("test1"), + types.StringValue("test2"), }, }, "SetType-[]string-null": { @@ -5232,12 +5202,11 @@ func TestDataGetAtPath(t *testing.T) { }, path: path.Root("object"), target: new(types.Object), - expected: &types.Object{ - AttrTypes: map[string]attr.Type{ + expected: pointer(types.ObjectNull( + map[string]attr.Type{ "nested_string": types.StringType, }, - Null: true, - }, + )), }, "SingleBlock-types.Object-unknown": { data: fwschemadata.Data{ @@ -5278,12 +5247,11 @@ func TestDataGetAtPath(t *testing.T) { }, path: path.Root("object"), target: new(types.Object), - expected: &types.Object{ - AttrTypes: map[string]attr.Type{ + expected: pointer(types.ObjectUnknown( + map[string]attr.Type{ "nested_string": types.StringType, }, - Unknown: true, - }, + )), }, "SingleBlock-types.Object-value": { data: fwschemadata.Data{ @@ -5326,14 +5294,14 @@ func TestDataGetAtPath(t *testing.T) { }, path: path.Root("object"), target: new(types.Object), - expected: &types.Object{ - AttrTypes: map[string]attr.Type{ + expected: pointer(types.ObjectValueMust( + map[string]attr.Type{ "nested_string": types.StringType, }, - Attrs: map[string]attr.Value{ - "nested_string": types.String{Value: "test1"}, + map[string]attr.Value{ + "nested_string": types.StringValue("test1"), }, - }, + )), }, "SingleBlock-*struct-null": { data: fwschemadata.Data{ @@ -5480,7 +5448,7 @@ func TestDataGetAtPath(t *testing.T) { expected: pointer(&struct { NestedString types.String `tfsdk:"nested_string"` }{ - NestedString: types.String{Value: "test1"}, + NestedString: types.StringValue("test1"), }), }, "SingleBlock-struct-null": { @@ -5641,7 +5609,7 @@ func TestDataGetAtPath(t *testing.T) { expected: &struct { NestedString types.String `tfsdk:"nested_string"` }{ - NestedString: types.String{Value: "test1"}, + NestedString: types.StringValue("test1"), }, }, "SingleNestedAttributes-types.Object-null": { @@ -5683,12 +5651,11 @@ func TestDataGetAtPath(t *testing.T) { }, path: path.Root("object"), target: new(types.Object), - expected: &types.Object{ - AttrTypes: map[string]attr.Type{ + expected: pointer(types.ObjectNull( + map[string]attr.Type{ "nested_string": types.StringType, }, - Null: true, - }, + )), }, "SingleNestedAttributes-types.Object-unknown": { data: fwschemadata.Data{ @@ -5729,12 +5696,11 @@ func TestDataGetAtPath(t *testing.T) { }, path: path.Root("object"), target: new(types.Object), - expected: &types.Object{ - AttrTypes: map[string]attr.Type{ + expected: pointer(types.ObjectUnknown( + map[string]attr.Type{ "nested_string": types.StringType, }, - Unknown: true, - }, + )), }, "SingleNestedAttributes-types.Object-value": { data: fwschemadata.Data{ @@ -5777,14 +5743,14 @@ func TestDataGetAtPath(t *testing.T) { }, path: path.Root("object"), target: new(types.Object), - expected: &types.Object{ - AttrTypes: map[string]attr.Type{ + expected: pointer(types.ObjectValueMust( + map[string]attr.Type{ "nested_string": types.StringType, }, - Attrs: map[string]attr.Value{ - "nested_string": types.String{Value: "test1"}, + map[string]attr.Value{ + "nested_string": types.StringValue("test1"), }, - }, + )), }, "SingleNestedAttributes-*struct-null": { data: fwschemadata.Data{ @@ -5931,7 +5897,7 @@ func TestDataGetAtPath(t *testing.T) { expected: pointer(&struct { NestedString types.String `tfsdk:"nested_string"` }{ - NestedString: types.String{Value: "test1"}, + NestedString: types.StringValue("test1"), }), }, "SingleNestedAttributes-struct-null": { @@ -6092,7 +6058,7 @@ func TestDataGetAtPath(t *testing.T) { expected: &struct { NestedString types.String `tfsdk:"nested_string"` }{ - NestedString: types.String{Value: "test1"}, + NestedString: types.StringValue("test1"), }, }, "StringType-types.string-null": { @@ -6118,7 +6084,7 @@ func TestDataGetAtPath(t *testing.T) { }, path: path.Root("string"), target: new(types.String), - expected: &types.String{Null: true}, + expected: pointer(types.StringNull()), }, "StringType-types.string-unknown": { data: fwschemadata.Data{ @@ -6143,7 +6109,7 @@ func TestDataGetAtPath(t *testing.T) { }, path: path.Root("string"), target: new(types.String), - expected: &types.String{Unknown: true}, + expected: pointer(types.StringUnknown()), }, "StringType-types.string-value": { data: fwschemadata.Data{ @@ -6168,7 +6134,7 @@ func TestDataGetAtPath(t *testing.T) { }, path: path.Root("string"), target: new(types.String), - expected: &types.String{Value: "test"}, + expected: pointer(types.StringValue("test")), }, "StringType-*string-null": { data: fwschemadata.Data{ diff --git a/internal/fwschemadata/data_get_test.go b/internal/fwschemadata/data_get_test.go index d2d68c3d5..8257c6cde 100644 --- a/internal/fwschemadata/data_get_test.go +++ b/internal/fwschemadata/data_get_test.go @@ -144,7 +144,7 @@ func TestDataGet(t *testing.T) { }{ String: testtypes.String{ CreatedBy: testtypes.StringTypeWithValidateError{}, - InternalString: types.String{Value: ""}, + InternalString: types.StringNull(), }, }, expectedDiags: diag.Diagnostics{ @@ -180,7 +180,7 @@ func TestDataGet(t *testing.T) { }{ String: testtypes.String{ CreatedBy: testtypes.StringTypeWithValidateWarning{}, - InternalString: types.String{Value: "test"}, + InternalString: types.StringValue("test"), }, }, expectedDiags: diag.Diagnostics{ @@ -222,8 +222,8 @@ func TestDataGet(t *testing.T) { One types.String `tfsdk:"one"` Two types.String `tfsdk:"two"` }{ - One: types.String{Value: "value1"}, - Two: types.String{Value: "value2"}, + One: types.StringValue("value1"), + Two: types.StringValue("value2"), }, }, "BoolType-types.Bool-null": { @@ -253,7 +253,7 @@ func TestDataGet(t *testing.T) { expected: &struct { Bool types.Bool `tfsdk:"bool"` }{ - Bool: types.Bool{Null: true}, + Bool: types.BoolNull(), }, }, "BoolType-types.Bool-unknown": { @@ -283,7 +283,7 @@ func TestDataGet(t *testing.T) { expected: &struct { Bool types.Bool `tfsdk:"bool"` }{ - Bool: types.Bool{Unknown: true}, + Bool: types.BoolUnknown(), }, }, "BoolType-types.Bool-value": { @@ -313,7 +313,7 @@ func TestDataGet(t *testing.T) { expected: &struct { Bool types.Bool `tfsdk:"bool"` }{ - Bool: types.Bool{Value: true}, + Bool: types.BoolValue(true), }, }, "BoolType-*bool-null": { @@ -550,7 +550,7 @@ func TestDataGet(t *testing.T) { expected: &struct { Float64 types.Float64 `tfsdk:"float64"` }{ - Float64: types.Float64{Null: true}, + Float64: types.Float64Null(), }, }, "Float64Type-types.Float64-unknown": { @@ -580,7 +580,7 @@ func TestDataGet(t *testing.T) { expected: &struct { Float64 types.Float64 `tfsdk:"float64"` }{ - Float64: types.Float64{Unknown: true}, + Float64: types.Float64Unknown(), }, }, "Float64Type-types.Float64-value": { @@ -610,7 +610,7 @@ func TestDataGet(t *testing.T) { expected: &struct { Float64 types.Float64 `tfsdk:"float64"` }{ - Float64: types.Float64{Value: 1.2}, + Float64: types.Float64Value(1.2), }, }, "Float64Type-*float64-null": { @@ -847,7 +847,7 @@ func TestDataGet(t *testing.T) { expected: &struct { Int64 types.Int64 `tfsdk:"int64"` }{ - Int64: types.Int64{Null: true}, + Int64: types.Int64Null(), }, }, "Int64Type-types.Int64-unknown": { @@ -877,7 +877,7 @@ func TestDataGet(t *testing.T) { expected: &struct { Int64 types.Int64 `tfsdk:"int64"` }{ - Int64: types.Int64{Unknown: true}, + Int64: types.Int64Unknown(), }, }, "Int64Type-types.Int64-value": { @@ -907,7 +907,7 @@ func TestDataGet(t *testing.T) { expected: &struct { Int64 types.Int64 `tfsdk:"int64"` }{ - Int64: types.Int64{Value: 12}, + Int64: types.Int64Value(12), }, }, "Int64Type-*int64-null": { @@ -1164,14 +1164,13 @@ func TestDataGet(t *testing.T) { expected: &struct { List types.List `tfsdk:"list"` }{ - List: types.List{ - ElemType: types.ObjectType{ + List: types.ListNull( + types.ObjectType{ AttrTypes: map[string]attr.Type{ "nested_string": types.StringType, }, }, - Null: true, - }, + ), }, }, "ListBlock-types.List-unknown": { @@ -1221,14 +1220,13 @@ func TestDataGet(t *testing.T) { expected: &struct { List types.List `tfsdk:"list"` }{ - List: types.List{ - ElemType: types.ObjectType{ + List: types.ListUnknown( + types.ObjectType{ AttrTypes: map[string]attr.Type{ "nested_string": types.StringType, }, }, - Unknown: true, - }, + ), }, }, "ListBlock-types.List-value": { @@ -1299,31 +1297,31 @@ func TestDataGet(t *testing.T) { expected: &struct { List types.List `tfsdk:"list"` }{ - List: types.List{ - ElemType: types.ObjectType{ + List: types.ListValueMust( + types.ObjectType{ AttrTypes: map[string]attr.Type{ "nested_string": types.StringType, }, }, - Elems: []attr.Value{ - types.Object{ - AttrTypes: map[string]attr.Type{ + []attr.Value{ + types.ObjectValueMust( + map[string]attr.Type{ "nested_string": types.StringType, }, - Attrs: map[string]attr.Value{ - "nested_string": types.String{Value: "test1"}, + map[string]attr.Value{ + "nested_string": types.StringValue("test1"), }, - }, - types.Object{ - AttrTypes: map[string]attr.Type{ + ), + types.ObjectValueMust( + map[string]attr.Type{ "nested_string": types.StringType, }, - Attrs: map[string]attr.Value{ - "nested_string": types.String{Value: "test2"}, + map[string]attr.Value{ + "nested_string": types.StringValue("test2"), }, - }, + ), }, - }, + ), }, }, "ListBlock-[]types.Object-null": { @@ -1504,22 +1502,22 @@ func TestDataGet(t *testing.T) { List []types.Object `tfsdk:"list"` }{ List: []types.Object{ - { - AttrTypes: map[string]attr.Type{ + types.ObjectValueMust( + map[string]attr.Type{ "nested_string": types.StringType, }, - Attrs: map[string]attr.Value{ - "nested_string": types.String{Value: "test1"}, + map[string]attr.Value{ + "nested_string": types.StringValue("test1"), }, - }, - { - AttrTypes: map[string]attr.Type{ + ), + types.ObjectValueMust( + map[string]attr.Type{ "nested_string": types.StringType, }, - Attrs: map[string]attr.Value{ - "nested_string": types.String{Value: "test2"}, + map[string]attr.Value{ + "nested_string": types.StringValue("test2"), }, - }, + ), }, }, }, @@ -1715,8 +1713,8 @@ func TestDataGet(t *testing.T) { List: []struct { NestedString types.String `tfsdk:"nested_string"` }{ - {NestedString: types.String{Value: "test1"}}, - {NestedString: types.String{Value: "test2"}}, + {NestedString: types.StringValue("test1")}, + {NestedString: types.StringValue("test2")}, }, }, }, @@ -1767,14 +1765,13 @@ func TestDataGet(t *testing.T) { expected: &struct { List types.List `tfsdk:"list"` }{ - List: types.List{ - ElemType: types.ObjectType{ + List: types.ListNull( + types.ObjectType{ AttrTypes: map[string]attr.Type{ "nested_string": types.StringType, }, }, - Null: true, - }, + ), }, }, "ListNestedAttributes-types.List-unknown": { @@ -1824,14 +1821,13 @@ func TestDataGet(t *testing.T) { expected: &struct { List types.List `tfsdk:"list"` }{ - List: types.List{ - ElemType: types.ObjectType{ + List: types.ListUnknown( + types.ObjectType{ AttrTypes: map[string]attr.Type{ "nested_string": types.StringType, }, }, - Unknown: true, - }, + ), }, }, "ListNestedAttributes-types.List-value": { @@ -1902,31 +1898,31 @@ func TestDataGet(t *testing.T) { expected: &struct { List types.List `tfsdk:"list"` }{ - List: types.List{ - ElemType: types.ObjectType{ + List: types.ListValueMust( + types.ObjectType{ AttrTypes: map[string]attr.Type{ "nested_string": types.StringType, }, }, - Elems: []attr.Value{ - types.Object{ - AttrTypes: map[string]attr.Type{ + []attr.Value{ + types.ObjectValueMust( + map[string]attr.Type{ "nested_string": types.StringType, }, - Attrs: map[string]attr.Value{ - "nested_string": types.String{Value: "test1"}, + map[string]attr.Value{ + "nested_string": types.StringValue("test1"), }, - }, - types.Object{ - AttrTypes: map[string]attr.Type{ + ), + types.ObjectValueMust( + map[string]attr.Type{ "nested_string": types.StringType, }, - Attrs: map[string]attr.Value{ - "nested_string": types.String{Value: "test2"}, + map[string]attr.Value{ + "nested_string": types.StringValue("test2"), }, - }, + ), }, - }, + ), }, }, "ListNestedAttributes-[]types.Object-null": { @@ -2107,22 +2103,22 @@ func TestDataGet(t *testing.T) { List []types.Object `tfsdk:"list"` }{ List: []types.Object{ - { - AttrTypes: map[string]attr.Type{ + types.ObjectValueMust( + map[string]attr.Type{ "nested_string": types.StringType, }, - Attrs: map[string]attr.Value{ - "nested_string": types.String{Value: "test1"}, + map[string]attr.Value{ + "nested_string": types.StringValue("test1"), }, - }, - { - AttrTypes: map[string]attr.Type{ + ), + types.ObjectValueMust( + map[string]attr.Type{ "nested_string": types.StringType, }, - Attrs: map[string]attr.Value{ - "nested_string": types.String{Value: "test2"}, + map[string]attr.Value{ + "nested_string": types.StringValue("test2"), }, - }, + ), }, }, }, @@ -2318,8 +2314,8 @@ func TestDataGet(t *testing.T) { List: []struct { NestedString types.String `tfsdk:"nested_string"` }{ - {NestedString: types.String{Value: "test1"}}, - {NestedString: types.String{Value: "test2"}}, + {NestedString: types.StringValue("test1")}, + {NestedString: types.StringValue("test2")}, }, }, }, @@ -2359,10 +2355,7 @@ func TestDataGet(t *testing.T) { expected: &struct { List types.List `tfsdk:"list"` }{ - List: types.List{ - ElemType: types.StringType, - Null: true, - }, + List: types.ListNull(types.StringType), }, }, "ListType-types.List-unknown": { @@ -2401,10 +2394,7 @@ func TestDataGet(t *testing.T) { expected: &struct { List types.List `tfsdk:"list"` }{ - List: types.List{ - ElemType: types.StringType, - Unknown: true, - }, + List: types.ListUnknown(types.StringType), }, }, "ListType-types.List-value": { @@ -2446,13 +2436,13 @@ func TestDataGet(t *testing.T) { expected: &struct { List types.List `tfsdk:"list"` }{ - List: types.List{ - ElemType: types.StringType, - Elems: []attr.Value{ - types.String{Value: "test1"}, - types.String{Value: "test2"}, + List: types.ListValueMust( + types.StringType, + []attr.Value{ + types.StringValue("test1"), + types.StringValue("test2"), }, - }, + ), }, }, "ListType-[]types.String-null": { @@ -2582,8 +2572,8 @@ func TestDataGet(t *testing.T) { List []types.String `tfsdk:"list"` }{ List: []types.String{ - {Value: "test1"}, - {Value: "test2"}, + types.StringValue("test1"), + types.StringValue("test2"), }, }, }, @@ -2766,14 +2756,13 @@ func TestDataGet(t *testing.T) { expected: &struct { Map types.Map `tfsdk:"map"` }{ - Map: types.Map{ - ElemType: types.ObjectType{ + Map: types.MapNull( + types.ObjectType{ AttrTypes: map[string]attr.Type{ "nested_string": types.StringType, }, }, - Null: true, - }, + ), }, }, "MapNestedAttributes-types.Map-unknown": { @@ -2823,14 +2812,13 @@ func TestDataGet(t *testing.T) { expected: &struct { Map types.Map `tfsdk:"map"` }{ - Map: types.Map{ - ElemType: types.ObjectType{ + Map: types.MapUnknown( + types.ObjectType{ AttrTypes: map[string]attr.Type{ "nested_string": types.StringType, }, }, - Unknown: true, - }, + ), }, }, "MapNestedAttributes-types.Map-value": { @@ -2901,31 +2889,31 @@ func TestDataGet(t *testing.T) { expected: &struct { Map types.Map `tfsdk:"map"` }{ - Map: types.Map{ - ElemType: types.ObjectType{ + Map: types.MapValueMust( + types.ObjectType{ AttrTypes: map[string]attr.Type{ "nested_string": types.StringType, }, }, - Elems: map[string]attr.Value{ - "key1": types.Object{ - AttrTypes: map[string]attr.Type{ + map[string]attr.Value{ + "key1": types.ObjectValueMust( + map[string]attr.Type{ "nested_string": types.StringType, }, - Attrs: map[string]attr.Value{ - "nested_string": types.String{Value: "value1"}, + map[string]attr.Value{ + "nested_string": types.StringValue("value1"), }, - }, - "key2": types.Object{ - AttrTypes: map[string]attr.Type{ + ), + "key2": types.ObjectValueMust( + map[string]attr.Type{ "nested_string": types.StringType, }, - Attrs: map[string]attr.Value{ - "nested_string": types.String{Value: "value2"}, + map[string]attr.Value{ + "nested_string": types.StringValue("value2"), }, - }, + ), }, - }, + ), }, }, "MapNestedAttributes-map[string]types.Object-null": { @@ -3106,22 +3094,22 @@ func TestDataGet(t *testing.T) { Map map[string]types.Object `tfsdk:"map"` }{ Map: map[string]types.Object{ - "key1": { - AttrTypes: map[string]attr.Type{ + "key1": types.ObjectValueMust( + map[string]attr.Type{ "nested_string": types.StringType, }, - Attrs: map[string]attr.Value{ - "nested_string": types.String{Value: "value1"}, + map[string]attr.Value{ + "nested_string": types.StringValue("value1"), }, - }, - "key2": { - AttrTypes: map[string]attr.Type{ + ), + "key2": types.ObjectValueMust( + map[string]attr.Type{ "nested_string": types.StringType, }, - Attrs: map[string]attr.Value{ - "nested_string": types.String{Value: "value2"}, + map[string]attr.Value{ + "nested_string": types.StringValue("value2"), }, - }, + ), }, }, }, @@ -3317,8 +3305,8 @@ func TestDataGet(t *testing.T) { Map: map[string]struct { NestedString types.String `tfsdk:"nested_string"` }{ - "key1": {NestedString: types.String{Value: "value1"}}, - "key2": {NestedString: types.String{Value: "value2"}}, + "key1": {NestedString: types.StringValue("value1")}, + "key2": {NestedString: types.StringValue("value2")}, }, }, }, @@ -3358,10 +3346,7 @@ func TestDataGet(t *testing.T) { expected: &struct { Map types.Map `tfsdk:"map"` }{ - Map: types.Map{ - ElemType: types.StringType, - Null: true, - }, + Map: types.MapNull(types.StringType), }, }, "MapType-types.Map-unknown": { @@ -3400,10 +3385,7 @@ func TestDataGet(t *testing.T) { expected: &struct { Map types.Map `tfsdk:"map"` }{ - Map: types.Map{ - ElemType: types.StringType, - Unknown: true, - }, + Map: types.MapUnknown(types.StringType), }, }, "MapType-types.Map-value": { @@ -3445,13 +3427,13 @@ func TestDataGet(t *testing.T) { expected: &struct { Map types.Map `tfsdk:"map"` }{ - Map: types.Map{ - ElemType: types.StringType, - Elems: map[string]attr.Value{ - "key1": types.String{Value: "value1"}, - "key2": types.String{Value: "value2"}, + Map: types.MapValueMust( + types.StringType, + map[string]attr.Value{ + "key1": types.StringValue("value1"), + "key2": types.StringValue("value2"), }, - }, + ), }, }, "MapType-map[string]types.String-null": { @@ -3581,8 +3563,8 @@ func TestDataGet(t *testing.T) { Map map[string]types.String `tfsdk:"map"` }{ Map: map[string]types.String{ - "key1": {Value: "value1"}, - "key2": {Value: "value2"}, + "key1": types.StringValue("value1"), + "key2": types.StringValue("value2"), }, }, }, @@ -3760,12 +3742,11 @@ func TestDataGet(t *testing.T) { expected: &struct { Object types.Object `tfsdk:"object"` }{ - Object: types.Object{ - AttrTypes: map[string]attr.Type{ + Object: types.ObjectNull( + map[string]attr.Type{ "nested_string": types.StringType, }, - Null: true, - }, + ), }, }, "ObjectType-types.Object-unknown": { @@ -3810,12 +3791,11 @@ func TestDataGet(t *testing.T) { expected: &struct { Object types.Object `tfsdk:"object"` }{ - Object: types.Object{ - AttrTypes: map[string]attr.Type{ + Object: types.ObjectUnknown( + map[string]attr.Type{ "nested_string": types.StringType, }, - Unknown: true, - }, + ), }, }, "ObjectType-types.Object-value": { @@ -3862,14 +3842,14 @@ func TestDataGet(t *testing.T) { expected: &struct { Object types.Object `tfsdk:"object"` }{ - Object: types.Object{ - AttrTypes: map[string]attr.Type{ + Object: types.ObjectValueMust( + map[string]attr.Type{ "nested_string": types.StringType, }, - Attrs: map[string]attr.Value{ - "nested_string": types.String{Value: "test1"}, + map[string]attr.Value{ + "nested_string": types.StringValue("test1"), }, - }, + ), }, }, "ObjectType-*struct-null": { @@ -4030,7 +4010,7 @@ func TestDataGet(t *testing.T) { Object: &struct { NestedString types.String `tfsdk:"nested_string"` }{ - NestedString: types.String{Value: "test1"}, + NestedString: types.StringValue("test1"), }, }, }, @@ -4209,7 +4189,7 @@ func TestDataGet(t *testing.T) { Object: struct { NestedString types.String `tfsdk:"nested_string"` }{ - NestedString: types.String{Value: "test1"}, + NestedString: types.StringValue("test1"), }, }, }, @@ -4260,14 +4240,13 @@ func TestDataGet(t *testing.T) { expected: &struct { Set types.Set `tfsdk:"set"` }{ - Set: types.Set{ - ElemType: types.ObjectType{ + Set: types.SetNull( + types.ObjectType{ AttrTypes: map[string]attr.Type{ "nested_string": types.StringType, }, }, - Null: true, - }, + ), }, }, "SetBlock-types.Set-unknown": { @@ -4317,14 +4296,13 @@ func TestDataGet(t *testing.T) { expected: &struct { Set types.Set `tfsdk:"set"` }{ - Set: types.Set{ - ElemType: types.ObjectType{ + Set: types.SetUnknown( + types.ObjectType{ AttrTypes: map[string]attr.Type{ "nested_string": types.StringType, }, }, - Unknown: true, - }, + ), }, }, "SetBlock-types.Set-value": { @@ -4395,31 +4373,31 @@ func TestDataGet(t *testing.T) { expected: &struct { Set types.Set `tfsdk:"set"` }{ - Set: types.Set{ - ElemType: types.ObjectType{ + Set: types.SetValueMust( + types.ObjectType{ AttrTypes: map[string]attr.Type{ "nested_string": types.StringType, }, }, - Elems: []attr.Value{ - types.Object{ - AttrTypes: map[string]attr.Type{ + []attr.Value{ + types.ObjectValueMust( + map[string]attr.Type{ "nested_string": types.StringType, }, - Attrs: map[string]attr.Value{ - "nested_string": types.String{Value: "test1"}, + map[string]attr.Value{ + "nested_string": types.StringValue("test1"), }, - }, - types.Object{ - AttrTypes: map[string]attr.Type{ + ), + types.ObjectValueMust( + map[string]attr.Type{ "nested_string": types.StringType, }, - Attrs: map[string]attr.Value{ - "nested_string": types.String{Value: "test2"}, + map[string]attr.Value{ + "nested_string": types.StringValue("test2"), }, - }, + ), }, - }, + ), }, }, "SetBlock-[]types.Object-null": { @@ -4600,22 +4578,22 @@ func TestDataGet(t *testing.T) { Set []types.Object `tfsdk:"set"` }{ Set: []types.Object{ - { - AttrTypes: map[string]attr.Type{ + types.ObjectValueMust( + map[string]attr.Type{ "nested_string": types.StringType, }, - Attrs: map[string]attr.Value{ - "nested_string": types.String{Value: "test1"}, + map[string]attr.Value{ + "nested_string": types.StringValue("test1"), }, - }, - { - AttrTypes: map[string]attr.Type{ + ), + types.ObjectValueMust( + map[string]attr.Type{ "nested_string": types.StringType, }, - Attrs: map[string]attr.Value{ - "nested_string": types.String{Value: "test2"}, + map[string]attr.Value{ + "nested_string": types.StringValue("test2"), }, - }, + ), }, }, }, @@ -4811,8 +4789,8 @@ func TestDataGet(t *testing.T) { Set: []struct { NestedString types.String `tfsdk:"nested_string"` }{ - {NestedString: types.String{Value: "test1"}}, - {NestedString: types.String{Value: "test2"}}, + {NestedString: types.StringValue("test1")}, + {NestedString: types.StringValue("test2")}, }, }, }, @@ -4863,14 +4841,13 @@ func TestDataGet(t *testing.T) { expected: &struct { Set types.Set `tfsdk:"set"` }{ - Set: types.Set{ - ElemType: types.ObjectType{ + Set: types.SetNull( + types.ObjectType{ AttrTypes: map[string]attr.Type{ "nested_string": types.StringType, }, }, - Null: true, - }, + ), }, }, "SetNestedAttributes-types.Set-unknown": { @@ -4920,14 +4897,13 @@ func TestDataGet(t *testing.T) { expected: &struct { Set types.Set `tfsdk:"set"` }{ - Set: types.Set{ - ElemType: types.ObjectType{ + Set: types.SetUnknown( + types.ObjectType{ AttrTypes: map[string]attr.Type{ "nested_string": types.StringType, }, }, - Unknown: true, - }, + ), }, }, "SetNestedAttributes-types.Set-value": { @@ -4998,31 +4974,31 @@ func TestDataGet(t *testing.T) { expected: &struct { Set types.Set `tfsdk:"set"` }{ - Set: types.Set{ - ElemType: types.ObjectType{ + Set: types.SetValueMust( + types.ObjectType{ AttrTypes: map[string]attr.Type{ "nested_string": types.StringType, }, }, - Elems: []attr.Value{ - types.Object{ - AttrTypes: map[string]attr.Type{ + []attr.Value{ + types.ObjectValueMust( + map[string]attr.Type{ "nested_string": types.StringType, }, - Attrs: map[string]attr.Value{ - "nested_string": types.String{Value: "test1"}, + map[string]attr.Value{ + "nested_string": types.StringValue("test1"), }, - }, - types.Object{ - AttrTypes: map[string]attr.Type{ + ), + types.ObjectValueMust( + map[string]attr.Type{ "nested_string": types.StringType, }, - Attrs: map[string]attr.Value{ - "nested_string": types.String{Value: "test2"}, + map[string]attr.Value{ + "nested_string": types.StringValue("test2"), }, - }, + ), }, - }, + ), }, }, "SetNestedAttributes-[]types.Object-null": { @@ -5203,22 +5179,22 @@ func TestDataGet(t *testing.T) { Set []types.Object `tfsdk:"set"` }{ Set: []types.Object{ - { - AttrTypes: map[string]attr.Type{ + types.ObjectValueMust( + map[string]attr.Type{ "nested_string": types.StringType, }, - Attrs: map[string]attr.Value{ - "nested_string": types.String{Value: "test1"}, + map[string]attr.Value{ + "nested_string": types.StringValue("test1"), }, - }, - { - AttrTypes: map[string]attr.Type{ + ), + types.ObjectValueMust( + map[string]attr.Type{ "nested_string": types.StringType, }, - Attrs: map[string]attr.Value{ - "nested_string": types.String{Value: "test2"}, + map[string]attr.Value{ + "nested_string": types.StringValue("test2"), }, - }, + ), }, }, }, @@ -5414,8 +5390,8 @@ func TestDataGet(t *testing.T) { Set: []struct { NestedString types.String `tfsdk:"nested_string"` }{ - {NestedString: types.String{Value: "test1"}}, - {NestedString: types.String{Value: "test2"}}, + {NestedString: types.StringValue("test1")}, + {NestedString: types.StringValue("test2")}, }, }, }, @@ -5455,10 +5431,7 @@ func TestDataGet(t *testing.T) { expected: &struct { Set types.Set `tfsdk:"set"` }{ - Set: types.Set{ - ElemType: types.StringType, - Null: true, - }, + Set: types.SetNull(types.StringType), }, }, "SetType-types.Set-unknown": { @@ -5497,10 +5470,7 @@ func TestDataGet(t *testing.T) { expected: &struct { Set types.Set `tfsdk:"set"` }{ - Set: types.Set{ - ElemType: types.StringType, - Unknown: true, - }, + Set: types.SetUnknown(types.StringType), }, }, "SetType-types.Set-value": { @@ -5542,13 +5512,13 @@ func TestDataGet(t *testing.T) { expected: &struct { Set types.Set `tfsdk:"set"` }{ - Set: types.Set{ - ElemType: types.StringType, - Elems: []attr.Value{ - types.String{Value: "test1"}, - types.String{Value: "test2"}, + Set: types.SetValueMust( + types.StringType, + []attr.Value{ + types.StringValue("test1"), + types.StringValue("test2"), }, - }, + ), }, }, "SetType-[]types.String-null": { @@ -5678,8 +5648,8 @@ func TestDataGet(t *testing.T) { Set []types.String `tfsdk:"set"` }{ Set: []types.String{ - {Value: "test1"}, - {Value: "test2"}, + types.StringValue("test1"), + types.StringValue("test2"), }, }, }, @@ -5858,12 +5828,11 @@ func TestDataGet(t *testing.T) { expected: &struct { Object types.Object `tfsdk:"object"` }{ - Object: types.Object{ - AttrTypes: map[string]attr.Type{ + Object: types.ObjectNull( + map[string]attr.Type{ "nested_string": types.StringType, }, - Null: true, - }, + ), }, }, "SingleBlock-types.Object-unknown": { @@ -5909,12 +5878,11 @@ func TestDataGet(t *testing.T) { expected: &struct { Object types.Object `tfsdk:"object"` }{ - Object: types.Object{ - AttrTypes: map[string]attr.Type{ + Object: types.ObjectUnknown( + map[string]attr.Type{ "nested_string": types.StringType, }, - Unknown: true, - }, + ), }, }, "SingleBlock-types.Object-value": { @@ -5962,14 +5930,14 @@ func TestDataGet(t *testing.T) { expected: &struct { Object types.Object `tfsdk:"object"` }{ - Object: types.Object{ - AttrTypes: map[string]attr.Type{ + Object: types.ObjectValueMust( + map[string]attr.Type{ "nested_string": types.StringType, }, - Attrs: map[string]attr.Value{ - "nested_string": types.String{Value: "test1"}, + map[string]attr.Value{ + "nested_string": types.StringValue("test1"), }, - }, + ), }, }, "SingleBlock-*struct-null": { @@ -6133,7 +6101,7 @@ func TestDataGet(t *testing.T) { Object: &struct { NestedString types.String `tfsdk:"nested_string"` }{ - NestedString: types.String{Value: "test1"}, + NestedString: types.StringValue("test1"), }, }, }, @@ -6315,7 +6283,7 @@ func TestDataGet(t *testing.T) { Object: struct { NestedString types.String `tfsdk:"nested_string"` }{ - NestedString: types.String{Value: "test1"}, + NestedString: types.StringValue("test1"), }, }, }, @@ -6362,12 +6330,11 @@ func TestDataGet(t *testing.T) { expected: &struct { Object types.Object `tfsdk:"object"` }{ - Object: types.Object{ - AttrTypes: map[string]attr.Type{ + Object: types.ObjectNull( + map[string]attr.Type{ "nested_string": types.StringType, }, - Null: true, - }, + ), }, }, "SingleNestedAttributes-types.Object-unknown": { @@ -6413,12 +6380,11 @@ func TestDataGet(t *testing.T) { expected: &struct { Object types.Object `tfsdk:"object"` }{ - Object: types.Object{ - AttrTypes: map[string]attr.Type{ + Object: types.ObjectUnknown( + map[string]attr.Type{ "nested_string": types.StringType, }, - Unknown: true, - }, + ), }, }, "SingleNestedAttributes-types.Object-value": { @@ -6466,14 +6432,14 @@ func TestDataGet(t *testing.T) { expected: &struct { Object types.Object `tfsdk:"object"` }{ - Object: types.Object{ - AttrTypes: map[string]attr.Type{ + Object: types.ObjectValueMust( + map[string]attr.Type{ "nested_string": types.StringType, }, - Attrs: map[string]attr.Value{ - "nested_string": types.String{Value: "test1"}, + map[string]attr.Value{ + "nested_string": types.StringValue("test1"), }, - }, + ), }, }, "SingleNestedAttributes-*struct-null": { @@ -6637,7 +6603,7 @@ func TestDataGet(t *testing.T) { Object: &struct { NestedString types.String `tfsdk:"nested_string"` }{ - NestedString: types.String{Value: "test1"}, + NestedString: types.StringValue("test1"), }, }, }, @@ -6819,7 +6785,7 @@ func TestDataGet(t *testing.T) { Object: struct { NestedString types.String `tfsdk:"nested_string"` }{ - NestedString: types.String{Value: "test1"}, + NestedString: types.StringValue("test1"), }, }, }, @@ -6850,7 +6816,7 @@ func TestDataGet(t *testing.T) { expected: &struct { String types.String `tfsdk:"string"` }{ - String: types.String{Null: true}, + String: types.StringNull(), }, }, "StringType-types.string-unknown": { @@ -6880,7 +6846,7 @@ func TestDataGet(t *testing.T) { expected: &struct { String types.String `tfsdk:"string"` }{ - String: types.String{Unknown: true}, + String: types.StringUnknown(), }, }, "StringType-types.string-value": { @@ -6910,7 +6876,7 @@ func TestDataGet(t *testing.T) { expected: &struct { String types.String `tfsdk:"string"` }{ - String: types.String{Value: "test"}, + String: types.StringValue("test"), }, }, "StringType-*string-null": { diff --git a/internal/fwschemadata/data_path_exists_test.go b/internal/fwschemadata/data_path_exists_test.go index 9cf5bf627..0e141917f 100644 --- a/internal/fwschemadata/data_path_exists_test.go +++ b/internal/fwschemadata/data_path_exists_test.go @@ -373,7 +373,7 @@ func TestDataPathExists(t *testing.T) { }, }, }, - path: path.Root("test").AtSetValue(types.String{Value: "testvalue"}), + path: path.Root("test").AtSetValue(types.StringValue("testvalue")), expected: true, }, "WithAttributeName.WithElementKeyValue-mismatch-child": { @@ -402,7 +402,7 @@ func TestDataPathExists(t *testing.T) { }, }, }, - path: path.Root("test").AtSetValue(types.String{Value: "othervalue"}), + path: path.Root("test").AtSetValue(types.StringValue("othervalue")), expected: false, }, "WithAttributeName.WithElementKeyValue-mismatch-parent": { @@ -423,7 +423,7 @@ func TestDataPathExists(t *testing.T) { }, }, }, - path: path.Root("test").AtSetValue(types.String{Value: "othervalue"}), + path: path.Root("test").AtSetValue(types.StringValue("othervalue")), expected: false, }, } diff --git a/internal/fwschemadata/data_path_matches_test.go b/internal/fwschemadata/data_path_matches_test.go index 9cc45f8e7..0236fbbe8 100644 --- a/internal/fwschemadata/data_path_matches_test.go +++ b/internal/fwschemadata/data_path_matches_test.go @@ -1061,9 +1061,9 @@ func TestDataPathMatches(t *testing.T) { ), expression: path.MatchRoot("test").AtAnySetValue(), expected: path.Paths{ - path.Root("test").AtSetValue(types.String{Value: "test-value1"}), - path.Root("test").AtSetValue(types.String{Value: "test-value2"}), - path.Root("test").AtSetValue(types.String{Value: "test-value3"}), + path.Root("test").AtSetValue(types.StringValue("test-value1")), + path.Root("test").AtSetValue(types.StringValue("test-value2")), + path.Root("test").AtSetValue(types.StringValue("test-value3")), }, }, "AttributeNameExact-ElementKeyValueAny-mismatch": { @@ -1204,9 +1204,9 @@ func TestDataPathMatches(t *testing.T) { ), }, ), - expression: path.MatchRoot("test").AtSetValue(types.String{Value: "test-value2"}), + expression: path.MatchRoot("test").AtSetValue(types.StringValue("test-value2")), expected: path.Paths{ - path.Root("test").AtSetValue(types.String{Value: "test-value2"}), + path.Root("test").AtSetValue(types.StringValue("test-value2")), }, }, "AttributeNameExact-ElementKeyValueExact-mismatch": { @@ -1240,7 +1240,7 @@ func TestDataPathMatches(t *testing.T) { ), }, ), - expression: path.MatchRoot("test").AtSetValue(types.String{Value: "test-value4"}), + expression: path.MatchRoot("test").AtSetValue(types.StringValue("test-value4")), expected: nil, expectedDiags: diag.Diagnostics{ diag.NewErrorDiagnostic( @@ -1279,7 +1279,7 @@ func TestDataPathMatches(t *testing.T) { ), }, ), - expression: path.MatchRoot("test").AtSetValue(types.String{Value: "test-value2"}), + expression: path.MatchRoot("test").AtSetValue(types.StringValue("test-value2")), expected: path.Paths{ path.Root("test"), }, @@ -1311,7 +1311,7 @@ func TestDataPathMatches(t *testing.T) { ), }, ), - expression: path.MatchRoot("test").AtSetValue(types.String{Value: "test-value2"}), + expression: path.MatchRoot("test").AtSetValue(types.StringValue("test-value2")), expected: path.Paths{ path.Root("test"), }, diff --git a/internal/fwschemadata/data_set_at_path_test.go b/internal/fwschemadata/data_set_at_path_test.go index f94906e6b..bce077c28 100644 --- a/internal/fwschemadata/data_set_at_path_test.go +++ b/internal/fwschemadata/data_set_at_path_test.go @@ -579,16 +579,16 @@ func TestDataSetAtPath(t *testing.T) { }, }, }, - path: path.Root("disks").AtSetValue(types.Object{ - AttrTypes: map[string]attr.Type{ + path: path.Root("disks").AtSetValue(types.ObjectValueMust( + map[string]attr.Type{ "id": types.StringType, "delete_with_instance": types.BoolType, }, - Attrs: map[string]attr.Value{ - "id": types.String{Value: "mynewdisk"}, - "delete_with_instance": types.Bool{Value: true}, + map[string]attr.Value{ + "id": types.StringValue("mynewdisk"), + "delete_with_instance": types.BoolValue(true), }, - }), + )), val: struct { ID string `tfsdk:"id"` DeleteWithInstance bool `tfsdk:"delete_with_instance"` @@ -687,16 +687,16 @@ func TestDataSetAtPath(t *testing.T) { }, }, }, - path: path.Root("disks").AtSetValue(types.Object{ - AttrTypes: map[string]attr.Type{ + path: path.Root("disks").AtSetValue(types.ObjectValueMust( + map[string]attr.Type{ "id": types.StringType, "delete_with_instance": types.BoolType, }, - Attrs: map[string]attr.Value{ - "id": types.String{Value: "mynewdisk"}, - "delete_with_instance": types.Bool{Value: true}, + map[string]attr.Value{ + "id": types.StringValue("mynewdisk"), + "delete_with_instance": types.BoolValue(true), }, - }), + )), val: struct { ID string `tfsdk:"id"` DeleteWithInstance bool `tfsdk:"delete_with_instance"` @@ -1331,16 +1331,16 @@ func TestDataSetAtPath(t *testing.T) { }, }, }, - path: path.Root("disks").AtSetValue(types.Object{ - AttrTypes: map[string]attr.Type{ + path: path.Root("disks").AtSetValue(types.ObjectValueMust( + map[string]attr.Type{ "id": types.StringType, "delete_with_instance": types.BoolType, }, - Attrs: map[string]attr.Value{ - "id": types.String{Value: "disk1"}, - "delete_with_instance": types.Bool{Value: false}, + map[string]attr.Value{ + "id": types.StringValue("disk1"), + "delete_with_instance": types.BoolValue(false), }, - }), + )), val: struct { ID string `tfsdk:"id"` DeleteWithInstance bool `tfsdk:"delete_with_instance"` @@ -1425,7 +1425,7 @@ func TestDataSetAtPath(t *testing.T) { }, }, }, - path: path.Root("tags").AtSetValue(types.String{Value: "three"}), + path: path.Root("tags").AtSetValue(types.StringValue("three")), val: "three", expected: tftypes.NewValue(tftypes.Object{ AttributeTypes: map[string]tftypes.Type{ @@ -2205,16 +2205,16 @@ func TestDataSetAtPath(t *testing.T) { }, }, }, - path: path.Root("disks").AtSetValue(types.Object{ - AttrTypes: map[string]attr.Type{ + path: path.Root("disks").AtSetValue(types.ObjectValueMust( + map[string]attr.Type{ "id": types.StringType, "delete_with_instance": types.BoolType, }, - Attrs: map[string]attr.Value{ - "id": types.String{Value: "mynewdisk"}, - "delete_with_instance": types.Bool{Value: true}, + map[string]attr.Value{ + "id": types.StringValue("mynewdisk"), + "delete_with_instance": types.BoolValue(true), }, - }), + )), val: struct { ID string `tfsdk:"id"` DeleteWithInstance bool `tfsdk:"delete_with_instance"` @@ -2284,7 +2284,7 @@ func TestDataSetAtPath(t *testing.T) { }, }, }, - path: path.Root("test").AtSetValue(types.String{Value: "testvalue"}), + path: path.Root("test").AtSetValue(types.StringValue("testvalue")), val: "testvalue", expected: tftypes.NewValue(tftypes.Object{ AttributeTypes: map[string]tftypes.Type{ @@ -2343,16 +2343,16 @@ func TestDataSetAtPath(t *testing.T) { }, }, }, - path: path.Root("disks").AtSetValue(types.Object{ - AttrTypes: map[string]attr.Type{ + path: path.Root("disks").AtSetValue(types.ObjectValueMust( + map[string]attr.Type{ "id": types.StringType, "delete_with_instance": types.BoolType, }, - Attrs: map[string]attr.Value{ - "id": types.String{Value: "mynewdisk"}, - "delete_with_instance": types.Bool{Value: true}, + map[string]attr.Value{ + "id": types.StringValue("mynewdisk"), + "delete_with_instance": types.BoolValue(true), }, - }), + )), val: struct { ID string `tfsdk:"id"` DeleteWithInstance bool `tfsdk:"delete_with_instance"` @@ -2394,16 +2394,16 @@ func TestDataSetAtPath(t *testing.T) { "other": tftypes.NewValue(tftypes.String, nil), }), expectedDiags: diag.Diagnostics{ - testtypes.TestWarningDiagnostic(path.Root("disks").AtSetValue(types.Object{ - AttrTypes: map[string]attr.Type{ + testtypes.TestWarningDiagnostic(path.Root("disks").AtSetValue(types.ObjectValueMust( + map[string]attr.Type{ "id": types.StringType, "delete_with_instance": types.BoolType, }, - Attrs: map[string]attr.Value{ - "id": types.String{Value: "mynewdisk"}, - "delete_with_instance": types.Bool{Value: true}, + map[string]attr.Value{ + "id": types.StringValue("mynewdisk"), + "delete_with_instance": types.BoolValue(true), }, - }).AtName("id")), + )).AtName("id")), }, }, "write-String": { diff --git a/internal/fwschemadata/data_set_test.go b/internal/fwschemadata/data_set_test.go index 2bf49f1c2..d54de09b6 100644 --- a/internal/fwschemadata/data_set_test.go +++ b/internal/fwschemadata/data_set_test.go @@ -106,7 +106,7 @@ func TestDataSet(t *testing.T) { Two *string `tfsdk:"two"` Three string `tfsdk:"three"` }{ - One: types.String{Unknown: true}, + One: types.StringUnknown(), Two: nil, Three: "value3", }, diff --git a/internal/fwschemadata/data_value_test.go b/internal/fwschemadata/data_value_test.go index 791a9475d..5a737c4c5 100644 --- a/internal/fwschemadata/data_value_test.go +++ b/internal/fwschemadata/data_value_test.go @@ -48,7 +48,7 @@ func TestDataValueAtPath(t *testing.T) { }, }, path: path.Root("test"), - expected: types.String{Null: true}, + expected: types.StringNull(), }, "WithAttributeName-nonexistent": { data: fwschemadata.Data{ @@ -110,7 +110,7 @@ func TestDataValueAtPath(t *testing.T) { }, }, path: path.Root("test").AtListIndex(0), - expected: types.String{Null: true}, + expected: types.StringNull(), }, "WithAttributeName-List-WithElementKeyInt": { data: fwschemadata.Data{ @@ -146,7 +146,7 @@ func TestDataValueAtPath(t *testing.T) { }, }, path: path.Root("test").AtListIndex(0), - expected: types.String{Value: "value"}, + expected: types.StringValue("value"), }, "WithAttributeName-ListNestedAttributes-null-WithElementKeyInt-WithAttributeName": { data: fwschemadata.Data{ @@ -190,7 +190,7 @@ func TestDataValueAtPath(t *testing.T) { }, }, path: path.Root("test").AtListIndex(0).AtName("sub_test"), - expected: types.String{Null: true}, + expected: types.StringNull(), }, "WithAttributeName-ListNestedAttributes-null-WithElementKeyInt-WithAttributeName-Object": { data: fwschemadata.Data{ @@ -247,10 +247,9 @@ func TestDataValueAtPath(t *testing.T) { }, }, path: path.Root("test").AtListIndex(0).AtName("sub_test"), - expected: types.Object{ - Null: true, - AttrTypes: map[string]attr.Type{"value": types.StringType}, - }, + expected: types.ObjectNull( + map[string]attr.Type{"value": types.StringType}, + ), }, "WithAttributeName-ListNestedAttributes-WithElementKeyInt-WithAttributeName": { data: fwschemadata.Data{ @@ -302,7 +301,7 @@ func TestDataValueAtPath(t *testing.T) { }, }, path: path.Root("test").AtListIndex(0).AtName("sub_test"), - expected: types.String{Value: "value"}, + expected: types.StringValue("value"), }, "WithAttributeName-ListNestedBlocks-null-WithElementKeyInt-WithAttributeName": { data: fwschemadata.Data{ @@ -371,7 +370,7 @@ func TestDataValueAtPath(t *testing.T) { }, }, path: path.Root("test").AtListIndex(0).AtName("sub_test"), - expected: types.String{Null: true}, + expected: types.StringNull(), }, "WithAttributeName-ListNestedBlocks-WithElementKeyInt-WithAttributeName": { data: fwschemadata.Data{ @@ -448,7 +447,7 @@ func TestDataValueAtPath(t *testing.T) { }, }, path: path.Root("test").AtListIndex(0).AtName("sub_test"), - expected: types.String{Value: "value"}, + expected: types.StringValue("value"), }, "WithAttributeName-Map-null-WithElementKeyString": { data: fwschemadata.Data{ @@ -481,7 +480,7 @@ func TestDataValueAtPath(t *testing.T) { }, }, path: path.Root("test").AtMapKey("sub_test"), - expected: types.String{Null: true}, + expected: types.StringNull(), }, "WithAttributeName-Map-WithElementKeyString": { data: fwschemadata.Data{ @@ -517,7 +516,7 @@ func TestDataValueAtPath(t *testing.T) { }, }, path: path.Root("test").AtMapKey("sub_test"), - expected: types.String{Value: "value"}, + expected: types.StringValue("value"), }, "WithAttributeName-Map-WithElementKeyString-nonexistent": { data: fwschemadata.Data{ @@ -552,7 +551,7 @@ func TestDataValueAtPath(t *testing.T) { }, }, path: path.Root("test").AtMapKey("other"), - expected: types.String{Null: true}, + expected: types.StringNull(), }, "WithAttributeName-MapNestedAttributes-null-WithElementKeyInt-WithAttributeName": { data: fwschemadata.Data{ @@ -596,7 +595,7 @@ func TestDataValueAtPath(t *testing.T) { }, }, path: path.Root("test").AtMapKey("element").AtName("sub_test"), - expected: types.String{Null: true}, + expected: types.StringNull(), }, "WithAttributeName-MapNestedAttributes-WithElementKeyString-WithAttributeName": { data: fwschemadata.Data{ @@ -648,7 +647,7 @@ func TestDataValueAtPath(t *testing.T) { }, }, path: path.Root("test").AtMapKey("element").AtName("sub_test"), - expected: types.String{Value: "value"}, + expected: types.StringValue("value"), }, "WithAttributeName-Object-WithAttributeName": { data: fwschemadata.Data{ @@ -689,7 +688,7 @@ func TestDataValueAtPath(t *testing.T) { }, }, path: path.Root("test").AtName("sub_test"), - expected: types.String{Value: "value"}, + expected: types.StringValue("value"), }, "WithAttributeName-Set-null-WithElementKeyValue": { data: fwschemadata.Data{ @@ -721,8 +720,8 @@ func TestDataValueAtPath(t *testing.T) { }, }, }, - path: path.Root("test").AtSetValue(types.String{Value: "value"}), - expected: types.String{Null: true}, + path: path.Root("test").AtSetValue(types.StringValue("value")), + expected: types.StringNull(), }, "WithAttributeName-Set-WithElementKeyValue": { data: fwschemadata.Data{ @@ -757,8 +756,8 @@ func TestDataValueAtPath(t *testing.T) { }, }, }, - path: path.Root("test").AtSetValue(types.String{Value: "value"}), - expected: types.String{Value: "value"}, + path: path.Root("test").AtSetValue(types.StringValue("value")), + expected: types.StringValue("value"), }, "WithAttributeName-SetNestedAttributes-null-WithElementKeyValue-WithAttributeName": { data: fwschemadata.Data{ @@ -801,15 +800,15 @@ func TestDataValueAtPath(t *testing.T) { }, }, }, - path: path.Root("test").AtSetValue(types.Object{ - AttrTypes: map[string]attr.Type{ + path: path.Root("test").AtSetValue(types.ObjectValueMust( + map[string]attr.Type{ "sub_test": types.StringType, }, - Attrs: map[string]attr.Value{ - "sub_test": types.String{Value: "value"}, + map[string]attr.Value{ + "sub_test": types.StringValue("value"), }, - }).AtName("sub_test"), - expected: types.String{Null: true}, + )).AtName("sub_test"), + expected: types.StringNull(), }, "WithAttributeName-SetNestedAttributes-WithElementKeyValue-WithAttributeName": { data: fwschemadata.Data{ @@ -860,15 +859,15 @@ func TestDataValueAtPath(t *testing.T) { }, }, }, - path: path.Root("test").AtSetValue(types.Object{ - AttrTypes: map[string]attr.Type{ + path: path.Root("test").AtSetValue(types.ObjectValueMust( + map[string]attr.Type{ "sub_test": types.StringType, }, - Attrs: map[string]attr.Value{ - "sub_test": types.String{Value: "value"}, + map[string]attr.Value{ + "sub_test": types.StringValue("value"), }, - }).AtName("sub_test"), - expected: types.String{Value: "value"}, + )).AtName("sub_test"), + expected: types.StringValue("value"), }, "WithAttributeName-SetNestedBlocks-null-WithElementKeyValue-WithAttributeName": { data: fwschemadata.Data{ @@ -936,15 +935,15 @@ func TestDataValueAtPath(t *testing.T) { }, }, }, - path: path.Root("test").AtSetValue(types.Object{ - AttrTypes: map[string]attr.Type{ + path: path.Root("test").AtSetValue(types.ObjectValueMust( + map[string]attr.Type{ "sub_test": types.StringType, }, - Attrs: map[string]attr.Value{ - "sub_test": types.String{Value: "value"}, + map[string]attr.Value{ + "sub_test": types.StringValue("value"), }, - }).AtName("sub_test"), - expected: types.String{Null: true}, + )).AtName("sub_test"), + expected: types.StringNull(), }, "WithAttributeName-SetNestedBlocks-WithElementKeyValue-WithAttributeName": { data: fwschemadata.Data{ @@ -1020,15 +1019,15 @@ func TestDataValueAtPath(t *testing.T) { }, }, }, - path: path.Root("test").AtSetValue(types.Object{ - AttrTypes: map[string]attr.Type{ + path: path.Root("test").AtSetValue(types.ObjectValueMust( + map[string]attr.Type{ "sub_test": types.StringType, }, - Attrs: map[string]attr.Value{ - "sub_test": types.String{Value: "value"}, + map[string]attr.Value{ + "sub_test": types.StringValue("value"), }, - }).AtName("sub_test"), - expected: types.String{Value: "value"}, + )).AtName("sub_test"), + expected: types.StringValue("value"), }, "WithAttributeName-SingleBlock-null-WithAttributeName-Float64": { data: fwschemadata.Data{ @@ -1089,7 +1088,7 @@ func TestDataValueAtPath(t *testing.T) { }, }, path: path.Root("test").AtName("sub_test"), - expected: types.Float64{Null: true}, + expected: types.Float64Null(), }, "WithAttributeName-SingleBlock-null-WithAttributeName-Int64": { data: fwschemadata.Data{ @@ -1150,7 +1149,7 @@ func TestDataValueAtPath(t *testing.T) { }, }, path: path.Root("test").AtName("sub_test"), - expected: types.Int64{Null: true}, + expected: types.Int64Null(), }, "WithAttributeName-SingleBlock-null-WithAttributeName-Set": { data: fwschemadata.Data{ @@ -1223,7 +1222,7 @@ func TestDataValueAtPath(t *testing.T) { }, }, path: path.Root("test").AtName("sub_test"), - expected: types.Set{ElemType: types.StringType, Null: true}, + expected: types.SetNull(types.StringType), }, "WithAttributeName-SingleBlock-null-WithAttributeName-String": { data: fwschemadata.Data{ @@ -1284,7 +1283,7 @@ func TestDataValueAtPath(t *testing.T) { }, }, path: path.Root("test").AtName("sub_test"), - expected: types.String{Null: true}, + expected: types.StringNull(), }, "WithAttributeName-SingleBlock-WithAttributeName": { data: fwschemadata.Data{ @@ -1349,7 +1348,7 @@ func TestDataValueAtPath(t *testing.T) { }, }, path: path.Root("test").AtName("sub_test"), - expected: types.String{Value: "value"}, + expected: types.StringValue("value"), }, "WithAttributeName-SingleNestedAttributes-null-WithAttributeName-Float64": { data: fwschemadata.Data{ @@ -1389,7 +1388,7 @@ func TestDataValueAtPath(t *testing.T) { }, }, path: path.Root("test").AtName("sub_test"), - expected: types.Float64{Null: true}, + expected: types.Float64Null(), }, "WithAttributeName-SingleNestedAttributes-null-WithAttributeName-Int64": { data: fwschemadata.Data{ @@ -1429,7 +1428,7 @@ func TestDataValueAtPath(t *testing.T) { }, }, path: path.Root("test").AtName("sub_test"), - expected: types.Int64{Null: true}, + expected: types.Int64Null(), }, "WithAttributeName-SingleNestedAttributes-null-WithAttributeName-Set": { data: fwschemadata.Data{ @@ -1475,7 +1474,7 @@ func TestDataValueAtPath(t *testing.T) { }, }, path: path.Root("test").AtName("sub_test"), - expected: types.Set{ElemType: types.StringType, Null: true}, + expected: types.SetNull(types.StringType), }, "WithAttributeName-SingleNestedAttributes-null-WithAttributeName-String": { data: fwschemadata.Data{ @@ -1515,7 +1514,7 @@ func TestDataValueAtPath(t *testing.T) { }, }, path: path.Root("test").AtName("sub_test"), - expected: types.String{Null: true}, + expected: types.StringNull(), }, "WithAttributeName-SingleNestedAttributes-WithAttributeName": { data: fwschemadata.Data{ @@ -1557,7 +1556,7 @@ func TestDataValueAtPath(t *testing.T) { }, }, path: path.Root("test").AtName("sub_test"), - expected: types.String{Value: "value"}, + expected: types.StringValue("value"), }, "WithAttributeName-String-null": { data: fwschemadata.Data{ @@ -1584,7 +1583,7 @@ func TestDataValueAtPath(t *testing.T) { }, }, path: path.Root("test"), - expected: types.String{Null: true}, + expected: types.StringNull(), }, "WithAttributeName-String-unknown": { data: fwschemadata.Data{ @@ -1611,7 +1610,7 @@ func TestDataValueAtPath(t *testing.T) { }, }, path: path.Root("test"), - expected: types.String{Unknown: true}, + expected: types.StringUnknown(), }, "WithAttributeName-String-value": { data: fwschemadata.Data{ @@ -1638,7 +1637,7 @@ func TestDataValueAtPath(t *testing.T) { }, }, path: path.Root("test"), - expected: types.String{Value: "value"}, + expected: types.StringValue("value"), }, "AttrTypeWithValidateError": { data: fwschemadata.Data{ @@ -1693,7 +1692,7 @@ func TestDataValueAtPath(t *testing.T) { }, }, path: path.Root("test"), - expected: testtypes.String{InternalString: types.String{Value: "value"}, CreatedBy: testtypes.StringTypeWithValidateWarning{}}, + expected: testtypes.String{InternalString: types.StringValue("value"), CreatedBy: testtypes.StringTypeWithValidateWarning{}}, expectedDiags: diag.Diagnostics{testtypes.TestWarningDiagnostic(path.Root("test"))}, }, } diff --git a/internal/fwschemadata/tftypes_value_test.go b/internal/fwschemadata/tftypes_value_test.go index 9ec2d10f4..8222adace 100644 --- a/internal/fwschemadata/tftypes_value_test.go +++ b/internal/fwschemadata/tftypes_value_test.go @@ -444,7 +444,7 @@ func TestUpsertChildTerraformValue(t *testing.T) { parentValue: tftypes.NewValue(tftypes.Set{ ElementType: tftypes.String, }, nil), - childStep: path.PathStepElementKeyValue{Value: types.String{Value: "one"}}, + childStep: path.PathStepElementKeyValue{Value: types.StringValue("one")}, childValue: tftypes.NewValue(tftypes.String, "one"), expected: tftypes.NewValue(tftypes.Set{ ElementType: tftypes.String, @@ -461,7 +461,7 @@ func TestUpsertChildTerraformValue(t *testing.T) { }, []tftypes.Value{ tftypes.NewValue(tftypes.String, "one"), }), - childStep: path.PathStepElementKeyValue{Value: types.String{Value: "one"}}, + childStep: path.PathStepElementKeyValue{Value: types.StringValue("one")}, childValue: tftypes.NewValue(tftypes.String, "one"), expected: tftypes.NewValue(tftypes.Set{ ElementType: tftypes.String, @@ -478,7 +478,7 @@ func TestUpsertChildTerraformValue(t *testing.T) { }, []tftypes.Value{ tftypes.NewValue(tftypes.String, "one"), }), - childStep: path.PathStepElementKeyValue{Value: types.String{Value: "two"}}, + childStep: path.PathStepElementKeyValue{Value: types.StringValue("two")}, childValue: tftypes.NewValue(tftypes.String, "two"), expected: tftypes.NewValue(tftypes.Set{ ElementType: tftypes.String, diff --git a/internal/fwserver/attr_value.go b/internal/fwserver/attr_value.go index 70731345d..8ee6dd8e6 100644 --- a/internal/fwserver/attr_value.go +++ b/internal/fwserver/attr_value.go @@ -15,7 +15,7 @@ func coerceListValue(schemaPath path.Path, value attr.Value) (types.List, diag.D list, ok := value.(types.List) if !ok { - return types.List{Null: true}, diag.Diagnostics{ + return types.ListNull(nil), diag.Diagnostics{ attributePlanModificationWalkError(schemaPath, value), } } @@ -27,7 +27,7 @@ func coerceMapValue(schemaPath path.Path, value attr.Value) (types.Map, diag.Dia m, ok := value.(types.Map) if !ok { - return types.Map{Null: true}, diag.Diagnostics{ + return types.MapNull(nil), diag.Diagnostics{ attributePlanModificationWalkError(schemaPath, value), } } @@ -39,7 +39,7 @@ func coerceObjectValue(schemaPath path.Path, value attr.Value) (types.Object, di object, ok := value.(types.Object) if !ok { - return types.Object{Null: true}, diag.Diagnostics{ + return types.ObjectNull(nil), diag.Diagnostics{ attributePlanModificationWalkError(schemaPath, value), } } @@ -51,7 +51,7 @@ func coerceSetValue(schemaPath path.Path, value attr.Value) (types.Set, diag.Dia set, ok := value.(types.Set) if !ok { - return types.Set{Null: true}, diag.Diagnostics{ + return types.SetNull(nil), diag.Diagnostics{ attributePlanModificationWalkError(schemaPath, value), } } @@ -80,7 +80,7 @@ func listElemObjectFromTerraformValue(ctx context.Context, schemaPath path.Path, elemValue, err := elemType.ValueFromTerraform(ctx, tftypes.NewValue(elemType.TerraformType(ctx), tfValue)) if err != nil { - return types.Object{Null: true}, diag.Diagnostics{ + return types.ObjectNull(nil), diag.Diagnostics{ attributePlanModificationValueError(ctx, list, description, err), } } @@ -111,7 +111,7 @@ func mapElemObjectFromTerraformValue(ctx context.Context, schemaPath path.Path, elemValue, err := elemType.ValueFromTerraform(ctx, tftypes.NewValue(elemType.TerraformType(ctx), tfValue)) if err != nil { - return types.Object{Null: true}, diag.Diagnostics{ + return types.ObjectNull(nil), diag.Diagnostics{ attributePlanModificationValueError(ctx, m, description, err), } } @@ -170,7 +170,7 @@ func setElemObjectFromTerraformValue(ctx context.Context, schemaPath path.Path, elemValue, err := elemType.ValueFromTerraform(ctx, tftypes.NewValue(elemType.TerraformType(ctx), tfValue)) if err != nil { - return types.Object{Null: true}, diag.Diagnostics{ + return types.ObjectNull(nil), diag.Diagnostics{ attributePlanModificationValueError(ctx, set, description, err), } } diff --git a/internal/fwserver/attribute_plan_modification_test.go b/internal/fwserver/attribute_plan_modification_test.go index 7b00a49b4..e5a280517 100644 --- a/internal/fwserver/attribute_plan_modification_test.go +++ b/internal/fwserver/attribute_plan_modification_test.go @@ -40,13 +40,13 @@ func TestAttributeModifyPlan(t *testing.T) { Required: true, }, req: tfsdk.ModifyAttributePlanRequest{ - AttributeConfig: types.String{Value: "testvalue"}, + AttributeConfig: types.StringValue("testvalue"), AttributePath: path.Root("test"), - AttributePlan: types.String{Value: "testvalue"}, - AttributeState: types.String{Value: "testvalue"}, + AttributePlan: types.StringValue("testvalue"), + AttributeState: types.StringValue("testvalue"), }, expectedResp: ModifyAttributePlanResponse{ - AttributePlan: types.String{Value: "testvalue"}, + AttributePlan: types.StringValue("testvalue"), }, }, "attribute-plan": { @@ -59,10 +59,10 @@ func TestAttributeModifyPlan(t *testing.T) { }, }, req: tfsdk.ModifyAttributePlanRequest{ - AttributeConfig: types.String{Value: "TESTATTRONE"}, + AttributeConfig: types.StringValue("TESTATTRONE"), AttributePath: path.Root("test"), - AttributePlan: types.String{Value: "TESTATTRONE"}, - AttributeState: types.String{Value: "TESTATTRONE"}, + AttributePlan: types.StringValue("TESTATTRONE"), + AttributeState: types.StringValue("TESTATTRONE"), }, expectedResp: ModifyAttributePlanResponse{ AttributePlan: types.StringValue("MODIFIED_TWO"), @@ -78,14 +78,14 @@ func TestAttributeModifyPlan(t *testing.T) { }, }, req: tfsdk.ModifyAttributePlanRequest{ - AttributeConfig: types.String{Value: "TESTATTRONE"}, + AttributeConfig: types.StringValue("TESTATTRONE"), AttributePath: path.Root("test"), - AttributePlan: types.String{Value: "TESTATTRONE"}, - AttributeState: types.String{Value: "TESTATTRONE"}, + AttributePlan: types.StringValue("TESTATTRONE"), + AttributeState: types.StringValue("TESTATTRONE"), Private: testProviderData, }, expectedResp: ModifyAttributePlanResponse{ - AttributePlan: types.String{Value: "TESTATTRONE"}, + AttributePlan: types.StringValue("TESTATTRONE"), Private: testProviderData, }, }, @@ -98,13 +98,13 @@ func TestAttributeModifyPlan(t *testing.T) { }, }, req: tfsdk.ModifyAttributePlanRequest{ - AttributeConfig: types.String{Value: "TESTATTRONE"}, + AttributeConfig: types.StringValue("TESTATTRONE"), AttributePath: path.Root("test"), - AttributePlan: types.String{Value: "TESTATTRONE"}, - AttributeState: types.String{Value: "TESTATTRONE"}, + AttributePlan: types.StringValue("TESTATTRONE"), + AttributeState: types.StringValue("TESTATTRONE"), }, expectedResp: ModifyAttributePlanResponse{ - AttributePlan: types.String{Value: "TESTATTRONE"}, + AttributePlan: types.StringValue("TESTATTRONE"), Private: testProviderData, }, }, @@ -125,58 +125,58 @@ func TestAttributeModifyPlan(t *testing.T) { }, }, req: tfsdk.ModifyAttributePlanRequest{ - AttributeConfig: types.List{ - ElemType: types.ObjectType{ + AttributeConfig: types.ListValueMust( + types.ObjectType{ AttrTypes: map[string]attr.Type{ "nested_attr": types.StringType, }, }, - Elems: []attr.Value{ - types.Object{ - AttrTypes: map[string]attr.Type{ + []attr.Value{ + types.ObjectValueMust( + map[string]attr.Type{ "nested_attr": types.StringType, }, - Attrs: map[string]attr.Value{ - "nested_attr": types.String{Value: "testvalue"}, + map[string]attr.Value{ + "nested_attr": types.StringValue("testvalue"), }, - }, + ), }, - }, + ), AttributePath: path.Root("test"), - AttributePlan: types.List{ - ElemType: types.ObjectType{ + AttributePlan: types.ListValueMust( + types.ObjectType{ AttrTypes: map[string]attr.Type{ "nested_attr": types.StringType, }, }, - Elems: []attr.Value{ - types.Object{ - AttrTypes: map[string]attr.Type{ + []attr.Value{ + types.ObjectValueMust( + map[string]attr.Type{ "nested_attr": types.StringType, }, - Attrs: map[string]attr.Value{ - "nested_attr": types.String{Value: "testvalue"}, + map[string]attr.Value{ + "nested_attr": types.StringValue("testvalue"), }, - }, + ), }, - }, - AttributeState: types.List{ - ElemType: types.ObjectType{ + ), + AttributeState: types.ListValueMust( + types.ObjectType{ AttrTypes: map[string]attr.Type{ "nested_attr": types.StringType, }, }, - Elems: []attr.Value{ - types.Object{ - AttrTypes: map[string]attr.Type{ + []attr.Value{ + types.ObjectValueMust( + map[string]attr.Type{ "nested_attr": types.StringType, }, - Attrs: map[string]attr.Value{ - "nested_attr": types.String{Value: "testvalue"}, + map[string]attr.Value{ + "nested_attr": types.StringValue("testvalue"), }, - }, + ), }, - }, + ), }, expectedResp: ModifyAttributePlanResponse{ AttributePlan: types.ListValueMust( @@ -191,7 +191,7 @@ func TestAttributeModifyPlan(t *testing.T) { "nested_attr": types.StringType, }, map[string]attr.Value{ - "nested_attr": types.String{Value: "testvalue"}, + "nested_attr": types.StringValue("testvalue"), }, ), }, @@ -216,58 +216,58 @@ func TestAttributeModifyPlan(t *testing.T) { }, }, req: tfsdk.ModifyAttributePlanRequest{ - AttributeConfig: types.Set{ - ElemType: types.ObjectType{ + AttributeConfig: types.SetValueMust( + types.ObjectType{ AttrTypes: map[string]attr.Type{ "nested_attr": types.StringType, }, }, - Elems: []attr.Value{ - types.Object{ - AttrTypes: map[string]attr.Type{ + []attr.Value{ + types.ObjectValueMust( + map[string]attr.Type{ "nested_attr": types.StringType, }, - Attrs: map[string]attr.Value{ - "nested_attr": types.String{Value: "testvalue"}, + map[string]attr.Value{ + "nested_attr": types.StringValue("testvalue"), }, - }, + ), }, - }, + ), AttributePath: path.Root("test"), - AttributePlan: types.Set{ - ElemType: types.ObjectType{ + AttributePlan: types.SetValueMust( + types.ObjectType{ AttrTypes: map[string]attr.Type{ "nested_attr": types.StringType, }, }, - Elems: []attr.Value{ - types.Object{ - AttrTypes: map[string]attr.Type{ + []attr.Value{ + types.ObjectValueMust( + map[string]attr.Type{ "nested_attr": types.StringType, }, - Attrs: map[string]attr.Value{ - "nested_attr": types.String{Value: "testvalue"}, + map[string]attr.Value{ + "nested_attr": types.StringValue("testvalue"), }, - }, + ), }, - }, - AttributeState: types.Set{ - ElemType: types.ObjectType{ + ), + AttributeState: types.SetValueMust( + types.ObjectType{ AttrTypes: map[string]attr.Type{ "nested_attr": types.StringType, }, }, - Elems: []attr.Value{ - types.Object{ - AttrTypes: map[string]attr.Type{ + []attr.Value{ + types.ObjectValueMust( + map[string]attr.Type{ "nested_attr": types.StringType, }, - Attrs: map[string]attr.Value{ - "nested_attr": types.String{Value: "testvalue"}, + map[string]attr.Value{ + "nested_attr": types.StringValue("testvalue"), }, - }, + ), }, - }, + ), }, expectedResp: ModifyAttributePlanResponse{ AttributePlan: types.SetValueMust( @@ -282,7 +282,7 @@ func TestAttributeModifyPlan(t *testing.T) { "nested_attr": types.StringType, }, map[string]attr.Value{ - "nested_attr": types.String{Value: "testvalue"}, + "nested_attr": types.StringValue("testvalue"), }, ), }, @@ -308,97 +308,97 @@ func TestAttributeModifyPlan(t *testing.T) { Required: true, }, req: tfsdk.ModifyAttributePlanRequest{ - AttributeConfig: types.Set{ - ElemType: types.ObjectType{ + AttributeConfig: types.SetValueMust( + types.ObjectType{ AttrTypes: map[string]attr.Type{ "nested_computed": types.StringType, "nested_required": types.StringType, }, }, - Elems: []attr.Value{ - types.Object{ - AttrTypes: map[string]attr.Type{ + []attr.Value{ + types.ObjectValueMust( + map[string]attr.Type{ "nested_computed": types.StringType, "nested_required": types.StringType, }, - Attrs: map[string]attr.Value{ - "nested_computed": types.String{Null: true}, - "nested_required": types.String{Value: "testvalue1"}, + map[string]attr.Value{ + "nested_computed": types.StringNull(), + "nested_required": types.StringValue("testvalue1"), }, - }, - types.Object{ - AttrTypes: map[string]attr.Type{ + ), + types.ObjectValueMust( + map[string]attr.Type{ "nested_computed": types.StringType, "nested_required": types.StringType, }, - Attrs: map[string]attr.Value{ - "nested_computed": types.String{Null: true}, - "nested_required": types.String{Value: "testvalue2"}, + map[string]attr.Value{ + "nested_computed": types.StringNull(), + "nested_required": types.StringValue("testvalue2"), }, - }, + ), }, - }, + ), AttributePath: path.Root("test"), - AttributePlan: types.Set{ - ElemType: types.ObjectType{ + AttributePlan: types.SetValueMust( + types.ObjectType{ AttrTypes: map[string]attr.Type{ "nested_computed": types.StringType, "nested_required": types.StringType, }, }, - Elems: []attr.Value{ - types.Object{ - AttrTypes: map[string]attr.Type{ + []attr.Value{ + types.ObjectValueMust( + map[string]attr.Type{ "nested_computed": types.StringType, "nested_required": types.StringType, }, - Attrs: map[string]attr.Value{ - "nested_computed": types.String{Unknown: true}, - "nested_required": types.String{Value: "testvalue1"}, + map[string]attr.Value{ + "nested_computed": types.StringUnknown(), + "nested_required": types.StringValue("testvalue1"), }, - }, - types.Object{ - AttrTypes: map[string]attr.Type{ + ), + types.ObjectValueMust( + map[string]attr.Type{ "nested_computed": types.StringType, "nested_required": types.StringType, }, - Attrs: map[string]attr.Value{ - "nested_computed": types.String{Unknown: true}, - "nested_required": types.String{Value: "testvalue2"}, + map[string]attr.Value{ + "nested_computed": types.StringUnknown(), + "nested_required": types.StringValue("testvalue2"), }, - }, + ), }, - }, - AttributeState: types.Set{ - ElemType: types.ObjectType{ + ), + AttributeState: types.SetValueMust( + types.ObjectType{ AttrTypes: map[string]attr.Type{ "nested_computed": types.StringType, "nested_required": types.StringType, }, }, - Elems: []attr.Value{ - types.Object{ - AttrTypes: map[string]attr.Type{ + []attr.Value{ + types.ObjectValueMust( + map[string]attr.Type{ "nested_computed": types.StringType, "nested_required": types.StringType, }, - Attrs: map[string]attr.Value{ - "nested_computed": types.String{Value: "statevalue1"}, - "nested_required": types.String{Value: "testvalue1"}, + map[string]attr.Value{ + "nested_computed": types.StringValue("statevalue1"), + "nested_required": types.StringValue("testvalue1"), }, - }, - types.Object{ - AttrTypes: map[string]attr.Type{ + ), + types.ObjectValueMust( + map[string]attr.Type{ "nested_computed": types.StringType, "nested_required": types.StringType, }, - Attrs: map[string]attr.Value{ - "nested_computed": types.String{Value: "statevalue2"}, - "nested_required": types.String{Value: "testvalue2"}, + map[string]attr.Value{ + "nested_computed": types.StringValue("statevalue2"), + "nested_required": types.StringValue("testvalue2"), }, - }, + ), }, - }, + ), }, expectedResp: ModifyAttributePlanResponse{ AttributePlan: types.SetValueMust( @@ -415,8 +415,8 @@ func TestAttributeModifyPlan(t *testing.T) { "nested_required": types.StringType, }, map[string]attr.Value{ - "nested_computed": types.String{Value: "statevalue1"}, - "nested_required": types.String{Value: "testvalue1"}, + "nested_computed": types.StringValue("statevalue1"), + "nested_required": types.StringValue("testvalue1"), }, ), types.ObjectValueMust( @@ -425,8 +425,8 @@ func TestAttributeModifyPlan(t *testing.T) { "nested_required": types.StringType, }, map[string]attr.Value{ - "nested_computed": types.String{Value: "statevalue2"}, - "nested_required": types.String{Value: "testvalue2"}, + "nested_computed": types.StringValue("statevalue2"), + "nested_required": types.StringValue("testvalue2"), }, ), }, @@ -451,58 +451,58 @@ func TestAttributeModifyPlan(t *testing.T) { }, }, req: tfsdk.ModifyAttributePlanRequest{ - AttributeConfig: types.Map{ - ElemType: types.ObjectType{ + AttributeConfig: types.MapValueMust( + types.ObjectType{ AttrTypes: map[string]attr.Type{ "nested_attr": types.StringType, }, }, - Elems: map[string]attr.Value{ - "testkey": types.Object{ - AttrTypes: map[string]attr.Type{ + map[string]attr.Value{ + "testkey": types.ObjectValueMust( + map[string]attr.Type{ "nested_attr": types.StringType, }, - Attrs: map[string]attr.Value{ - "nested_attr": types.String{Value: "testvalue"}, + map[string]attr.Value{ + "nested_attr": types.StringValue("testvalue"), }, - }, + ), }, - }, + ), AttributePath: path.Root("test"), - AttributePlan: types.Map{ - ElemType: types.ObjectType{ + AttributePlan: types.MapValueMust( + types.ObjectType{ AttrTypes: map[string]attr.Type{ "nested_attr": types.StringType, }, }, - Elems: map[string]attr.Value{ - "testkey": types.Object{ - AttrTypes: map[string]attr.Type{ + map[string]attr.Value{ + "testkey": types.ObjectValueMust( + map[string]attr.Type{ "nested_attr": types.StringType, }, - Attrs: map[string]attr.Value{ - "nested_attr": types.String{Value: "testvalue"}, + map[string]attr.Value{ + "nested_attr": types.StringValue("testvalue"), }, - }, + ), }, - }, - AttributeState: types.Map{ - ElemType: types.ObjectType{ + ), + AttributeState: types.MapValueMust( + types.ObjectType{ AttrTypes: map[string]attr.Type{ "nested_attr": types.StringType, }, }, - Elems: map[string]attr.Value{ - "testkey": types.Object{ - AttrTypes: map[string]attr.Type{ + map[string]attr.Value{ + "testkey": types.ObjectValueMust( + map[string]attr.Type{ "nested_attr": types.StringType, }, - Attrs: map[string]attr.Value{ - "nested_attr": types.String{Value: "testvalue"}, + map[string]attr.Value{ + "nested_attr": types.StringValue("testvalue"), }, - }, + ), }, - }, + ), }, expectedResp: ModifyAttributePlanResponse{ AttributePlan: types.MapValueMust( @@ -517,7 +517,7 @@ func TestAttributeModifyPlan(t *testing.T) { "nested_attr": types.StringType, }, map[string]attr.Value{ - "nested_attr": types.String{Value: "testvalue"}, + "nested_attr": types.StringValue("testvalue"), }, ), }, @@ -542,31 +542,31 @@ func TestAttributeModifyPlan(t *testing.T) { }, }, req: tfsdk.ModifyAttributePlanRequest{ - AttributeConfig: types.Object{ - AttrTypes: map[string]attr.Type{ + AttributeConfig: types.ObjectValueMust( + map[string]attr.Type{ "testing": types.StringType, }, - Attrs: map[string]attr.Value{ - "testing": types.String{Value: "testvalue"}, + map[string]attr.Value{ + "testing": types.StringValue("testvalue"), }, - }, + ), AttributePath: path.Root("test"), - AttributePlan: types.Object{ - AttrTypes: map[string]attr.Type{ + AttributePlan: types.ObjectValueMust( + map[string]attr.Type{ "testing": types.StringType, }, - Attrs: map[string]attr.Value{ - "testing": types.String{Value: "testvalue"}, + map[string]attr.Value{ + "testing": types.StringValue("testvalue"), }, - }, - AttributeState: types.Object{ - AttrTypes: map[string]attr.Type{ + ), + AttributeState: types.ObjectValueMust( + map[string]attr.Type{ "testing": types.StringType, }, - Attrs: map[string]attr.Value{ - "testing": types.String{Value: "testvalue"}, + map[string]attr.Value{ + "testing": types.StringValue("testvalue"), }, - }, + ), }, expectedResp: ModifyAttributePlanResponse{ AttributePlan: types.ObjectValueMust( @@ -574,7 +574,7 @@ func TestAttributeModifyPlan(t *testing.T) { "testing": types.StringType, }, map[string]attr.Value{ - "testing": types.String{Value: "testvalue"}, + "testing": types.StringValue("testvalue"), }, ), Private: testProviderData, @@ -589,10 +589,10 @@ func TestAttributeModifyPlan(t *testing.T) { }, }, req: tfsdk.ModifyAttributePlanRequest{ - AttributeConfig: types.String{Value: "newtestvalue"}, + AttributeConfig: types.StringValue("newtestvalue"), AttributePath: path.Root("test"), - AttributePlan: types.String{Value: "newtestvalue"}, - AttributeState: types.String{Value: "testvalue"}, + AttributePlan: types.StringValue("newtestvalue"), + AttributeState: types.StringValue("testvalue"), // resource.RequiresReplace() requires non-null plan // and state. Plan: tfsdk.Plan{ @@ -637,7 +637,7 @@ func TestAttributeModifyPlan(t *testing.T) { }, }, expectedResp: ModifyAttributePlanResponse{ - AttributePlan: types.String{Value: "newtestvalue"}, + AttributePlan: types.StringValue("newtestvalue"), RequiresReplace: path.Paths{ path.Root("test"), }, @@ -654,10 +654,10 @@ func TestAttributeModifyPlan(t *testing.T) { }, }, req: tfsdk.ModifyAttributePlanRequest{ - AttributeConfig: types.String{Value: "TESTATTRONE"}, + AttributeConfig: types.StringValue("TESTATTRONE"), AttributePath: path.Root("test"), - AttributePlan: types.String{Value: "TESTATTRONE"}, - AttributeState: types.String{Value: "TESTATTRONE"}, + AttributePlan: types.StringValue("TESTATTRONE"), + AttributeState: types.StringValue("TESTATTRONE"), // resource.RequiresReplace() requires non-null plan // and state. Plan: tfsdk.Plan{ @@ -721,13 +721,13 @@ func TestAttributeModifyPlan(t *testing.T) { }, }, req: tfsdk.ModifyAttributePlanRequest{ - AttributeConfig: types.String{Value: "testvalue"}, + AttributeConfig: types.StringValue("testvalue"), AttributePath: path.Root("test"), - AttributePlan: types.String{Value: "testvalue"}, - AttributeState: types.String{Value: "testvalue"}, + AttributePlan: types.StringValue("testvalue"), + AttributeState: types.StringValue("testvalue"), }, expectedResp: ModifyAttributePlanResponse{ - AttributePlan: types.String{Value: "testvalue"}, + AttributePlan: types.StringValue("testvalue"), Private: testEmptyProviderData, }, }, @@ -741,13 +741,13 @@ func TestAttributeModifyPlan(t *testing.T) { }, }, req: tfsdk.ModifyAttributePlanRequest{ - AttributeConfig: types.String{Value: "TESTDIAG"}, + AttributeConfig: types.StringValue("TESTDIAG"), AttributePath: path.Root("test"), - AttributePlan: types.String{Value: "TESTDIAG"}, - AttributeState: types.String{Value: "TESTDIAG"}, + AttributePlan: types.StringValue("TESTDIAG"), + AttributeState: types.StringValue("TESTDIAG"), }, expectedResp: ModifyAttributePlanResponse{ - AttributePlan: types.String{Value: "TESTDIAG"}, + AttributePlan: types.StringValue("TESTDIAG"), Diagnostics: diag.Diagnostics{ // Diagnostics.Append() deduplicates, so the warning will only // be here once unless the test implementation is changed to @@ -770,13 +770,13 @@ func TestAttributeModifyPlan(t *testing.T) { }, }, req: tfsdk.ModifyAttributePlanRequest{ - AttributeConfig: types.String{Value: "TESTDIAG"}, + AttributeConfig: types.StringValue("TESTDIAG"), AttributePath: path.Root("test"), - AttributePlan: types.String{Value: "TESTDIAG"}, - AttributeState: types.String{Value: "TESTDIAG"}, + AttributePlan: types.StringValue("TESTDIAG"), + AttributeState: types.StringValue("TESTDIAG"), }, expectedResp: ModifyAttributePlanResponse{ - AttributePlan: types.String{Value: "TESTDIAG"}, + AttributePlan: types.StringValue("TESTDIAG"), Diagnostics: diag.Diagnostics{ diag.NewErrorDiagnostic( "Error diag", diff --git a/internal/fwserver/block_plan_modification_test.go b/internal/fwserver/block_plan_modification_test.go index ca5598b04..a34f242dc 100644 --- a/internal/fwserver/block_plan_modification_test.go +++ b/internal/fwserver/block_plan_modification_test.go @@ -86,58 +86,58 @@ func TestBlockModifyPlan(t *testing.T) { modifyAttributePlanRequest := func(attrPath path.Path, schema tfsdk.Schema, values modifyAttributePlanValues) tfsdk.ModifyAttributePlanRequest { return tfsdk.ModifyAttributePlanRequest{ - AttributeConfig: types.List{ - ElemType: types.ObjectType{ + AttributeConfig: types.ListValueMust( + types.ObjectType{ AttrTypes: map[string]attr.Type{ "nested_attr": types.StringType, }, }, - Elems: []attr.Value{ - types.Object{ - AttrTypes: map[string]attr.Type{ + []attr.Value{ + types.ObjectValueMust( + map[string]attr.Type{ "nested_attr": types.StringType, }, - Attrs: map[string]attr.Value{ - "nested_attr": types.String{Value: values.config}, + map[string]attr.Value{ + "nested_attr": types.StringValue(values.config), }, - }, + ), }, - }, + ), AttributePath: attrPath, - AttributePlan: types.List{ - ElemType: types.ObjectType{ + AttributePlan: types.ListValueMust( + types.ObjectType{ AttrTypes: map[string]attr.Type{ "nested_attr": types.StringType, }, }, - Elems: []attr.Value{ - types.Object{ - AttrTypes: map[string]attr.Type{ + []attr.Value{ + types.ObjectValueMust( + map[string]attr.Type{ "nested_attr": types.StringType, }, - Attrs: map[string]attr.Value{ - "nested_attr": types.String{Value: values.plan}, + map[string]attr.Value{ + "nested_attr": types.StringValue(values.plan), }, - }, + ), }, - }, - AttributeState: types.List{ - ElemType: types.ObjectType{ + ), + AttributeState: types.ListValueMust( + types.ObjectType{ AttrTypes: map[string]attr.Type{ "nested_attr": types.StringType, }, }, - Elems: []attr.Value{ - types.Object{ - AttrTypes: map[string]attr.Type{ + []attr.Value{ + types.ObjectValueMust( + map[string]attr.Type{ "nested_attr": types.StringType, }, - Attrs: map[string]attr.Value{ - "nested_attr": types.String{Value: values.state}, + map[string]attr.Value{ + "nested_attr": types.StringValue(values.state), }, - }, + ), }, - }, + ), Config: tfsdk.Config{ Raw: schemaTfValue(values.config), Schema: schema, @@ -207,7 +207,7 @@ func TestBlockModifyPlan(t *testing.T) { "nested_attr": types.StringType, }, map[string]attr.Value{ - "nested_attr": types.String{Value: "testvalue"}, + "nested_attr": types.StringValue("testvalue"), }, ), }, @@ -240,14 +240,13 @@ func TestBlockModifyPlan(t *testing.T) { }, ), expectedResp: ModifyAttributePlanResponse{ - AttributePlan: types.List{ - ElemType: types.ObjectType{ + AttributePlan: types.ListNull( + types.ObjectType{ AttrTypes: map[string]attr.Type{ "nested_attr": types.StringType, }, }, - Null: true, - }, + ), Private: testEmptyProviderData, }, }, @@ -290,7 +289,7 @@ func TestBlockModifyPlan(t *testing.T) { "nested_attr": types.StringType, }, map[string]attr.Value{ - "nested_attr": types.String{Value: "TESTATTRONE"}, + "nested_attr": types.StringValue("TESTATTRONE"), }, ), }, @@ -336,7 +335,7 @@ func TestBlockModifyPlan(t *testing.T) { "nested_attr": types.StringType, }, map[string]attr.Value{ - "nested_attr": types.String{Value: "TESTATTRONE"}, + "nested_attr": types.StringValue("TESTATTRONE"), }, ), }, @@ -361,59 +360,57 @@ func TestBlockModifyPlan(t *testing.T) { }, }, req: tfsdk.ModifyAttributePlanRequest{ - AttributeConfig: types.List{ - ElemType: types.ObjectType{ + AttributeConfig: types.ListValueMust( + types.ObjectType{ AttrTypes: map[string]attr.Type{ "nested_attr": types.StringType, }, }, - Elems: []attr.Value{ - types.Object{ - AttrTypes: map[string]attr.Type{ + []attr.Value{ + types.ObjectValueMust( + map[string]attr.Type{ "nested_attr": types.StringType, }, - Attrs: map[string]attr.Value{ - "nested_attr": types.String{Value: "testvalue"}, + map[string]attr.Value{ + "nested_attr": types.StringValue("testvalue"), }, - }, + ), }, - }, + ), AttributePath: path.Root("test"), - AttributePlan: types.List{ - ElemType: types.ObjectType{ + AttributePlan: types.ListNull( + types.ObjectType{ AttrTypes: map[string]attr.Type{ "nested_attr": types.StringType, }, }, - Null: true, - }, - AttributeState: types.List{ - ElemType: types.ObjectType{ + ), + AttributeState: types.ListValueMust( + types.ObjectType{ AttrTypes: map[string]attr.Type{ "nested_attr": types.StringType, }, }, - Elems: []attr.Value{ - types.Object{ - AttrTypes: map[string]attr.Type{ + []attr.Value{ + types.ObjectValueMust( + map[string]attr.Type{ "nested_attr": types.StringType, }, - Attrs: map[string]attr.Value{ - "nested_attr": types.String{Value: "testvalue"}, + map[string]attr.Value{ + "nested_attr": types.StringValue("testvalue"), }, - }, + ), }, - }, + ), }, expectedResp: ModifyAttributePlanResponse{ - AttributePlan: types.List{ - ElemType: types.ObjectType{ + AttributePlan: types.ListNull( + types.ObjectType{ AttrTypes: map[string]attr.Type{ "nested_attr": types.StringType, }, }, - Null: true, - }, + ), Private: testProviderData, }, }, @@ -434,49 +431,48 @@ func TestBlockModifyPlan(t *testing.T) { }, }, req: tfsdk.ModifyAttributePlanRequest{ - AttributeConfig: types.List{ - ElemType: types.ObjectType{ + AttributeConfig: types.ListValueMust( + types.ObjectType{ AttrTypes: map[string]attr.Type{ "nested_attr": types.StringType, }, }, - Elems: []attr.Value{ - types.Object{ - AttrTypes: map[string]attr.Type{ + []attr.Value{ + types.ObjectValueMust( + map[string]attr.Type{ "nested_attr": types.StringType, }, - Attrs: map[string]attr.Value{ - "nested_attr": types.String{Value: "testvalue"}, + map[string]attr.Value{ + "nested_attr": types.StringValue("testvalue"), }, - }, + ), }, - }, + ), AttributePath: path.Root("test"), - AttributePlan: types.List{ - ElemType: types.ObjectType{ + AttributePlan: types.ListValueMust( + types.ObjectType{ AttrTypes: map[string]attr.Type{ "nested_attr": types.StringType, }, }, - Elems: []attr.Value{ - types.Object{ - AttrTypes: map[string]attr.Type{ + []attr.Value{ + types.ObjectValueMust( + map[string]attr.Type{ "nested_attr": types.StringType, }, - Attrs: map[string]attr.Value{ - "nested_attr": types.String{Value: "testvalue"}, + map[string]attr.Value{ + "nested_attr": types.StringValue("testvalue"), }, - }, + ), }, - }, - AttributeState: types.List{ - ElemType: types.ObjectType{ + ), + AttributeState: types.ListNull( + types.ObjectType{ AttrTypes: map[string]attr.Type{ "nested_attr": types.StringType, }, }, - Null: true, - }, + ), }, expectedResp: ModifyAttributePlanResponse{ AttributePlan: types.ListValueMust( @@ -491,7 +487,7 @@ func TestBlockModifyPlan(t *testing.T) { "nested_attr": types.StringType, }, map[string]attr.Value{ - "nested_attr": types.String{Value: "testvalue"}, + "nested_attr": types.StringValue("testvalue"), }, ), }, @@ -516,58 +512,58 @@ func TestBlockModifyPlan(t *testing.T) { }, }, req: tfsdk.ModifyAttributePlanRequest{ - AttributeConfig: types.List{ - ElemType: types.ObjectType{ + AttributeConfig: types.ListValueMust( + types.ObjectType{ AttrTypes: map[string]attr.Type{ "nested_attr": types.StringType, }, }, - Elems: []attr.Value{ - types.Object{ - AttrTypes: map[string]attr.Type{ + []attr.Value{ + types.ObjectValueMust( + map[string]attr.Type{ "nested_attr": types.StringType, }, - Attrs: map[string]attr.Value{ - "nested_attr": types.String{Value: "testvalue"}, + map[string]attr.Value{ + "nested_attr": types.StringValue("testvalue"), }, - }, + ), }, - }, + ), AttributePath: path.Root("test"), - AttributePlan: types.List{ - ElemType: types.ObjectType{ + AttributePlan: types.ListValueMust( + types.ObjectType{ AttrTypes: map[string]attr.Type{ "nested_attr": types.StringType, }, }, - Elems: []attr.Value{ - types.Object{ - AttrTypes: map[string]attr.Type{ + []attr.Value{ + types.ObjectValueMust( + map[string]attr.Type{ "nested_attr": types.StringType, }, - Attrs: map[string]attr.Value{ - "nested_attr": types.String{Value: "testvalue"}, + map[string]attr.Value{ + "nested_attr": types.StringValue("testvalue"), }, - }, + ), }, - }, - AttributeState: types.List{ - ElemType: types.ObjectType{ + ), + AttributeState: types.ListValueMust( + types.ObjectType{ AttrTypes: map[string]attr.Type{ "nested_attr": types.StringType, }, }, - Elems: []attr.Value{ - types.Object{ - AttrTypes: map[string]attr.Type{ + []attr.Value{ + types.ObjectValueMust( + map[string]attr.Type{ "nested_attr": types.StringType, }, - Attrs: map[string]attr.Value{ - "nested_attr": types.String{Value: "testvalue"}, + map[string]attr.Value{ + "nested_attr": types.StringValue("testvalue"), }, - }, + ), }, - }, + ), }, expectedResp: ModifyAttributePlanResponse{ AttributePlan: types.ListValueMust( @@ -582,7 +578,7 @@ func TestBlockModifyPlan(t *testing.T) { "nested_attr": types.StringType, }, map[string]attr.Value{ - "nested_attr": types.String{Value: "testvalue"}, + "nested_attr": types.StringValue("testvalue"), }, ), }, @@ -607,59 +603,57 @@ func TestBlockModifyPlan(t *testing.T) { }, }, req: tfsdk.ModifyAttributePlanRequest{ - AttributeConfig: types.Set{ - ElemType: types.ObjectType{ + AttributeConfig: types.SetValueMust( + types.ObjectType{ AttrTypes: map[string]attr.Type{ "nested_attr": types.StringType, }, }, - Elems: []attr.Value{ - types.Object{ - AttrTypes: map[string]attr.Type{ + []attr.Value{ + types.ObjectValueMust( + map[string]attr.Type{ "nested_attr": types.StringType, }, - Attrs: map[string]attr.Value{ - "nested_attr": types.String{Value: "testvalue"}, + map[string]attr.Value{ + "nested_attr": types.StringValue("testvalue"), }, - }, + ), }, - }, + ), AttributePath: path.Root("test"), - AttributePlan: types.Set{ - ElemType: types.ObjectType{ + AttributePlan: types.SetNull( + types.ObjectType{ AttrTypes: map[string]attr.Type{ "nested_attr": types.StringType, }, }, - Null: true, - }, - AttributeState: types.Set{ - ElemType: types.ObjectType{ + ), + AttributeState: types.SetValueMust( + types.ObjectType{ AttrTypes: map[string]attr.Type{ "nested_attr": types.StringType, }, }, - Elems: []attr.Value{ - types.Object{ - AttrTypes: map[string]attr.Type{ + []attr.Value{ + types.ObjectValueMust( + map[string]attr.Type{ "nested_attr": types.StringType, }, - Attrs: map[string]attr.Value{ - "nested_attr": types.String{Value: "testvalue"}, + map[string]attr.Value{ + "nested_attr": types.StringValue("testvalue"), }, - }, + ), }, - }, + ), }, expectedResp: ModifyAttributePlanResponse{ - AttributePlan: types.Set{ - ElemType: types.ObjectType{ + AttributePlan: types.SetNull( + types.ObjectType{ AttrTypes: map[string]attr.Type{ "nested_attr": types.StringType, }, }, - Null: true, - }, + ), Private: testProviderData, }, }, @@ -680,49 +674,48 @@ func TestBlockModifyPlan(t *testing.T) { }, }, req: tfsdk.ModifyAttributePlanRequest{ - AttributeConfig: types.Set{ - ElemType: types.ObjectType{ + AttributeConfig: types.SetValueMust( + types.ObjectType{ AttrTypes: map[string]attr.Type{ "nested_attr": types.StringType, }, }, - Elems: []attr.Value{ - types.Object{ - AttrTypes: map[string]attr.Type{ + []attr.Value{ + types.ObjectValueMust( + map[string]attr.Type{ "nested_attr": types.StringType, }, - Attrs: map[string]attr.Value{ - "nested_attr": types.String{Value: "testvalue"}, + map[string]attr.Value{ + "nested_attr": types.StringValue("testvalue"), }, - }, + ), }, - }, + ), AttributePath: path.Root("test"), - AttributePlan: types.Set{ - ElemType: types.ObjectType{ + AttributePlan: types.SetValueMust( + types.ObjectType{ AttrTypes: map[string]attr.Type{ "nested_attr": types.StringType, }, }, - Elems: []attr.Value{ - types.Object{ - AttrTypes: map[string]attr.Type{ + []attr.Value{ + types.ObjectValueMust( + map[string]attr.Type{ "nested_attr": types.StringType, }, - Attrs: map[string]attr.Value{ - "nested_attr": types.String{Value: "testvalue"}, + map[string]attr.Value{ + "nested_attr": types.StringValue("testvalue"), }, - }, + ), }, - }, - AttributeState: types.Set{ - ElemType: types.ObjectType{ + ), + AttributeState: types.SetNull( + types.ObjectType{ AttrTypes: map[string]attr.Type{ "nested_attr": types.StringType, }, }, - Null: true, - }, + ), }, expectedResp: ModifyAttributePlanResponse{ AttributePlan: types.SetValueMust( @@ -737,7 +730,7 @@ func TestBlockModifyPlan(t *testing.T) { "nested_attr": types.StringType, }, map[string]attr.Value{ - "nested_attr": types.String{Value: "testvalue"}, + "nested_attr": types.StringValue("testvalue"), }, ), }, @@ -762,58 +755,58 @@ func TestBlockModifyPlan(t *testing.T) { }, }, req: tfsdk.ModifyAttributePlanRequest{ - AttributeConfig: types.Set{ - ElemType: types.ObjectType{ + AttributeConfig: types.SetValueMust( + types.ObjectType{ AttrTypes: map[string]attr.Type{ "nested_attr": types.StringType, }, }, - Elems: []attr.Value{ - types.Object{ - AttrTypes: map[string]attr.Type{ + []attr.Value{ + types.ObjectValueMust( + map[string]attr.Type{ "nested_attr": types.StringType, }, - Attrs: map[string]attr.Value{ - "nested_attr": types.String{Value: "testvalue"}, + map[string]attr.Value{ + "nested_attr": types.StringValue("testvalue"), }, - }, + ), }, - }, + ), AttributePath: path.Root("test"), - AttributePlan: types.Set{ - ElemType: types.ObjectType{ + AttributePlan: types.SetValueMust( + types.ObjectType{ AttrTypes: map[string]attr.Type{ "nested_attr": types.StringType, }, }, - Elems: []attr.Value{ - types.Object{ - AttrTypes: map[string]attr.Type{ + []attr.Value{ + types.ObjectValueMust( + map[string]attr.Type{ "nested_attr": types.StringType, }, - Attrs: map[string]attr.Value{ - "nested_attr": types.String{Value: "testvalue"}, + map[string]attr.Value{ + "nested_attr": types.StringValue("testvalue"), }, - }, + ), }, - }, - AttributeState: types.Set{ - ElemType: types.ObjectType{ + ), + AttributeState: types.SetValueMust( + types.ObjectType{ AttrTypes: map[string]attr.Type{ "nested_attr": types.StringType, }, }, - Elems: []attr.Value{ - types.Object{ - AttrTypes: map[string]attr.Type{ + []attr.Value{ + types.ObjectValueMust( + map[string]attr.Type{ "nested_attr": types.StringType, }, - Attrs: map[string]attr.Value{ - "nested_attr": types.String{Value: "testvalue"}, + map[string]attr.Value{ + "nested_attr": types.StringValue("testvalue"), }, - }, + ), }, - }, + ), }, expectedResp: ModifyAttributePlanResponse{ AttributePlan: types.SetValueMust( @@ -828,7 +821,7 @@ func TestBlockModifyPlan(t *testing.T) { "nested_attr": types.StringType, }, map[string]attr.Value{ - "nested_attr": types.String{Value: "testvalue"}, + "nested_attr": types.StringValue("testvalue"), }, ), }, @@ -869,8 +862,8 @@ func TestBlockModifyPlan(t *testing.T) { NestingMode: tfsdk.BlockNestingModeList, }, req: tfsdk.ModifyAttributePlanRequest{ - AttributeConfig: types.List{ - ElemType: types.ObjectType{ + AttributeConfig: types.ListValueMust( + types.ObjectType{ AttrTypes: map[string]attr.Type{ "id": types.StringType, "list": types.ListType{ @@ -883,9 +876,9 @@ func TestBlockModifyPlan(t *testing.T) { }, }, }, - Elems: []attr.Value{ - types.Object{ - AttrTypes: map[string]attr.Type{ + []attr.Value{ + types.ObjectValueMust( + map[string]attr.Type{ "id": types.StringType, "list": types.ListType{ ElemType: types.ObjectType{ @@ -896,35 +889,35 @@ func TestBlockModifyPlan(t *testing.T) { }, }, }, - Attrs: map[string]attr.Value{ - "id": types.String{Value: "configvalue"}, - "list": types.List{ - ElemType: types.ObjectType{ + map[string]attr.Value{ + "id": types.StringValue("configvalue"), + "list": types.ListValueMust( + types.ObjectType{ AttrTypes: map[string]attr.Type{ "nested_computed": types.StringType, "nested_required": types.StringType, }, }, - Elems: []attr.Value{ - types.Object{ - AttrTypes: map[string]attr.Type{ + []attr.Value{ + types.ObjectValueMust( + map[string]attr.Type{ "nested_computed": types.StringType, "nested_required": types.StringType, }, - Attrs: map[string]attr.Value{ - "nested_computed": types.String{Null: true}, - "nested_required": types.String{Value: "configvalue"}, + map[string]attr.Value{ + "nested_computed": types.StringNull(), + "nested_required": types.StringValue("configvalue"), }, - }, + ), }, - }, + ), }, - }, + ), }, - }, + ), AttributePath: path.Root("test"), - AttributePlan: types.List{ - ElemType: types.ObjectType{ + AttributePlan: types.ListValueMust( + types.ObjectType{ AttrTypes: map[string]attr.Type{ "id": types.StringType, "list": types.ListType{ @@ -937,9 +930,9 @@ func TestBlockModifyPlan(t *testing.T) { }, }, }, - Elems: []attr.Value{ - types.Object{ - AttrTypes: map[string]attr.Type{ + []attr.Value{ + types.ObjectValueMust( + map[string]attr.Type{ "id": types.StringType, "list": types.ListType{ ElemType: types.ObjectType{ @@ -950,34 +943,34 @@ func TestBlockModifyPlan(t *testing.T) { }, }, }, - Attrs: map[string]attr.Value{ - "id": types.String{Value: "one"}, - "list": types.List{ - ElemType: types.ObjectType{ + map[string]attr.Value{ + "id": types.StringValue("one"), + "list": types.ListValueMust( + types.ObjectType{ AttrTypes: map[string]attr.Type{ "nested_computed": types.StringType, "nested_required": types.StringType, }, }, - Elems: []attr.Value{ - types.Object{ - AttrTypes: map[string]attr.Type{ + []attr.Value{ + types.ObjectValueMust( + map[string]attr.Type{ "nested_computed": types.StringType, "nested_required": types.StringType, }, - Attrs: map[string]attr.Value{ - "nested_computed": types.String{Unknown: true}, - "nested_required": types.String{Value: "configvalue"}, + map[string]attr.Value{ + "nested_computed": types.StringUnknown(), + "nested_required": types.StringValue("configvalue"), }, - }, + ), }, - }, + ), }, - }, + ), }, - }, - AttributeState: types.List{ - ElemType: types.ObjectType{ + ), + AttributeState: types.ListValueMust( + types.ObjectType{ AttrTypes: map[string]attr.Type{ "id": types.StringType, "list": types.ListType{ @@ -990,9 +983,9 @@ func TestBlockModifyPlan(t *testing.T) { }, }, }, - Elems: []attr.Value{ - types.Object{ - AttrTypes: map[string]attr.Type{ + []attr.Value{ + types.ObjectValueMust( + map[string]attr.Type{ "id": types.StringType, "list": types.ListType{ ElemType: types.ObjectType{ @@ -1003,32 +996,32 @@ func TestBlockModifyPlan(t *testing.T) { }, }, }, - Attrs: map[string]attr.Value{ - "id": types.String{Value: "one"}, - "list": types.List{ - ElemType: types.ObjectType{ + map[string]attr.Value{ + "id": types.StringValue("one"), + "list": types.ListValueMust( + types.ObjectType{ AttrTypes: map[string]attr.Type{ "nested_computed": types.StringType, "nested_required": types.StringType, }, }, - Elems: []attr.Value{ - types.Object{ - AttrTypes: map[string]attr.Type{ + []attr.Value{ + types.ObjectValueMust( + map[string]attr.Type{ "nested_computed": types.StringType, "nested_required": types.StringType, }, - Attrs: map[string]attr.Value{ - "nested_computed": types.String{Value: "statevalue"}, - "nested_required": types.String{Value: "configvalue"}, + map[string]attr.Value{ + "nested_computed": types.StringValue("statevalue"), + "nested_required": types.StringValue("configvalue"), }, - }, + ), }, - }, + ), }, - }, + ), }, - }, + ), }, expectedResp: ModifyAttributePlanResponse{ AttributePlan: types.ListValueMust( @@ -1059,7 +1052,7 @@ func TestBlockModifyPlan(t *testing.T) { }, }, map[string]attr.Value{ - "id": types.String{Value: "one"}, + "id": types.StringValue("one"), "list": types.ListValueMust( types.ObjectType{ AttrTypes: map[string]attr.Type{ @@ -1074,8 +1067,8 @@ func TestBlockModifyPlan(t *testing.T) { "nested_required": types.StringType, }, map[string]attr.Value{ - "nested_computed": types.String{Value: "statevalue"}, - "nested_required": types.String{Value: "configvalue"}, + "nested_computed": types.StringValue("statevalue"), + "nested_required": types.StringValue("configvalue"), }, ), }, @@ -1105,97 +1098,97 @@ func TestBlockModifyPlan(t *testing.T) { NestingMode: tfsdk.BlockNestingModeSet, }, req: tfsdk.ModifyAttributePlanRequest{ - AttributeConfig: types.Set{ - ElemType: types.ObjectType{ + AttributeConfig: types.SetValueMust( + types.ObjectType{ AttrTypes: map[string]attr.Type{ "nested_computed": types.StringType, "nested_required": types.StringType, }, }, - Elems: []attr.Value{ - types.Object{ - AttrTypes: map[string]attr.Type{ + []attr.Value{ + types.ObjectValueMust( + map[string]attr.Type{ "nested_computed": types.StringType, "nested_required": types.StringType, }, - Attrs: map[string]attr.Value{ - "nested_computed": types.String{Null: true}, - "nested_required": types.String{Value: "testvalue1"}, + map[string]attr.Value{ + "nested_computed": types.StringNull(), + "nested_required": types.StringValue("testvalue1"), }, - }, - types.Object{ - AttrTypes: map[string]attr.Type{ + ), + types.ObjectValueMust( + map[string]attr.Type{ "nested_computed": types.StringType, "nested_required": types.StringType, }, - Attrs: map[string]attr.Value{ - "nested_computed": types.String{Null: true}, - "nested_required": types.String{Value: "testvalue2"}, + map[string]attr.Value{ + "nested_computed": types.StringNull(), + "nested_required": types.StringValue("testvalue2"), }, - }, + ), }, - }, + ), AttributePath: path.Root("test"), - AttributePlan: types.Set{ - ElemType: types.ObjectType{ + AttributePlan: types.SetValueMust( + types.ObjectType{ AttrTypes: map[string]attr.Type{ "nested_computed": types.StringType, "nested_required": types.StringType, }, }, - Elems: []attr.Value{ - types.Object{ - AttrTypes: map[string]attr.Type{ + []attr.Value{ + types.ObjectValueMust( + map[string]attr.Type{ "nested_computed": types.StringType, "nested_required": types.StringType, }, - Attrs: map[string]attr.Value{ - "nested_computed": types.String{Unknown: true}, - "nested_required": types.String{Value: "testvalue1"}, + map[string]attr.Value{ + "nested_computed": types.StringUnknown(), + "nested_required": types.StringValue("testvalue1"), }, - }, - types.Object{ - AttrTypes: map[string]attr.Type{ + ), + types.ObjectValueMust( + map[string]attr.Type{ "nested_computed": types.StringType, "nested_required": types.StringType, }, - Attrs: map[string]attr.Value{ - "nested_computed": types.String{Unknown: true}, - "nested_required": types.String{Value: "testvalue2"}, + map[string]attr.Value{ + "nested_computed": types.StringUnknown(), + "nested_required": types.StringValue("testvalue2"), }, - }, + ), }, - }, - AttributeState: types.Set{ - ElemType: types.ObjectType{ + ), + AttributeState: types.SetValueMust( + types.ObjectType{ AttrTypes: map[string]attr.Type{ "nested_computed": types.StringType, "nested_required": types.StringType, }, }, - Elems: []attr.Value{ - types.Object{ - AttrTypes: map[string]attr.Type{ + []attr.Value{ + types.ObjectValueMust( + map[string]attr.Type{ "nested_computed": types.StringType, "nested_required": types.StringType, }, - Attrs: map[string]attr.Value{ - "nested_computed": types.String{Value: "statevalue1"}, - "nested_required": types.String{Value: "testvalue1"}, + map[string]attr.Value{ + "nested_computed": types.StringValue("statevalue1"), + "nested_required": types.StringValue("testvalue1"), }, - }, - types.Object{ - AttrTypes: map[string]attr.Type{ + ), + types.ObjectValueMust( + map[string]attr.Type{ "nested_computed": types.StringType, "nested_required": types.StringType, }, - Attrs: map[string]attr.Value{ - "nested_computed": types.String{Value: "statevalue2"}, - "nested_required": types.String{Value: "testvalue2"}, + map[string]attr.Value{ + "nested_computed": types.StringValue("statevalue2"), + "nested_required": types.StringValue("testvalue2"), }, - }, + ), }, - }, + ), }, expectedResp: ModifyAttributePlanResponse{ AttributePlan: types.SetValueMust( @@ -1212,8 +1205,8 @@ func TestBlockModifyPlan(t *testing.T) { "nested_required": types.StringType, }, map[string]attr.Value{ - "nested_computed": types.String{Value: "statevalue1"}, - "nested_required": types.String{Value: "testvalue1"}, + "nested_computed": types.StringValue("statevalue1"), + "nested_required": types.StringValue("testvalue1"), }, ), types.ObjectValueMust( @@ -1222,8 +1215,8 @@ func TestBlockModifyPlan(t *testing.T) { "nested_required": types.StringType, }, map[string]attr.Value{ - "nested_computed": types.String{Value: "statevalue2"}, - "nested_required": types.String{Value: "testvalue2"}, + "nested_computed": types.StringValue("statevalue2"), + "nested_required": types.StringValue("testvalue2"), }, ), }, @@ -1248,37 +1241,35 @@ func TestBlockModifyPlan(t *testing.T) { }, }, req: tfsdk.ModifyAttributePlanRequest{ - AttributeConfig: types.Object{ - AttrTypes: map[string]attr.Type{ + AttributeConfig: types.ObjectValueMust( + map[string]attr.Type{ "nested_attr": types.StringType, }, - Attrs: map[string]attr.Value{ - "nested_attr": types.String{Value: "testvalue"}, + map[string]attr.Value{ + "nested_attr": types.StringValue("testvalue"), }, - }, + ), AttributePath: path.Root("test"), - AttributePlan: types.Object{ - AttrTypes: map[string]attr.Type{ + AttributePlan: types.ObjectNull( + map[string]attr.Type{ "nested_attr": types.StringType, }, - Null: true, - }, - AttributeState: types.Object{ - AttrTypes: map[string]attr.Type{ + ), + AttributeState: types.ObjectValueMust( + map[string]attr.Type{ "nested_attr": types.StringType, }, - Attrs: map[string]attr.Value{ - "nested_attr": types.String{Value: "testvalue"}, + map[string]attr.Value{ + "nested_attr": types.StringValue("testvalue"), }, - }, + ), }, expectedResp: ModifyAttributePlanResponse{ - AttributePlan: types.Object{ - AttrTypes: map[string]attr.Type{ + AttributePlan: types.ObjectNull( + map[string]attr.Type{ "nested_attr": types.StringType, }, - Null: true, - }, + ), Private: testProviderData, }, }, @@ -1299,29 +1290,28 @@ func TestBlockModifyPlan(t *testing.T) { }, }, req: tfsdk.ModifyAttributePlanRequest{ - AttributeConfig: types.Object{ - AttrTypes: map[string]attr.Type{ + AttributeConfig: types.ObjectValueMust( + map[string]attr.Type{ "nested_attr": types.StringType, }, - Attrs: map[string]attr.Value{ - "nested_attr": types.String{Value: "testvalue"}, + map[string]attr.Value{ + "nested_attr": types.StringValue("testvalue"), }, - }, + ), AttributePath: path.Root("test"), - AttributePlan: types.Object{ - AttrTypes: map[string]attr.Type{ + AttributePlan: types.ObjectValueMust( + map[string]attr.Type{ "nested_attr": types.StringType, }, - Attrs: map[string]attr.Value{ - "nested_attr": types.String{Value: "testvalue"}, + map[string]attr.Value{ + "nested_attr": types.StringValue("testvalue"), }, - }, - AttributeState: types.Object{ - AttrTypes: map[string]attr.Type{ + ), + AttributeState: types.ObjectNull( + map[string]attr.Type{ "nested_attr": types.StringType, }, - Null: true, - }, + ), }, expectedResp: ModifyAttributePlanResponse{ AttributePlan: types.ObjectValueMust( @@ -1329,7 +1319,7 @@ func TestBlockModifyPlan(t *testing.T) { "nested_attr": types.StringType, }, map[string]attr.Value{ - "nested_attr": types.String{Value: "testvalue"}, + "nested_attr": types.StringValue("testvalue"), }, ), Private: testProviderData, @@ -1352,31 +1342,31 @@ func TestBlockModifyPlan(t *testing.T) { }, }, req: tfsdk.ModifyAttributePlanRequest{ - AttributeConfig: types.Object{ - AttrTypes: map[string]attr.Type{ + AttributeConfig: types.ObjectValueMust( + map[string]attr.Type{ "nested_attr": types.StringType, }, - Attrs: map[string]attr.Value{ - "nested_attr": types.String{Value: "testvalue"}, + map[string]attr.Value{ + "nested_attr": types.StringValue("testvalue"), }, - }, + ), AttributePath: path.Root("test"), - AttributePlan: types.Object{ - AttrTypes: map[string]attr.Type{ + AttributePlan: types.ObjectValueMust( + map[string]attr.Type{ "nested_attr": types.StringType, }, - Attrs: map[string]attr.Value{ - "nested_attr": types.String{Value: "testvalue"}, + map[string]attr.Value{ + "nested_attr": types.StringValue("testvalue"), }, - }, - AttributeState: types.Object{ - AttrTypes: map[string]attr.Type{ + ), + AttributeState: types.ObjectValueMust( + map[string]attr.Type{ "nested_attr": types.StringType, }, - Attrs: map[string]attr.Value{ - "nested_attr": types.String{Value: "testvalue"}, + map[string]attr.Value{ + "nested_attr": types.StringValue("testvalue"), }, - }, + ), }, expectedResp: ModifyAttributePlanResponse{ AttributePlan: types.ObjectValueMust( @@ -1384,7 +1374,7 @@ func TestBlockModifyPlan(t *testing.T) { "nested_attr": types.StringType, }, map[string]attr.Value{ - "nested_attr": types.String{Value: "testvalue"}, + "nested_attr": types.StringValue("testvalue"), }, ), Private: testProviderData, @@ -1408,37 +1398,37 @@ func TestBlockModifyPlan(t *testing.T) { NestingMode: tfsdk.BlockNestingModeSingle, }, req: tfsdk.ModifyAttributePlanRequest{ - AttributeConfig: types.Object{ - AttrTypes: map[string]attr.Type{ + AttributeConfig: types.ObjectValueMust( + map[string]attr.Type{ "nested_computed": types.StringType, "nested_required": types.StringType, }, - Attrs: map[string]attr.Value{ - "nested_computed": types.String{Null: true}, - "nested_required": types.String{Value: "testvalue"}, + map[string]attr.Value{ + "nested_computed": types.StringNull(), + "nested_required": types.StringValue("testvalue"), }, - }, + ), AttributePath: path.Root("test"), - AttributePlan: types.Object{ - AttrTypes: map[string]attr.Type{ + AttributePlan: types.ObjectValueMust( + map[string]attr.Type{ "nested_computed": types.StringType, "nested_required": types.StringType, }, - Attrs: map[string]attr.Value{ - "nested_computed": types.String{Unknown: true}, - "nested_required": types.String{Value: "testvalue"}, + map[string]attr.Value{ + "nested_computed": types.StringUnknown(), + "nested_required": types.StringValue("testvalue"), }, - }, - AttributeState: types.Object{ - AttrTypes: map[string]attr.Type{ + ), + AttributeState: types.ObjectValueMust( + map[string]attr.Type{ "nested_computed": types.StringType, "nested_required": types.StringType, }, - Attrs: map[string]attr.Value{ - "nested_computed": types.String{Value: "statevalue"}, - "nested_required": types.String{Value: "testvalue"}, + map[string]attr.Value{ + "nested_computed": types.StringValue("statevalue"), + "nested_required": types.StringValue("testvalue"), }, - }, + ), }, expectedResp: ModifyAttributePlanResponse{ AttributePlan: types.ObjectValueMust( @@ -1447,8 +1437,8 @@ func TestBlockModifyPlan(t *testing.T) { "nested_required": types.StringType, }, map[string]attr.Value{ - "nested_computed": types.String{Value: "statevalue"}, - "nested_required": types.String{Value: "testvalue"}, + "nested_computed": types.StringValue("statevalue"), + "nested_required": types.StringValue("testvalue"), }, ), Private: testEmptyProviderData, @@ -1491,7 +1481,7 @@ func TestBlockModifyPlan(t *testing.T) { "nested_attr": types.StringType, }, map[string]attr.Value{ - "nested_attr": types.String{Value: "newtestvalue"}, + "nested_attr": types.StringValue("newtestvalue"), }, ), }, @@ -1529,14 +1519,13 @@ func TestBlockModifyPlan(t *testing.T) { }, ), expectedResp: ModifyAttributePlanResponse{ - AttributePlan: types.List{ - ElemType: types.ObjectType{ + AttributePlan: types.ListNull( + types.ObjectType{ AttrTypes: map[string]attr.Type{ "nested_attr": types.StringType, }, }, - Null: true, - }, + ), RequiresReplace: path.Paths{ path.Root("test"), }, @@ -1582,7 +1571,7 @@ func TestBlockModifyPlan(t *testing.T) { "nested_attr": types.StringType, }, map[string]attr.Value{ - "nested_attr": types.String{Value: "newtestvalue"}, + "nested_attr": types.StringValue("newtestvalue"), }, ), }, @@ -1638,7 +1627,7 @@ func TestBlockModifyPlan(t *testing.T) { "nested_attr": types.StringType, }, map[string]attr.Value{ - "nested_attr": types.String{Value: "TESTDIAG"}, + "nested_attr": types.StringValue("TESTDIAG"), }, ), }, @@ -1679,23 +1668,23 @@ func TestBlockModifyPlan(t *testing.T) { "This is an error", ), }, - AttributePlan: types.List{ - ElemType: types.ObjectType{ + AttributePlan: types.ListValueMust( + types.ObjectType{ AttrTypes: map[string]attr.Type{ "nested_attr": types.StringType, }, }, - Elems: []attr.Value{ - types.Object{ - AttrTypes: map[string]attr.Type{ + []attr.Value{ + types.ObjectValueMust( + map[string]attr.Type{ "nested_attr": types.StringType, }, - Attrs: map[string]attr.Value{ - "nested_attr": types.String{Value: "TESTDIAG"}, + map[string]attr.Value{ + "nested_attr": types.StringValue("TESTDIAG"), }, - }, + ), }, - }, + ), Private: testEmptyProviderData, }, }, @@ -1783,7 +1772,7 @@ func TestBlockModifyPlan(t *testing.T) { "nested_attr": types.StringType, }, map[string]attr.Value{ - "nested_attr": types.String{Value: "newtestvalue"}, + "nested_attr": types.StringValue("newtestvalue"), }, ), }, @@ -1883,7 +1872,7 @@ func TestBlockModifyPlan(t *testing.T) { "nested_attr": types.StringType, }, map[string]attr.Value{ - "nested_attr": types.String{Value: "newtestvalue"}, + "nested_attr": types.StringValue("newtestvalue"), }, ), }, @@ -1939,7 +1928,7 @@ func TestBlockModifyPlan(t *testing.T) { "nested_attr": types.StringType, }, map[string]attr.Value{ - "nested_attr": types.String{Value: "TESTDIAG"}, + "nested_attr": types.StringValue("TESTDIAG"), }, ), }, @@ -1980,23 +1969,23 @@ func TestBlockModifyPlan(t *testing.T) { "This is an error", ), }, - AttributePlan: types.List{ - ElemType: types.ObjectType{ + AttributePlan: types.ListValueMust( + types.ObjectType{ AttrTypes: map[string]attr.Type{ "nested_attr": types.StringType, }, }, - Elems: []attr.Value{ + []attr.Value{ types.ObjectValueMust( map[string]attr.Type{ "nested_attr": types.StringType, }, map[string]attr.Value{ - "nested_attr": types.String{Value: "TESTDIAG"}, + "nested_attr": types.StringValue("TESTDIAG"), }, ), }, - }, + ), Private: testEmptyProviderData, }, }, @@ -2029,14 +2018,13 @@ func (t testBlockPlanModifierNullList) Modify(ctx context.Context, req tfsdk.Mod return } - resp.AttributePlan = types.List{ - ElemType: types.ObjectType{ + resp.AttributePlan = types.ListNull( + types.ObjectType{ AttrTypes: map[string]attr.Type{ "nested_attr": types.StringType, }, }, - Null: true, - } + ) } func (t testBlockPlanModifierNullList) Description(ctx context.Context) string { diff --git a/internal/fwserver/server_applyresourcechange_test.go b/internal/fwserver/server_applyresourcechange_test.go index b10e5ba15..7b730dafe 100644 --- a/internal/fwserver/server_applyresourcechange_test.go +++ b/internal/fwserver/server_applyresourcechange_test.go @@ -418,8 +418,8 @@ func TestServerApplyResourceChange(t *testing.T) { expectedResponse: &fwserver.ApplyResourceChangeResponse{ NewState: &tfsdk.State{ Raw: tftypes.NewValue(testSchemaType, map[string]tftypes.Value{ - "test_computed": tftypes.NewValue(tftypes.String, ""), - "test_required": tftypes.NewValue(tftypes.String, ""), + "test_computed": tftypes.NewValue(tftypes.String, nil), + "test_required": tftypes.NewValue(tftypes.String, nil), }), Schema: testSchema, }, diff --git a/internal/fwserver/server_createresource_test.go b/internal/fwserver/server_createresource_test.go index 6e13d494c..4967992bb 100644 --- a/internal/fwserver/server_createresource_test.go +++ b/internal/fwserver/server_createresource_test.go @@ -393,8 +393,8 @@ func TestServerCreateResource(t *testing.T) { expectedResponse: &fwserver.CreateResourceResponse{ NewState: &tfsdk.State{ Raw: tftypes.NewValue(testSchemaType, map[string]tftypes.Value{ - "test_computed": tftypes.NewValue(tftypes.String, ""), - "test_required": tftypes.NewValue(tftypes.String, ""), + "test_computed": tftypes.NewValue(tftypes.String, nil), + "test_required": tftypes.NewValue(tftypes.String, nil), }), Schema: testSchema, }, diff --git a/internal/fwserver/server_planresourcechange_test.go b/internal/fwserver/server_planresourcechange_test.go index ee0e14c48..596bc6ce1 100644 --- a/internal/fwserver/server_planresourcechange_test.go +++ b/internal/fwserver/server_planresourcechange_test.go @@ -316,7 +316,7 @@ func TestServerPlanResourceChange(t *testing.T) { PlanModifiers: tfsdk.AttributePlanModifiers{ &testprovider.AttributePlanModifier{ ModifyMethod: func(ctx context.Context, req tfsdk.ModifyAttributePlanRequest, resp *tfsdk.ModifyAttributePlanResponse) { - resp.AttributePlan = types.String{Value: "test-attributeplanmodifier-value"} + resp.AttributePlan = types.StringValue("test-attributeplanmodifier-value") }, }, }, @@ -1034,7 +1034,7 @@ func TestServerPlanResourceChange(t *testing.T) { resp.Diagnostics.Append(req.Plan.Get(ctx, &data)...) - data.TestComputed = types.String{Value: "test-plannedstate-value"} + data.TestComputed = types.StringValue("test-plannedstate-value") resp.Diagnostics.Append(resp.Plan.Set(ctx, &data)...) }, @@ -1402,7 +1402,7 @@ func TestServerPlanResourceChange(t *testing.T) { Resource: &testprovider.ResourceWithModifyPlan{ ModifyPlanMethod: func(ctx context.Context, req resource.ModifyPlanRequest, resp *resource.ModifyPlanResponse) { // This is invalid logic to run during deletion. - resp.Diagnostics.Append(resp.Plan.SetAttribute(ctx, path.Root("test_computed"), types.String{Value: "test-plannedstate-value"})...) + resp.Diagnostics.Append(resp.Plan.SetAttribute(ctx, path.Root("test_computed"), types.StringValue("test-plannedstate-value"))...) }, }, }, @@ -2172,7 +2172,7 @@ func TestServerPlanResourceChange(t *testing.T) { resp.Diagnostics.Append(req.Plan.Get(ctx, &data)...) - data.TestComputed = types.String{Value: "test-plannedstate-value"} + data.TestComputed = types.StringValue("test-plannedstate-value") resp.Diagnostics.Append(resp.Plan.Set(ctx, &data)...) }, diff --git a/internal/fwserver/server_readdatasource_test.go b/internal/fwserver/server_readdatasource_test.go index 7c0f95149..a59802814 100644 --- a/internal/fwserver/server_readdatasource_test.go +++ b/internal/fwserver/server_readdatasource_test.go @@ -212,7 +212,7 @@ func TestServerReadDataSource(t *testing.T) { resp.Diagnostics.Append(req.Config.Get(ctx, &data)...) - data.TestComputed = types.String{Value: "test-state-value"} + data.TestComputed = types.StringValue("test-state-value") resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) }, diff --git a/internal/fwserver/server_readresource_test.go b/internal/fwserver/server_readresource_test.go index 5ca6c60aa..7eb8c7171 100644 --- a/internal/fwserver/server_readresource_test.go +++ b/internal/fwserver/server_readresource_test.go @@ -316,7 +316,7 @@ func TestServerReadResource(t *testing.T) { resp.Diagnostics.Append(req.State.Get(ctx, &data)...) - data.TestComputed = types.String{Value: "test-newstate-value"} + data.TestComputed = types.StringValue("test-newstate-value") resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) }, diff --git a/internal/proto5server/server_applyresourcechange_test.go b/internal/proto5server/server_applyresourcechange_test.go index 582160d0e..9990becb3 100644 --- a/internal/proto5server/server_applyresourcechange_test.go +++ b/internal/proto5server/server_applyresourcechange_test.go @@ -469,8 +469,8 @@ func TestServerApplyResourceChange(t *testing.T) { }, expectedResponse: &tfprotov5.ApplyResourceChangeResponse{ NewState: testNewDynamicValue(t, testSchemaType, map[string]tftypes.Value{ - "test_computed": tftypes.NewValue(tftypes.String, ""), - "test_required": tftypes.NewValue(tftypes.String, ""), + "test_computed": tftypes.NewValue(tftypes.String, nil), + "test_required": tftypes.NewValue(tftypes.String, nil), }), Private: privatestate.MustMarshalToJson(map[string][]byte{ "providerKey": []byte(`{"key": "value"}`), diff --git a/internal/proto5server/server_planresourcechange_test.go b/internal/proto5server/server_planresourcechange_test.go index 44dd35b15..4ed55f7d9 100644 --- a/internal/proto5server/server_planresourcechange_test.go +++ b/internal/proto5server/server_planresourcechange_test.go @@ -313,7 +313,7 @@ func TestServerPlanResourceChange(t *testing.T) { resp.Diagnostics.Append(req.Plan.Get(ctx, &data)...) - data.TestComputed = types.String{Value: "test-plannedstate-value"} + data.TestComputed = types.StringValue("test-plannedstate-value") resp.Diagnostics.Append(resp.Plan.Set(ctx, &data)...) }, @@ -562,7 +562,7 @@ func TestServerPlanResourceChange(t *testing.T) { }, ModifyPlanMethod: func(ctx context.Context, req resource.ModifyPlanRequest, resp *resource.ModifyPlanResponse) { // This is invalid logic to run during deletion. - resp.Diagnostics.Append(resp.Plan.SetAttribute(ctx, path.Root("test_computed"), types.String{Value: "test-plannedstate-value"})...) + resp.Diagnostics.Append(resp.Plan.SetAttribute(ctx, path.Root("test_computed"), types.StringValue("test-plannedstate-value"))...) }, } }, @@ -948,7 +948,7 @@ func TestServerPlanResourceChange(t *testing.T) { resp.Diagnostics.Append(req.Plan.Get(ctx, &data)...) - data.TestComputed = types.String{Value: "test-plannedstate-value"} + data.TestComputed = types.StringValue("test-plannedstate-value") resp.Diagnostics.Append(resp.Plan.Set(ctx, &data)...) }, diff --git a/internal/proto5server/server_readdatasource_test.go b/internal/proto5server/server_readdatasource_test.go index 8f00dd9ad..5b3caae28 100644 --- a/internal/proto5server/server_readdatasource_test.go +++ b/internal/proto5server/server_readdatasource_test.go @@ -240,7 +240,7 @@ func TestServerReadDataSource(t *testing.T) { resp.Diagnostics.Append(req.Config.Get(ctx, &data)...) - data.TestComputed = types.String{Value: "test-state-value"} + data.TestComputed = types.StringValue("test-state-value") resp.Diagnostics.Append(resp.State.Set(ctx, data)...) }, diff --git a/internal/proto5server/server_readresource_test.go b/internal/proto5server/server_readresource_test.go index daaf37177..ad47d0f29 100644 --- a/internal/proto5server/server_readresource_test.go +++ b/internal/proto5server/server_readresource_test.go @@ -295,7 +295,7 @@ func TestServerReadResource(t *testing.T) { resp.Diagnostics.Append(req.State.Get(ctx, &data)...) - data.TestComputed = types.String{Value: "test-newstate-value"} + data.TestComputed = types.StringValue("test-newstate-value") resp.Diagnostics.Append(resp.State.Set(ctx, data)...) }, diff --git a/internal/proto6server/server_applyresourcechange_test.go b/internal/proto6server/server_applyresourcechange_test.go index 7075f879a..498eef020 100644 --- a/internal/proto6server/server_applyresourcechange_test.go +++ b/internal/proto6server/server_applyresourcechange_test.go @@ -469,8 +469,8 @@ func TestServerApplyResourceChange(t *testing.T) { }, expectedResponse: &tfprotov6.ApplyResourceChangeResponse{ NewState: testNewDynamicValue(t, testSchemaType, map[string]tftypes.Value{ - "test_computed": tftypes.NewValue(tftypes.String, ""), - "test_required": tftypes.NewValue(tftypes.String, ""), + "test_computed": tftypes.NewValue(tftypes.String, nil), + "test_required": tftypes.NewValue(tftypes.String, nil), }), Private: privatestate.MustMarshalToJson(map[string][]byte{ "providerKey": []byte(`{"key": "value"}`), diff --git a/internal/proto6server/server_planresourcechange_test.go b/internal/proto6server/server_planresourcechange_test.go index 83be2b9cf..21dfb86b2 100644 --- a/internal/proto6server/server_planresourcechange_test.go +++ b/internal/proto6server/server_planresourcechange_test.go @@ -313,7 +313,7 @@ func TestServerPlanResourceChange(t *testing.T) { resp.Diagnostics.Append(req.Plan.Get(ctx, &data)...) - data.TestComputed = types.String{Value: "test-plannedstate-value"} + data.TestComputed = types.StringValue("test-plannedstate-value") resp.Diagnostics.Append(resp.Plan.Set(ctx, &data)...) }, @@ -562,7 +562,7 @@ func TestServerPlanResourceChange(t *testing.T) { }, ModifyPlanMethod: func(ctx context.Context, req resource.ModifyPlanRequest, resp *resource.ModifyPlanResponse) { // This is invalid logic to run during deletion. - resp.Diagnostics.Append(resp.Plan.SetAttribute(ctx, path.Root("test_computed"), types.String{Value: "test-plannedstate-value"})...) + resp.Diagnostics.Append(resp.Plan.SetAttribute(ctx, path.Root("test_computed"), types.StringValue("test-plannedstate-value"))...) }, } }, @@ -948,7 +948,7 @@ func TestServerPlanResourceChange(t *testing.T) { resp.Diagnostics.Append(req.Plan.Get(ctx, &data)...) - data.TestComputed = types.String{Value: "test-plannedstate-value"} + data.TestComputed = types.StringValue("test-plannedstate-value") resp.Diagnostics.Append(resp.Plan.Set(ctx, &data)...) }, diff --git a/internal/proto6server/server_readdatasource_test.go b/internal/proto6server/server_readdatasource_test.go index 42e614dd7..5e6f744fe 100644 --- a/internal/proto6server/server_readdatasource_test.go +++ b/internal/proto6server/server_readdatasource_test.go @@ -240,7 +240,7 @@ func TestServerReadDataSource(t *testing.T) { resp.Diagnostics.Append(req.Config.Get(ctx, &data)...) - data.TestComputed = types.String{Value: "test-state-value"} + data.TestComputed = types.StringValue("test-state-value") resp.Diagnostics.Append(resp.State.Set(ctx, data)...) }, diff --git a/internal/proto6server/server_readresource_test.go b/internal/proto6server/server_readresource_test.go index 28110d4d8..9ee1b1228 100644 --- a/internal/proto6server/server_readresource_test.go +++ b/internal/proto6server/server_readresource_test.go @@ -295,7 +295,7 @@ func TestServerReadResource(t *testing.T) { resp.Diagnostics.Append(req.State.Get(ctx, &data)...) - data.TestComputed = types.String{Value: "test-newstate-value"} + data.TestComputed = types.StringValue("test-newstate-value") resp.Diagnostics.Append(resp.State.Set(ctx, data)...) }, diff --git a/internal/reflect/interfaces_test.go b/internal/reflect/interfaces_test.go index 512d9833e..12ef167c2 100644 --- a/internal/reflect/interfaces_test.go +++ b/internal/reflect/interfaces_test.go @@ -290,13 +290,13 @@ func TestFromUnknownable(t *testing.T) { val: &unknownableString{ Unknown: true, }, - expected: types.String{Unknown: true}, + expected: types.StringUnknown(), }, "value": { val: &unknownableString{ String: "hello, world", }, - expected: types.String{Value: "hello, world"}, + expected: types.StringValue("hello, world"), }, } @@ -388,13 +388,13 @@ func TestFromNullable(t *testing.T) { val: &nullableString{ Null: true, }, - expected: types.String{Null: true}, + expected: types.StringNull(), }, "value": { val: &nullableString{ String: "hello, world", }, - expected: types.String{Value: "hello, world"}, + expected: types.StringValue("hello, world"), }, } @@ -428,17 +428,17 @@ func TestNewAttributeValue(t *testing.T) { "unknown": { val: tftypes.NewValue(tftypes.String, tftypes.UnknownValue), target: reflect.ValueOf(types.String{}), - expected: types.String{Unknown: true}, + expected: types.StringUnknown(), }, "null": { val: tftypes.NewValue(tftypes.String, nil), target: reflect.ValueOf(types.String{}), - expected: types.String{Null: true}, + expected: types.StringNull(), }, "value": { val: tftypes.NewValue(tftypes.String, "hello"), target: reflect.ValueOf(types.String{}), - expected: types.String{Value: "hello"}, + expected: types.StringValue("hello"), }, } @@ -474,13 +474,13 @@ func TestFromAttributeValue(t *testing.T) { expectedDiags diag.Diagnostics }{ "null": { - val: types.String{Null: true}, + val: types.StringNull(), }, "unknown": { - val: types.String{Unknown: true}, + val: types.StringUnknown(), }, "value": { - val: types.String{Value: "hello, world"}, + val: types.StringValue("hello, world"), }, } @@ -575,19 +575,19 @@ func TestFromValueCreator(t *testing.T) { vc: &valueCreator{ null: true, }, - expected: types.String{Null: true}, + expected: types.StringNull(), }, "unknown": { vc: &valueCreator{ unknown: true, }, - expected: types.String{Unknown: true}, + expected: types.StringUnknown(), }, "value": { vc: &valueCreator{ value: "hello, world", }, - expected: types.String{Value: "hello, world"}, + expected: types.StringValue("hello, world"), }, } diff --git a/internal/reflect/number_test.go b/internal/reflect/number_test.go index 5bd0113ca..365e6933b 100644 --- a/internal/reflect/number_test.go +++ b/internal/reflect/number_test.go @@ -1183,26 +1183,20 @@ func TestFromInt(t *testing.T) { expectedDiags diag.Diagnostics }{ "0": { - val: 0, - typ: types.NumberType, - expected: types.Number{ - Value: big.NewFloat(0), - }, + val: 0, + typ: types.NumberType, + expected: types.NumberValue(big.NewFloat(0)), }, "1": { - val: 1, - typ: types.NumberType, - expected: types.Number{ - Value: big.NewFloat(1), - }, + val: 1, + typ: types.NumberType, + expected: types.NumberValue(big.NewFloat(1)), }, "WithValidateWarning": { val: 1, typ: testtypes.NumberTypeWithValidateWarning{}, expected: testtypes.Number{ - Number: types.Number{ - Value: big.NewFloat(1), - }, + Number: types.NumberValue(big.NewFloat(1)), CreatedBy: testtypes.NumberType{}, }, expectedDiags: diag.Diagnostics{ @@ -1245,26 +1239,20 @@ func TestFromUint(t *testing.T) { expectedDiags diag.Diagnostics }{ "0": { - val: 0, - typ: types.NumberType, - expected: types.Number{ - Value: big.NewFloat(0), - }, + val: 0, + typ: types.NumberType, + expected: types.NumberValue(big.NewFloat(0)), }, "1": { - val: 1, - typ: types.NumberType, - expected: types.Number{ - Value: big.NewFloat(1), - }, + val: 1, + typ: types.NumberType, + expected: types.NumberValue(big.NewFloat(1)), }, "WithValidateWarning": { val: 1, typ: testtypes.NumberTypeWithValidateWarning{}, expected: testtypes.Number{ - Number: types.Number{ - Value: big.NewFloat(1), - }, + Number: types.NumberValue(big.NewFloat(1)), CreatedBy: testtypes.NumberType{}, }, expectedDiags: diag.Diagnostics{ @@ -1307,33 +1295,25 @@ func TestFromFloat(t *testing.T) { expectedDiags diag.Diagnostics }{ "0": { - val: 0, - typ: types.NumberType, - expected: types.Number{ - Value: big.NewFloat(0), - }, + val: 0, + typ: types.NumberType, + expected: types.NumberValue(big.NewFloat(0)), }, "1": { - val: 1, - typ: types.NumberType, - expected: types.Number{ - Value: big.NewFloat(1), - }, + val: 1, + typ: types.NumberType, + expected: types.NumberValue(big.NewFloat(1)), }, "1.234": { - val: 1.234, - typ: types.NumberType, - expected: types.Number{ - Value: big.NewFloat(1.234), - }, + val: 1.234, + typ: types.NumberType, + expected: types.NumberValue(big.NewFloat(1.234)), }, "WithValidateWarning": { val: 1, typ: testtypes.NumberTypeWithValidateWarning{}, expected: testtypes.Number{ - Number: types.Number{ - Value: big.NewFloat(1), - }, + Number: types.NumberValue(big.NewFloat(1)), CreatedBy: testtypes.NumberType{}, }, expectedDiags: diag.Diagnostics{ @@ -1376,33 +1356,25 @@ func TestFromBigFloat(t *testing.T) { expectedDiags diag.Diagnostics }{ "0": { - val: big.NewFloat(0), - typ: types.NumberType, - expected: types.Number{ - Value: big.NewFloat(0), - }, + val: big.NewFloat(0), + typ: types.NumberType, + expected: types.NumberValue(big.NewFloat(0)), }, "1": { - val: big.NewFloat(1), - typ: types.NumberType, - expected: types.Number{ - Value: big.NewFloat(1), - }, + val: big.NewFloat(1), + typ: types.NumberType, + expected: types.NumberValue(big.NewFloat(1)), }, "1.234": { - val: big.NewFloat(1.234), - typ: types.NumberType, - expected: types.Number{ - Value: big.NewFloat(1.234), - }, + val: big.NewFloat(1.234), + typ: types.NumberType, + expected: types.NumberValue(big.NewFloat(1.234)), }, "WithValidateWarning": { val: big.NewFloat(1), typ: testtypes.NumberTypeWithValidateWarning{}, expected: testtypes.Number{ - Number: types.Number{ - Value: big.NewFloat(1), - }, + Number: types.NumberValue(big.NewFloat(1)), CreatedBy: testtypes.NumberType{}, }, expectedDiags: diag.Diagnostics{ @@ -1445,26 +1417,20 @@ func TestFromBigInt(t *testing.T) { expectedDiags diag.Diagnostics }{ "0": { - val: big.NewInt(0), - typ: types.NumberType, - expected: types.Number{ - Value: big.NewFloat(0), - }, + val: big.NewInt(0), + typ: types.NumberType, + expected: types.NumberValue(big.NewFloat(0)), }, "1": { - val: big.NewInt(1), - typ: types.NumberType, - expected: types.Number{ - Value: big.NewFloat(1), - }, + val: big.NewInt(1), + typ: types.NumberType, + expected: types.NumberValue(big.NewFloat(1)), }, "WithValidateWarning": { val: big.NewInt(1), typ: testtypes.NumberTypeWithValidateWarning{}, expected: testtypes.Number{ - Number: types.Number{ - Value: big.NewFloat(1), - }, + Number: types.NumberValue(big.NewFloat(1)), CreatedBy: testtypes.NumberTypeWithValidateWarning{}, }, expectedDiags: diag.Diagnostics{ diff --git a/internal/reflect/pointer_test.go b/internal/reflect/pointer_test.go index 68cf4b14d..0473d3003 100644 --- a/internal/reflect/pointer_test.go +++ b/internal/reflect/pointer_test.go @@ -94,18 +94,14 @@ func TestFromPointer(t *testing.T) { expectedDiags diag.Diagnostics }{ "simple": { - typ: types.StringType, - val: reflect.ValueOf(strPtr("hello, world")), - expected: types.String{ - Value: "hello, world", - }, + typ: types.StringType, + val: reflect.ValueOf(strPtr("hello, world")), + expected: types.StringValue("hello, world"), }, "null": { - typ: types.StringType, - val: reflect.ValueOf(new(*string)), - expected: types.String{ - Null: true, - }, + typ: types.StringType, + val: reflect.ValueOf(new(*string)), + expected: types.StringNull(), }, "WithValidateError": { typ: testtypes.StringTypeWithValidateError{}, @@ -118,10 +114,8 @@ func TestFromPointer(t *testing.T) { typ: testtypes.StringTypeWithValidateWarning{}, val: reflect.ValueOf(strPtr("hello, world")), expected: testtypes.String{ - InternalString: types.String{ - Value: "hello, world", - }, - CreatedBy: testtypes.StringTypeWithValidateWarning{}, + InternalString: types.StringValue("hello, world"), + CreatedBy: testtypes.StringTypeWithValidateWarning{}, }, expectedDiags: diag.Diagnostics{ testtypes.TestWarningDiagnostic(path.Empty()), diff --git a/internal/reflect/primitive_test.go b/internal/reflect/primitive_test.go index 46cbb91d5..3c4a63ba3 100644 --- a/internal/reflect/primitive_test.go +++ b/internal/reflect/primitive_test.go @@ -87,20 +87,16 @@ func TestFromString(t *testing.T) { expectedDiags diag.Diagnostics }{ "basic": { - val: "mystring", - typ: types.StringType, - expected: types.String{ - Value: "mystring", - }, + val: "mystring", + typ: types.StringType, + expected: types.StringValue("mystring"), }, "WithValidateWarning": { val: "mystring", typ: testtypes.StringTypeWithValidateWarning{}, expected: testtypes.String{ - InternalString: types.String{ - Value: "mystring", - }, - CreatedBy: testtypes.StringTypeWithValidateWarning{}, + InternalString: types.StringValue("mystring"), + CreatedBy: testtypes.StringTypeWithValidateWarning{}, }, expectedDiags: diag.Diagnostics{ testtypes.TestWarningDiagnostic(path.Empty()), @@ -143,18 +139,14 @@ func TestFromBool(t *testing.T) { expectedDiags diag.Diagnostics }{ "true": { - val: true, - typ: types.BoolType, - expected: types.Bool{ - Value: true, - }, + val: true, + typ: types.BoolType, + expected: types.BoolValue(true), }, "false": { - val: false, - typ: types.BoolType, - expected: types.Bool{ - Value: false, - }, + val: false, + typ: types.BoolType, + expected: types.BoolValue(false), }, "WithValidateWarning": { val: true, diff --git a/internal/reflect/struct_test.go b/internal/reflect/struct_test.go index d8cbac97e..a7b917f81 100644 --- a/internal/reflect/struct_test.go +++ b/internal/reflect/struct_test.go @@ -483,9 +483,7 @@ func TestNewStruct_complex(t *testing.T) { Nullable: &nullableString{ Null: true, }, - AttributeValue: types.String{ - Unknown: true, - }, + AttributeValue: types.StringUnknown(), ValueConverter: &valueConverter{ null: true, }, @@ -520,18 +518,18 @@ func TestFromStruct_primitives(t *testing.T) { t.Fatalf("Unexpected error: %v", diags) } - expectedVal := types.Object{ - Attrs: map[string]attr.Value{ - "name": types.String{Value: "myfirstdisk"}, - "age": types.Number{Value: big.NewFloat(30)}, - "opted_in": types.Bool{Value: true}, - }, - AttrTypes: map[string]attr.Type{ + expectedVal := types.ObjectValueMust( + map[string]attr.Type{ "name": types.StringType, "age": types.NumberType, "opted_in": types.BoolType, }, - } + map[string]attr.Value{ + "name": types.StringValue("myfirstdisk"), + "age": types.NumberValue(big.NewFloat(30)), + "opted_in": types.BoolValue(true), + }, + ) if diff := cmp.Diff(expectedVal, actualVal); diff != "" { t.Errorf("Unexpected diff (+wanted, -got): %s", diff) @@ -614,9 +612,7 @@ func TestFromStruct_complex(t *testing.T) { Nullable: &nullableString{ Null: true, }, - AttributeValue: types.String{ - Unknown: true, - }, + AttributeValue: types.StringUnknown(), ValueCreator: &valueCreator{ null: true, }, @@ -674,8 +670,8 @@ func TestFromStruct_complex(t *testing.T) { if diags.HasError() { t.Errorf("Unexpected error: %v", diags) } - expected := types.Object{ - AttrTypes: map[string]attr.Type{ + expected := types.ObjectValueMust( + map[string]attr.Type{ "list_slice": types.ListType{ ElemType: types.StringType, }, @@ -720,134 +716,134 @@ func TestFromStruct_complex(t *testing.T) { "big_int": types.NumberType, "uint": types.NumberType, }, - Attrs: map[string]attr.Value{ - "list_slice": types.List{ - ElemType: types.StringType, - Elems: []attr.Value{ - types.String{Value: "red"}, - types.String{Value: "blue"}, - types.String{Value: "green"}, - }, - }, - "list_slice_of_structs": types.List{ - ElemType: types.ObjectType{ + map[string]attr.Value{ + "list_slice": types.ListValueMust( + types.StringType, + []attr.Value{ + types.StringValue("red"), + types.StringValue("blue"), + types.StringValue("green"), + }, + ), + "list_slice_of_structs": types.ListValueMust( + types.ObjectType{ AttrTypes: map[string]attr.Type{ "a": types.StringType, "b": types.NumberType, }, }, - Elems: []attr.Value{ - types.Object{ - AttrTypes: map[string]attr.Type{ + []attr.Value{ + types.ObjectValueMust( + map[string]attr.Type{ "a": types.StringType, "b": types.NumberType, }, - Attrs: map[string]attr.Value{ - "a": types.String{Value: "hello, world"}, - "b": types.Number{Value: big.NewFloat(123)}, + map[string]attr.Value{ + "a": types.StringValue("hello, world"), + "b": types.NumberValue(big.NewFloat(123)), }, - }, - types.Object{ - AttrTypes: map[string]attr.Type{ + ), + types.ObjectValueMust( + map[string]attr.Type{ "a": types.StringType, "b": types.NumberType, }, - Attrs: map[string]attr.Value{ - "a": types.String{Value: "goodnight, moon"}, - "b": types.Number{Value: big.NewFloat(456)}, + map[string]attr.Value{ + "a": types.StringValue("goodnight, moon"), + "b": types.NumberValue(big.NewFloat(456)), }, - }, - }, - }, - "set_slice": types.Set{ - ElemType: types.StringType, - Elems: []attr.Value{ - types.String{Value: "red"}, - types.String{Value: "blue"}, - types.String{Value: "green"}, - }, - }, - "set_slice_of_structs": types.Set{ - ElemType: types.ObjectType{ + ), + }, + ), + "set_slice": types.SetValueMust( + types.StringType, + []attr.Value{ + types.StringValue("red"), + types.StringValue("blue"), + types.StringValue("green"), + }, + ), + "set_slice_of_structs": types.SetValueMust( + types.ObjectType{ AttrTypes: map[string]attr.Type{ "a": types.StringType, "b": types.NumberType, }, }, - Elems: []attr.Value{ - types.Object{ - AttrTypes: map[string]attr.Type{ + []attr.Value{ + types.ObjectValueMust( + map[string]attr.Type{ "a": types.StringType, "b": types.NumberType, }, - Attrs: map[string]attr.Value{ - "a": types.String{Value: "hello, world"}, - "b": types.Number{Value: big.NewFloat(123)}, + map[string]attr.Value{ + "a": types.StringValue("hello, world"), + "b": types.NumberValue(big.NewFloat(123)), }, - }, - types.Object{ - AttrTypes: map[string]attr.Type{ + ), + types.ObjectValueMust( + map[string]attr.Type{ "a": types.StringType, "b": types.NumberType, }, - Attrs: map[string]attr.Value{ - "a": types.String{Value: "goodnight, moon"}, - "b": types.Number{Value: big.NewFloat(456)}, + map[string]attr.Value{ + "a": types.StringValue("goodnight, moon"), + "b": types.NumberValue(big.NewFloat(456)), }, - }, + ), }, - }, - "struct": types.Object{ - AttrTypes: map[string]attr.Type{ + ), + "struct": types.ObjectValueMust( + map[string]attr.Type{ "a": types.BoolType, "slice": types.ListType{ ElemType: types.NumberType, }, }, - Attrs: map[string]attr.Value{ - "a": types.Bool{Value: true}, - "slice": types.List{ - ElemType: types.NumberType, - Elems: []attr.Value{ - types.Number{Value: big.NewFloat(123)}, - types.Number{Value: big.NewFloat(456)}, - types.Number{Value: big.NewFloat(789)}, + map[string]attr.Value{ + "a": types.BoolValue(true), + "slice": types.ListValueMust( + types.NumberType, + []attr.Value{ + types.NumberValue(big.NewFloat(123)), + types.NumberValue(big.NewFloat(456)), + types.NumberValue(big.NewFloat(789)), }, - }, + ), }, - }, - "map": types.Map{ - ElemType: types.ListType{ + ), + "map": types.MapValueMust( + types.ListType{ ElemType: types.StringType, }, - Elems: map[string]attr.Value{ - "colors": types.List{ - ElemType: types.StringType, - Elems: []attr.Value{ - types.String{Value: "red"}, - types.String{Value: "orange"}, - types.String{Value: "yellow"}, + map[string]attr.Value{ + "colors": types.ListValueMust( + types.StringType, + []attr.Value{ + types.StringValue("red"), + types.StringValue("orange"), + types.StringValue("yellow"), }, - }, - "fruits": types.List{ - ElemType: types.StringType, - Elems: []attr.Value{ - types.String{Value: "apple"}, - types.String{Value: "banana"}, + ), + "fruits": types.ListValueMust( + types.StringType, + []attr.Value{ + types.StringValue("apple"), + types.StringValue("banana"), }, - }, - }, - }, - "pointer": types.String{Value: "pointed"}, - "unknownable": types.String{Unknown: true}, - "nullable": types.String{Null: true}, - "attribute_value": types.String{Unknown: true}, - "value_creator": types.String{Null: true}, - "big_float": types.Number{Value: big.NewFloat(123.456)}, - "big_int": types.Number{Value: big.NewFloat(123456)}, - "uint": types.Number{Value: big.NewFloat(123456)}, - }, - } + ), + }, + ), + "pointer": types.StringValue("pointed"), + "unknownable": types.StringUnknown(), + "nullable": types.StringNull(), + "attribute_value": types.StringUnknown(), + "value_creator": types.StringNull(), + "big_float": types.NumberValue(big.NewFloat(123.456)), + "big_int": types.NumberValue(big.NewFloat(123456)), + "uint": types.NumberValue(big.NewFloat(123456)), + }, + ) if diff := cmp.Diff(expected, result); diff != "" { t.Errorf("Didn't get expected value. Diff (+ is expected, - is result): %s", diff) } diff --git a/internal/testing/planmodifiers/planmodifiers.go b/internal/testing/planmodifiers/planmodifiers.go index 9bc3972e4..fa751c0af 100644 --- a/internal/testing/planmodifiers/planmodifiers.go +++ b/internal/testing/planmodifiers/planmodifiers.go @@ -93,7 +93,7 @@ func (t TestAttrDefaultValueModifier) Modify(ctx context.Context, req tfsdk.Modi configVal := req.AttributeConfig.(types.String) if configVal.IsNull() { - resp.AttributePlan = types.String{Value: "DEFAULTVALUE"} + resp.AttributePlan = types.StringValue("DEFAULTVALUE") } } diff --git a/internal/testing/types/number.go b/internal/testing/types/number.go index 8581f212f..2868cf46a 100644 --- a/internal/testing/types/number.go +++ b/internal/testing/types/number.go @@ -42,13 +42,13 @@ func (t NumberType) TerraformType(_ context.Context) tftypes.Type { func (t NumberType) ValueFromTerraform(ctx context.Context, in tftypes.Value) (attr.Value, error) { if !in.IsKnown() { return Number{ - Number: types.Number{Unknown: true}, + Number: types.NumberUnknown(), CreatedBy: t, }, nil } if in.IsNull() { return Number{ - Number: types.Number{Null: true}, + Number: types.NumberNull(), CreatedBy: t, }, nil } @@ -58,7 +58,7 @@ func (t NumberType) ValueFromTerraform(ctx context.Context, in tftypes.Value) (a return nil, err } return Number{ - Number: types.Number{Value: n}, + Number: types.NumberValue(n), CreatedBy: t, }, nil } diff --git a/internal/testing/types/string.go b/internal/testing/types/string.go index 56c4a69bd..c534d8a0b 100644 --- a/internal/testing/types/string.go +++ b/internal/testing/types/string.go @@ -41,13 +41,13 @@ func (t StringType) TerraformType(_ context.Context) tftypes.Type { func (t StringType) ValueFromTerraform(ctx context.Context, in tftypes.Value) (attr.Value, error) { if !in.IsKnown() { return String{ - InternalString: types.String{Unknown: true}, + InternalString: types.StringUnknown(), CreatedBy: t, }, nil } if in.IsNull() { return String{ - InternalString: types.String{Null: true}, + InternalString: types.StringNull(), CreatedBy: t, }, nil } @@ -57,7 +57,7 @@ func (t StringType) ValueFromTerraform(ctx context.Context, in tftypes.Value) (a return nil, err } return String{ - InternalString: types.String{Value: s}, + InternalString: types.StringValue(s), CreatedBy: t, }, nil } diff --git a/internal/totftypes/attribute_path_step_test.go b/internal/totftypes/attribute_path_step_test.go index 40d83b5c8..16a2787c5 100644 --- a/internal/totftypes/attribute_path_step_test.go +++ b/internal/totftypes/attribute_path_step_test.go @@ -39,7 +39,7 @@ func TestAttributePathStep(t *testing.T) { expected: tftypes.ElementKeyString("test"), }, "PathStepElementKeyValue": { - fw: path.PathStepElementKeyValue{Value: types.String{Value: "test"}}, + fw: path.PathStepElementKeyValue{Value: types.StringValue("test")}, expected: tftypes.ElementKeyValue(tftypes.NewValue(tftypes.String, "test")), }, } diff --git a/path/expression_step_attribute_name_exact_test.go b/path/expression_step_attribute_name_exact_test.go index 140ba377d..d094b9bb1 100644 --- a/path/expression_step_attribute_name_exact_test.go +++ b/path/expression_step_attribute_name_exact_test.go @@ -38,7 +38,7 @@ func TestExpressionStepAttributeNameExactEqual(t *testing.T) { }, "ExpressionStepElementKeyValueExact": { step: path.ExpressionStepAttributeNameExact("test"), - other: path.ExpressionStepElementKeyValueExact{Value: types.String{Value: "test"}}, + other: path.ExpressionStepElementKeyValueExact{Value: types.StringValue("test")}, expected: false, }, } @@ -88,7 +88,7 @@ func TestExpressionStepAttributeNameExactMatches(t *testing.T) { }, "StepElementKeyValue": { step: path.ExpressionStepAttributeNameExact("test"), - pathStep: path.PathStepElementKeyValue{Value: types.String{Value: "test"}}, + pathStep: path.PathStepElementKeyValue{Value: types.StringValue("test")}, expected: false, }, } diff --git a/path/expression_step_element_key_int_any_test.go b/path/expression_step_element_key_int_any_test.go index f3c4759ad..0204ccc76 100644 --- a/path/expression_step_element_key_int_any_test.go +++ b/path/expression_step_element_key_int_any_test.go @@ -38,7 +38,7 @@ func TestExpressionStepElementKeyIntAnyEqual(t *testing.T) { }, "ExpressionStepElementKeyValueExact": { step: path.ExpressionStepElementKeyIntAny{}, - other: path.ExpressionStepElementKeyValueExact{Value: types.String{Value: "test"}}, + other: path.ExpressionStepElementKeyValueExact{Value: types.StringValue("test")}, expected: false, }, } @@ -83,7 +83,7 @@ func TestExpressionStepElementKeyIntAnyMatches(t *testing.T) { }, "StepElementKeyValue": { step: path.ExpressionStepElementKeyIntAny{}, - pathStep: path.PathStepElementKeyValue{Value: types.String{Value: "test"}}, + pathStep: path.PathStepElementKeyValue{Value: types.StringValue("test")}, expected: false, }, } diff --git a/path/expression_step_element_key_int_exact_test.go b/path/expression_step_element_key_int_exact_test.go index 9ef627b15..f4f792cab 100644 --- a/path/expression_step_element_key_int_exact_test.go +++ b/path/expression_step_element_key_int_exact_test.go @@ -43,7 +43,7 @@ func TestExpressionStepElementKeyIntExactEqual(t *testing.T) { }, "ExpressionStepElementKeyValueExact": { step: path.ExpressionStepElementKeyIntExact(0), - other: path.ExpressionStepElementKeyValueExact{Value: types.String{Value: "test"}}, + other: path.ExpressionStepElementKeyValueExact{Value: types.StringValue("test")}, expected: false, }, } @@ -93,7 +93,7 @@ func TestExpressionStepElementKeyIntExactMatches(t *testing.T) { }, "StepElementKeyValue": { step: path.ExpressionStepElementKeyIntExact(0), - pathStep: path.PathStepElementKeyValue{Value: types.String{Value: "test"}}, + pathStep: path.PathStepElementKeyValue{Value: types.StringValue("test")}, expected: false, }, } diff --git a/path/expression_step_element_key_string_any_test.go b/path/expression_step_element_key_string_any_test.go index 933469ea8..3a4ecd3a1 100644 --- a/path/expression_step_element_key_string_any_test.go +++ b/path/expression_step_element_key_string_any_test.go @@ -38,7 +38,7 @@ func TestExpressionStepElementKeyStringAnyEqual(t *testing.T) { }, "ExpressionStepElementKeyValueExact": { step: path.ExpressionStepElementKeyStringAny{}, - other: path.ExpressionStepElementKeyValueExact{Value: types.String{Value: "test"}}, + other: path.ExpressionStepElementKeyValueExact{Value: types.StringValue("test")}, expected: false, }, } @@ -83,7 +83,7 @@ func TestExpressionStepElementKeyStringAnyMatches(t *testing.T) { }, "StepElementKeyValue": { step: path.ExpressionStepElementKeyStringAny{}, - pathStep: path.PathStepElementKeyValue{Value: types.String{Value: "test"}}, + pathStep: path.PathStepElementKeyValue{Value: types.StringValue("test")}, expected: false, }, } diff --git a/path/expression_step_element_key_string_exact_test.go b/path/expression_step_element_key_string_exact_test.go index 13c8cebd0..26a69ab12 100644 --- a/path/expression_step_element_key_string_exact_test.go +++ b/path/expression_step_element_key_string_exact_test.go @@ -38,7 +38,7 @@ func TestExpressionStepElementKeyStringExactEqual(t *testing.T) { }, "ExpressionStepElementKeyValueExact": { step: path.ExpressionStepElementKeyStringExact("test"), - other: path.ExpressionStepElementKeyValueExact{Value: types.String{Value: "test"}}, + other: path.ExpressionStepElementKeyValueExact{Value: types.StringValue("test")}, expected: false, }, } @@ -88,7 +88,7 @@ func TestExpressionStepElementKeyStringExactMatches(t *testing.T) { }, "StepElementKeyValue": { step: path.ExpressionStepElementKeyStringExact("test"), - pathStep: path.PathStepElementKeyValue{Value: types.String{Value: "test"}}, + pathStep: path.PathStepElementKeyValue{Value: types.StringValue("test")}, expected: false, }, } diff --git a/path/expression_step_element_key_value_any_test.go b/path/expression_step_element_key_value_any_test.go index 2502bbef3..0a186c8c8 100644 --- a/path/expression_step_element_key_value_any_test.go +++ b/path/expression_step_element_key_value_any_test.go @@ -38,7 +38,7 @@ func TestExpressionStepElementKeyValueAnyEqual(t *testing.T) { }, "ExpressionStepElementKeyValueExact": { step: path.ExpressionStepElementKeyValueAny{}, - other: path.ExpressionStepElementKeyValueExact{Value: types.String{Value: "test"}}, + other: path.ExpressionStepElementKeyValueExact{Value: types.StringValue("test")}, expected: false, }, } @@ -83,7 +83,7 @@ func TestExpressionStepElementKeyValueAnyMatches(t *testing.T) { }, "StepElementKeyValue": { step: path.ExpressionStepElementKeyValueAny{}, - pathStep: path.PathStepElementKeyValue{Value: types.String{Value: "test"}}, + pathStep: path.PathStepElementKeyValue{Value: types.StringValue("test")}, expected: true, }, } diff --git a/path/expression_step_element_key_value_exact_test.go b/path/expression_step_element_key_value_exact_test.go index 78e041416..1947b3004 100644 --- a/path/expression_step_element_key_value_exact_test.go +++ b/path/expression_step_element_key_value_exact_test.go @@ -18,28 +18,28 @@ func TestExpressionStepElementKeyValueExactEqual(t *testing.T) { expected bool }{ "ExpressionStepAttributeNameExact": { - step: path.ExpressionStepElementKeyValueExact{Value: types.String{Value: "test"}}, + step: path.ExpressionStepElementKeyValueExact{Value: types.StringValue("test")}, other: path.ExpressionStepAttributeNameExact("test"), expected: false, }, "ExpressionStepElementKeyIntExact": { - step: path.ExpressionStepElementKeyValueExact{Value: types.String{Value: "test"}}, + step: path.ExpressionStepElementKeyValueExact{Value: types.StringValue("test")}, other: path.ExpressionStepElementKeyIntExact(0), expected: false, }, "ExpressionStepElementKeyStringExact": { - step: path.ExpressionStepElementKeyValueExact{Value: types.String{Value: "test"}}, + step: path.ExpressionStepElementKeyValueExact{Value: types.StringValue("test")}, other: path.ExpressionStepElementKeyStringExact("test"), expected: false, }, "ExpressionStepElementKeyValueExact-different": { - step: path.ExpressionStepElementKeyValueExact{Value: types.String{Value: "test"}}, - other: path.ExpressionStepElementKeyValueExact{Value: types.String{Value: "not-test"}}, + step: path.ExpressionStepElementKeyValueExact{Value: types.StringValue("test")}, + other: path.ExpressionStepElementKeyValueExact{Value: types.StringValue("not-test")}, expected: false, }, "ExpressionStepElementKeyValueExact-equal": { - step: path.ExpressionStepElementKeyValueExact{Value: types.String{Value: "test"}}, - other: path.ExpressionStepElementKeyValueExact{Value: types.String{Value: "test"}}, + step: path.ExpressionStepElementKeyValueExact{Value: types.StringValue("test")}, + other: path.ExpressionStepElementKeyValueExact{Value: types.StringValue("test")}, expected: true, }, } @@ -68,28 +68,28 @@ func TestExpressionStepElementKeyValueExactMatches(t *testing.T) { expected bool }{ "StepAttributeName": { - step: path.ExpressionStepElementKeyValueExact{Value: types.String{Value: "test"}}, + step: path.ExpressionStepElementKeyValueExact{Value: types.StringValue("test")}, pathStep: path.PathStepAttributeName("test"), expected: false, }, "StepElementKeyInt": { - step: path.ExpressionStepElementKeyValueExact{Value: types.String{Value: "test"}}, + step: path.ExpressionStepElementKeyValueExact{Value: types.StringValue("test")}, pathStep: path.PathStepElementKeyInt(0), expected: false, }, "StepElementKeyString": { - step: path.ExpressionStepElementKeyValueExact{Value: types.String{Value: "test"}}, + step: path.ExpressionStepElementKeyValueExact{Value: types.StringValue("test")}, pathStep: path.PathStepElementKeyString("test"), expected: false, }, "StepElementKeyValue-different": { - step: path.ExpressionStepElementKeyValueExact{Value: types.String{Value: "test"}}, - pathStep: path.PathStepElementKeyValue{Value: types.String{Value: "not-test"}}, + step: path.ExpressionStepElementKeyValueExact{Value: types.StringValue("test")}, + pathStep: path.PathStepElementKeyValue{Value: types.StringValue("not-test")}, expected: false, }, "StepElementKeyValue-equal": { - step: path.ExpressionStepElementKeyValueExact{Value: types.String{Value: "test"}}, - pathStep: path.PathStepElementKeyValue{Value: types.String{Value: "test"}}, + step: path.ExpressionStepElementKeyValueExact{Value: types.StringValue("test")}, + pathStep: path.PathStepElementKeyValue{Value: types.StringValue("test")}, expected: true, }, } @@ -117,60 +117,60 @@ func TestExpressionStepElementKeyValueExactString(t *testing.T) { expected string }{ "bool-value": { - step: path.ExpressionStepElementKeyValueExact{Value: types.Bool{Value: true}}, + step: path.ExpressionStepElementKeyValueExact{Value: types.BoolValue(true)}, expected: `[Value(true)]`, }, "float64-value": { - step: path.ExpressionStepElementKeyValueExact{Value: types.Float64{Value: 1.2}}, + step: path.ExpressionStepElementKeyValueExact{Value: types.Float64Value(1.2)}, expected: `[Value(1.200000)]`, }, "int64-value": { - step: path.ExpressionStepElementKeyValueExact{Value: types.Int64{Value: 123}}, + step: path.ExpressionStepElementKeyValueExact{Value: types.Int64Value(123)}, expected: `[Value(123)]`, }, "list-value": { - step: path.ExpressionStepElementKeyValueExact{Value: types.List{ - Elems: []attr.Value{ - types.String{Value: "test-element-1"}, - types.String{Value: "test-element-2"}, + step: path.ExpressionStepElementKeyValueExact{Value: types.ListValueMust( + types.StringType, + []attr.Value{ + types.StringValue("test-element-1"), + types.StringValue("test-element-2"), }, - ElemType: types.StringType, - }}, + )}, expected: `[Value(["test-element-1","test-element-2"])]`, }, "map-value": { - step: path.ExpressionStepElementKeyValueExact{Value: types.Map{ - Elems: map[string]attr.Value{ - "test-key-1": types.String{Value: "test-value-1"}, - "test-key-2": types.String{Value: "test-value-2"}, + step: path.ExpressionStepElementKeyValueExact{Value: types.MapValueMust( + types.StringType, + map[string]attr.Value{ + "test-key-1": types.StringValue("test-value-1"), + "test-key-2": types.StringValue("test-value-2"), }, - ElemType: types.StringType, - }}, + )}, expected: `[Value({"test-key-1":"test-value-1","test-key-2":"test-value-2"})]`, }, "object-value": { - step: path.ExpressionStepElementKeyValueExact{Value: types.Object{ - Attrs: map[string]attr.Value{ - "test_attr_1": types.Bool{Value: true}, - "test_attr_2": types.String{Value: "test-value"}, - }, - AttrTypes: map[string]attr.Type{ + step: path.ExpressionStepElementKeyValueExact{Value: types.ObjectValueMust( + map[string]attr.Type{ "test_attr_1": types.BoolType, "test_attr_2": types.StringType, }, - }}, + map[string]attr.Value{ + "test_attr_1": types.BoolValue(true), + "test_attr_2": types.StringValue("test-value"), + }, + )}, expected: `[Value({"test_attr_1":true,"test_attr_2":"test-value"})]`, }, "string-null": { - step: path.ExpressionStepElementKeyValueExact{Value: types.String{Null: true}}, + step: path.ExpressionStepElementKeyValueExact{Value: types.StringNull()}, expected: `[Value()]`, }, "string-unknown": { - step: path.ExpressionStepElementKeyValueExact{Value: types.String{Unknown: true}}, + step: path.ExpressionStepElementKeyValueExact{Value: types.StringUnknown()}, expected: `[Value()]`, }, "string-value": { - step: path.ExpressionStepElementKeyValueExact{Value: types.String{Value: "test"}}, + step: path.ExpressionStepElementKeyValueExact{Value: types.StringValue("test")}, expected: `[Value("test")]`, }, } diff --git a/path/expression_step_parent_test.go b/path/expression_step_parent_test.go index 87701c1a7..e9233237b 100644 --- a/path/expression_step_parent_test.go +++ b/path/expression_step_parent_test.go @@ -33,7 +33,7 @@ func TestExpressionStepParentEqual(t *testing.T) { }, "ExpressionStepElementKeyValueExact": { step: path.ExpressionStepParent{}, - other: path.ExpressionStepElementKeyValueExact{Value: types.String{Value: "test"}}, + other: path.ExpressionStepElementKeyValueExact{Value: types.StringValue("test")}, expected: false, }, "StepParent": { @@ -83,7 +83,7 @@ func TestExpressionStepParentMatches(t *testing.T) { }, "StepElementKeyValue": { step: path.ExpressionStepParent{}, - pathStep: path.PathStepElementKeyValue{Value: types.String{Value: "test"}}, + pathStep: path.PathStepElementKeyValue{Value: types.StringValue("test")}, expected: false, }, } diff --git a/path/expression_steps_test.go b/path/expression_steps_test.go index 09f08de66..7cd81c539 100644 --- a/path/expression_steps_test.go +++ b/path/expression_steps_test.go @@ -221,22 +221,22 @@ func TestExpressionStepsEqual(t *testing.T) { "StepAttributeName-StepElementKeyValue-different": { steps: path.ExpressionSteps{ path.ExpressionStepAttributeNameExact("test"), - path.ExpressionStepElementKeyValueExact{Value: types.String{Value: "test-value"}}, + path.ExpressionStepElementKeyValueExact{Value: types.StringValue("test-value")}, }, other: path.ExpressionSteps{ path.ExpressionStepAttributeNameExact("test"), - path.ExpressionStepElementKeyValueExact{Value: types.String{Value: "not-test-value"}}, + path.ExpressionStepElementKeyValueExact{Value: types.StringValue("not-test-value")}, }, expected: false, }, "StepAttributeName-StepElementKeyValue-equal": { steps: path.ExpressionSteps{ path.ExpressionStepAttributeNameExact("test"), - path.ExpressionStepElementKeyValueExact{Value: types.String{Value: "test-value"}}, + path.ExpressionStepElementKeyValueExact{Value: types.StringValue("test-value")}, }, other: path.ExpressionSteps{ path.ExpressionStepAttributeNameExact("test"), - path.ExpressionStepElementKeyValueExact{Value: types.String{Value: "test-value"}}, + path.ExpressionStepElementKeyValueExact{Value: types.StringValue("test-value")}, }, expected: true, }, @@ -278,19 +278,19 @@ func TestExpressionStepsEqual(t *testing.T) { }, "StepElementKeyValue-different": { steps: path.ExpressionSteps{ - path.ExpressionStepElementKeyValueExact{Value: types.String{Value: "test-value"}}, + path.ExpressionStepElementKeyValueExact{Value: types.StringValue("test-value")}, }, other: path.ExpressionSteps{ - path.ExpressionStepElementKeyValueExact{Value: types.String{Value: "not-test-value"}}, + path.ExpressionStepElementKeyValueExact{Value: types.StringValue("not-test-value")}, }, expected: false, }, "StepElementKeyValue-equal": { steps: path.ExpressionSteps{ - path.ExpressionStepElementKeyValueExact{Value: types.String{Value: "test-value"}}, + path.ExpressionStepElementKeyValueExact{Value: types.StringValue("test-value")}, }, other: path.ExpressionSteps{ - path.ExpressionStepElementKeyValueExact{Value: types.String{Value: "test-value"}}, + path.ExpressionStepElementKeyValueExact{Value: types.StringValue("test-value")}, }, expected: true, }, @@ -578,29 +578,29 @@ func TestExpressionStepsMatches(t *testing.T) { }, pathSteps: path.PathSteps{ path.PathStepAttributeName("test"), - path.PathStepElementKeyValue{Value: types.String{Value: "test-value"}}, + path.PathStepElementKeyValue{Value: types.StringValue("test-value")}, }, expected: true, }, "AttributeNameExact-ElementKeyValueExact-different": { steps: path.ExpressionSteps{ path.ExpressionStepAttributeNameExact("test"), - path.ExpressionStepElementKeyValueExact{Value: types.String{Value: "test-value"}}, + path.ExpressionStepElementKeyValueExact{Value: types.StringValue("test-value")}, }, pathSteps: path.PathSteps{ path.PathStepAttributeName("test"), - path.PathStepElementKeyValue{Value: types.String{Value: "not-test-value"}}, + path.PathStepElementKeyValue{Value: types.StringValue("not-test-value")}, }, expected: false, }, "AttributeNameExact-ElementKeyValueExact-equal": { steps: path.ExpressionSteps{ path.ExpressionStepAttributeNameExact("test"), - path.ExpressionStepElementKeyValueExact{Value: types.String{Value: "test-value"}}, + path.ExpressionStepElementKeyValueExact{Value: types.StringValue("test-value")}, }, pathSteps: path.PathSteps{ path.PathStepAttributeName("test"), - path.PathStepElementKeyValue{Value: types.String{Value: "test-value"}}, + path.PathStepElementKeyValue{Value: types.StringValue("test-value")}, }, expected: true, }, @@ -958,7 +958,7 @@ func TestExpressionStepsMatchesParent(t *testing.T) { }, pathSteps: path.PathSteps{ path.PathStepAttributeName("test"), - path.PathStepElementKeyValue{Value: types.String{Value: "test-value"}}, + path.PathStepElementKeyValue{Value: types.StringValue("test-value")}, }, expected: false, }, @@ -970,41 +970,41 @@ func TestExpressionStepsMatchesParent(t *testing.T) { }, pathSteps: path.PathSteps{ path.PathStepAttributeName("test1"), - path.PathStepElementKeyValue{Value: types.String{Value: "test-value"}}, + path.PathStepElementKeyValue{Value: types.StringValue("test-value")}, }, expected: true, }, "AttributeNameExact-ElementKeyValueExact-different": { steps: path.ExpressionSteps{ path.ExpressionStepAttributeNameExact("test"), - path.ExpressionStepElementKeyValueExact{Value: types.String{Value: "test-value"}}, + path.ExpressionStepElementKeyValueExact{Value: types.StringValue("test-value")}, }, pathSteps: path.PathSteps{ path.PathStepAttributeName("test"), - path.PathStepElementKeyValue{Value: types.String{Value: "not-test-value"}}, + path.PathStepElementKeyValue{Value: types.StringValue("not-test-value")}, }, expected: false, }, "AttributeNameExact-ElementKeyValueExact-equal": { steps: path.ExpressionSteps{ path.ExpressionStepAttributeNameExact("test"), - path.ExpressionStepElementKeyValueExact{Value: types.String{Value: "test-value"}}, + path.ExpressionStepElementKeyValueExact{Value: types.StringValue("test-value")}, }, pathSteps: path.PathSteps{ path.PathStepAttributeName("test"), - path.PathStepElementKeyValue{Value: types.String{Value: "test-value"}}, + path.PathStepElementKeyValue{Value: types.StringValue("test-value")}, }, expected: false, }, "AttributeNameExact-ElementKeyValueExact-parent": { steps: path.ExpressionSteps{ path.ExpressionStepAttributeNameExact("test1"), - path.ExpressionStepElementKeyValueExact{Value: types.String{Value: "test-value"}}, + path.ExpressionStepElementKeyValueExact{Value: types.StringValue("test-value")}, path.ExpressionStepAttributeNameExact("test2"), }, pathSteps: path.PathSteps{ path.PathStepAttributeName("test1"), - path.PathStepElementKeyValue{Value: types.String{Value: "test-value"}}, + path.PathStepElementKeyValue{Value: types.StringValue("test-value")}, }, expected: true, }, @@ -1349,23 +1349,23 @@ func TestExpressionStepsString(t *testing.T) { "AttributeName-ElementKeyValue": { steps: path.ExpressionSteps{ path.ExpressionStepAttributeNameExact("test"), - path.ExpressionStepElementKeyValueExact{Value: types.String{Value: "test-value"}}, + path.ExpressionStepElementKeyValueExact{Value: types.StringValue("test-value")}, }, expected: `test[Value("test-value")]`, }, "AttributeName-ElementKeyValue-AttributeName": { steps: path.ExpressionSteps{ path.ExpressionStepAttributeNameExact("test"), - path.ExpressionStepElementKeyValueExact{Value: types.Object{ - Attrs: map[string]attr.Value{ - "test_attr_1": types.Bool{Value: true}, - "test_attr_2": types.String{Value: "test-value"}, - }, - AttrTypes: map[string]attr.Type{ + path.ExpressionStepElementKeyValueExact{Value: types.ObjectValueMust( + map[string]attr.Type{ "test_attr_1": types.BoolType, "test_attr_2": types.StringType, }, - }}, + map[string]attr.Value{ + "test_attr_1": types.BoolValue(true), + "test_attr_2": types.StringValue("test-value"), + }, + )}, path.ExpressionStepAttributeNameExact("test_attr_1"), }, expected: `test[Value({"test_attr_1":true,"test_attr_2":"test-value"})].test_attr_1`, @@ -1384,7 +1384,7 @@ func TestExpressionStepsString(t *testing.T) { }, "ElementKeyValue": { steps: path.ExpressionSteps{ - path.ExpressionStepElementKeyValueExact{Value: types.String{Value: "test"}}, + path.ExpressionStepElementKeyValueExact{Value: types.StringValue("test")}, }, expected: `[Value("test")]`, }, diff --git a/path/expression_test.go b/path/expression_test.go index 3f893c0d3..c91590026 100644 --- a/path/expression_test.go +++ b/path/expression_test.go @@ -252,13 +252,13 @@ func TestExpressionAtSetValue(t *testing.T) { }{ "shallow": { expression: path.MatchRoot("test"), - value: types.String{Value: "test"}, - expected: path.MatchRoot("test").AtSetValue(types.String{Value: "test"}), + value: types.StringValue("test"), + expected: path.MatchRoot("test").AtSetValue(types.StringValue("test")), }, "deep": { expression: path.MatchRoot("test1").AtListIndex(0).AtName("test2"), - value: types.String{Value: "test"}, - expected: path.MatchRoot("test1").AtListIndex(0).AtName("test2").AtSetValue(types.String{Value: "test"}), + value: types.StringValue("test"), + expected: path.MatchRoot("test1").AtListIndex(0).AtName("test2").AtSetValue(types.StringValue("test")), }, } @@ -459,17 +459,17 @@ func TestExpressionMatches(t *testing.T) { }, "AttributeNameExact-ElementKeyValueAny": { expression: path.MatchRoot("test").AtAnySetValue(), - path: path.Root("test").AtSetValue(types.String{Value: "test-value"}), + path: path.Root("test").AtSetValue(types.StringValue("test-value")), expected: true, }, "AttributeNameExact-ElementKeyValueExact-different": { - expression: path.MatchRoot("test").AtSetValue(types.String{Value: "test-value"}), - path: path.Root("test").AtSetValue(types.String{Value: "not-test-value"}), + expression: path.MatchRoot("test").AtSetValue(types.StringValue("test-value")), + path: path.Root("test").AtSetValue(types.StringValue("not-test-value")), expected: false, }, "AttributeNameExact-ElementKeyValueExact-equal": { - expression: path.MatchRoot("test").AtSetValue(types.String{Value: "test-value"}), - path: path.Root("test").AtSetValue(types.String{Value: "test-value"}), + expression: path.MatchRoot("test").AtSetValue(types.StringValue("test-value")), + path: path.Root("test").AtSetValue(types.StringValue("test-value")), expected: true, }, "AttributeNameExact-Parent-AttributeNameExact-different": { @@ -644,27 +644,27 @@ func TestExpressionMatchesParent(t *testing.T) { }, "AttributeNameExact-ElementKeyValueAny": { expression: path.MatchRoot("test").AtAnySetValue(), - path: path.Root("test").AtSetValue(types.String{Value: "test-value"}), + path: path.Root("test").AtSetValue(types.StringValue("test-value")), expected: false, }, "AttributeNameExact-ElementKeyValueAny-parent": { expression: path.MatchRoot("test1").AtAnySetValue().AtName("test2"), - path: path.Root("test1").AtSetValue(types.String{Value: "test-value"}), + path: path.Root("test1").AtSetValue(types.StringValue("test-value")), expected: true, }, "AttributeNameExact-ElementKeyValueExact-different": { - expression: path.MatchRoot("test").AtSetValue(types.String{Value: "test-value"}), - path: path.Root("test").AtSetValue(types.String{Value: "not-test-value"}), + expression: path.MatchRoot("test").AtSetValue(types.StringValue("test-value")), + path: path.Root("test").AtSetValue(types.StringValue("not-test-value")), expected: false, }, "AttributeNameExact-ElementKeyValueExact-equal": { - expression: path.MatchRoot("test").AtSetValue(types.String{Value: "test-value"}), - path: path.Root("test").AtSetValue(types.String{Value: "test-value"}), + expression: path.MatchRoot("test").AtSetValue(types.StringValue("test-value")), + path: path.Root("test").AtSetValue(types.StringValue("test-value")), expected: false, }, "AttributeNameExact-ElementKeyValueExact-parent": { - expression: path.MatchRoot("test1").AtSetValue(types.String{Value: "test-value"}).AtName("test2"), - path: path.Root("test1").AtSetValue(types.String{Value: "test-value"}), + expression: path.MatchRoot("test1").AtSetValue(types.StringValue("test-value")).AtName("test2"), + path: path.Root("test1").AtSetValue(types.StringValue("test-value")), expected: true, }, "AttributeNameExact-Parent": { @@ -989,20 +989,20 @@ func TestExpressionString(t *testing.T) { expected: `test[Value(*)]`, }, "AttributeNameExact-ElementKeyValueExact": { - expression: path.MatchRoot("test").AtSetValue(types.String{Value: "test-value"}), + expression: path.MatchRoot("test").AtSetValue(types.StringValue("test-value")), expected: `test[Value("test-value")]`, }, "AttributeNameExact-ElementKeyValue-AttributeNameExact": { - expression: path.MatchRoot("test").AtSetValue(types.Object{ - Attrs: map[string]attr.Value{ - "test_attr_1": types.Bool{Value: true}, - "test_attr_2": types.String{Value: "test-value"}, - }, - AttrTypes: map[string]attr.Type{ + expression: path.MatchRoot("test").AtSetValue(types.ObjectValueMust( + map[string]attr.Type{ "test_attr_1": types.BoolType, "test_attr_2": types.StringType, }, - }).AtName("test_attr_1"), + map[string]attr.Value{ + "test_attr_1": types.BoolValue(true), + "test_attr_2": types.StringValue("test-value"), + }, + )).AtName("test_attr_1"), expected: `test[Value({"test_attr_1":true,"test_attr_2":"test-value"})].test_attr_1`, }, } diff --git a/path/expressions_test.go b/path/expressions_test.go index ed4786313..747a31266 100644 --- a/path/expressions_test.go +++ b/path/expressions_test.go @@ -192,16 +192,16 @@ func TestExpressionsContains(t *testing.T) { }, "ElementKeyValue-different": { expressions: path.Expressions{ - path.MatchRelative().AtSetValue(types.String{Value: "test"}), + path.MatchRelative().AtSetValue(types.StringValue("test")), }, - contains: path.MatchRelative().AtSetValue(types.String{Value: "not-test"}), + contains: path.MatchRelative().AtSetValue(types.StringValue("not-test")), expected: false, }, "ElementKeyValue-equal": { expressions: path.Expressions{ - path.MatchRelative().AtSetValue(types.String{Value: "test"}), + path.MatchRelative().AtSetValue(types.StringValue("test")), }, - contains: path.MatchRelative().AtSetValue(types.String{Value: "test"}), + contains: path.MatchRelative().AtSetValue(types.StringValue("test")), expected: true, }, } diff --git a/path/path_step_attribute_name_test.go b/path/path_step_attribute_name_test.go index 15ce073ff..74eb63211 100644 --- a/path/path_step_attribute_name_test.go +++ b/path/path_step_attribute_name_test.go @@ -38,7 +38,7 @@ func TestPathStepAttributeNameEqual(t *testing.T) { }, "PathStepElementKeyValue": { step: path.PathStepAttributeName("test"), - other: path.PathStepElementKeyValue{Value: types.String{Value: "test"}}, + other: path.PathStepElementKeyValue{Value: types.StringValue("test")}, expected: false, }, } diff --git a/path/path_step_element_key_int_test.go b/path/path_step_element_key_int_test.go index f03a74db2..d5081d8bc 100644 --- a/path/path_step_element_key_int_test.go +++ b/path/path_step_element_key_int_test.go @@ -38,7 +38,7 @@ func TestPathStepElementKeyIntEqual(t *testing.T) { }, "PathStepElementKeyValue": { step: path.PathStepElementKeyInt(0), - other: path.PathStepElementKeyValue{Value: types.String{Value: "test"}}, + other: path.PathStepElementKeyValue{Value: types.StringValue("test")}, expected: false, }, } diff --git a/path/path_step_element_key_string_test.go b/path/path_step_element_key_string_test.go index a98f4de1c..4cf51d458 100644 --- a/path/path_step_element_key_string_test.go +++ b/path/path_step_element_key_string_test.go @@ -38,7 +38,7 @@ func TestPathStepElementKeyStringEqual(t *testing.T) { }, "PathStepElementKeyValue": { step: path.PathStepElementKeyString("test"), - other: path.PathStepElementKeyValue{Value: types.String{Value: "test"}}, + other: path.PathStepElementKeyValue{Value: types.StringValue("test")}, expected: false, }, } diff --git a/path/path_step_element_key_value_test.go b/path/path_step_element_key_value_test.go index 6be90b128..5160158d1 100644 --- a/path/path_step_element_key_value_test.go +++ b/path/path_step_element_key_value_test.go @@ -18,33 +18,33 @@ func TestPathStepElementKeyValueEqual(t *testing.T) { expected bool }{ "PathStepAttributeName": { - step: path.PathStepElementKeyValue{Value: types.String{Value: "test"}}, + step: path.PathStepElementKeyValue{Value: types.StringValue("test")}, other: path.PathStepAttributeName("test"), expected: false, }, "PathStepElementKeyInt": { - step: path.PathStepElementKeyValue{Value: types.String{Value: "test"}}, + step: path.PathStepElementKeyValue{Value: types.StringValue("test")}, other: path.PathStepElementKeyInt(0), expected: false, }, "PathStepElementKeyString": { - step: path.PathStepElementKeyValue{Value: types.String{Value: "test"}}, + step: path.PathStepElementKeyValue{Value: types.StringValue("test")}, other: path.PathStepElementKeyString("test"), expected: false, }, "PathStepElementKeyValue-different-type": { - step: path.PathStepElementKeyValue{Value: types.Bool{Value: true}}, - other: path.PathStepElementKeyValue{Value: types.String{Value: "not-test"}}, + step: path.PathStepElementKeyValue{Value: types.BoolValue(true)}, + other: path.PathStepElementKeyValue{Value: types.StringValue("not-test")}, expected: false, }, "PathStepElementKeyValue-different-value": { - step: path.PathStepElementKeyValue{Value: types.String{Value: "test"}}, - other: path.PathStepElementKeyValue{Value: types.String{Value: "not-test"}}, + step: path.PathStepElementKeyValue{Value: types.StringValue("test")}, + other: path.PathStepElementKeyValue{Value: types.StringValue("not-test")}, expected: false, }, "PathStepElementKeyValue-equal": { - step: path.PathStepElementKeyValue{Value: types.String{Value: "test"}}, - other: path.PathStepElementKeyValue{Value: types.String{Value: "test"}}, + step: path.PathStepElementKeyValue{Value: types.StringValue("test")}, + other: path.PathStepElementKeyValue{Value: types.StringValue("test")}, expected: true, }, } @@ -72,8 +72,8 @@ func TestPathStepElementKeyValueExpressionStep(t *testing.T) { expected path.ExpressionStep }{ "basic": { - step: path.PathStepElementKeyValue{Value: types.String{Value: "test"}}, - expected: path.ExpressionStepElementKeyValueExact{Value: types.String{Value: "test"}}, + step: path.PathStepElementKeyValue{Value: types.StringValue("test")}, + expected: path.ExpressionStepElementKeyValueExact{Value: types.StringValue("test")}, }, } @@ -100,60 +100,60 @@ func TestPathStepElementKeyValueString(t *testing.T) { expected string }{ "bool-value": { - step: path.PathStepElementKeyValue{Value: types.Bool{Value: true}}, + step: path.PathStepElementKeyValue{Value: types.BoolValue(true)}, expected: `[Value(true)]`, }, "float64-value": { - step: path.PathStepElementKeyValue{Value: types.Float64{Value: 1.2}}, + step: path.PathStepElementKeyValue{Value: types.Float64Value(1.2)}, expected: `[Value(1.200000)]`, }, "int64-value": { - step: path.PathStepElementKeyValue{Value: types.Int64{Value: 123}}, + step: path.PathStepElementKeyValue{Value: types.Int64Value(123)}, expected: `[Value(123)]`, }, "list-value": { - step: path.PathStepElementKeyValue{Value: types.List{ - Elems: []attr.Value{ - types.String{Value: "test-element-1"}, - types.String{Value: "test-element-2"}, + step: path.PathStepElementKeyValue{Value: types.ListValueMust( + types.StringType, + []attr.Value{ + types.StringValue("test-element-1"), + types.StringValue("test-element-2"), }, - ElemType: types.StringType, - }}, + )}, expected: `[Value(["test-element-1","test-element-2"])]`, }, "map-value": { - step: path.PathStepElementKeyValue{Value: types.Map{ - Elems: map[string]attr.Value{ - "test-key-1": types.String{Value: "test-value-1"}, - "test-key-2": types.String{Value: "test-value-2"}, + step: path.PathStepElementKeyValue{Value: types.MapValueMust( + types.StringType, + map[string]attr.Value{ + "test-key-1": types.StringValue("test-value-1"), + "test-key-2": types.StringValue("test-value-2"), }, - ElemType: types.StringType, - }}, + )}, expected: `[Value({"test-key-1":"test-value-1","test-key-2":"test-value-2"})]`, }, "object-value": { - step: path.PathStepElementKeyValue{Value: types.Object{ - Attrs: map[string]attr.Value{ - "test_attr_1": types.Bool{Value: true}, - "test_attr_2": types.String{Value: "test-value"}, - }, - AttrTypes: map[string]attr.Type{ + step: path.PathStepElementKeyValue{Value: types.ObjectValueMust( + map[string]attr.Type{ "test_attr_1": types.BoolType, "test_attr_2": types.StringType, }, - }}, + map[string]attr.Value{ + "test_attr_1": types.BoolValue(true), + "test_attr_2": types.StringValue("test-value"), + }, + )}, expected: `[Value({"test_attr_1":true,"test_attr_2":"test-value"})]`, }, "string-null": { - step: path.PathStepElementKeyValue{Value: types.String{Null: true}}, + step: path.PathStepElementKeyValue{Value: types.StringNull()}, expected: `[Value()]`, }, "string-unknown": { - step: path.PathStepElementKeyValue{Value: types.String{Unknown: true}}, + step: path.PathStepElementKeyValue{Value: types.StringUnknown()}, expected: `[Value()]`, }, "string-value": { - step: path.PathStepElementKeyValue{Value: types.String{Value: "test"}}, + step: path.PathStepElementKeyValue{Value: types.StringValue("test")}, expected: `[Value("test")]`, }, } diff --git a/path/path_steps_test.go b/path/path_steps_test.go index dbff0f134..f72f57382 100644 --- a/path/path_steps_test.go +++ b/path/path_steps_test.go @@ -221,22 +221,22 @@ func TestPathStepsEqual(t *testing.T) { "PathStepAttributeName-PathStepElementKeyValue-different": { steps: path.PathSteps{ path.PathStepAttributeName("test"), - path.PathStepElementKeyValue{Value: types.String{Value: "test-value"}}, + path.PathStepElementKeyValue{Value: types.StringValue("test-value")}, }, other: path.PathSteps{ path.PathStepAttributeName("test"), - path.PathStepElementKeyValue{Value: types.String{Value: "not-test-value"}}, + path.PathStepElementKeyValue{Value: types.StringValue("not-test-value")}, }, expected: false, }, "PathStepAttributeName-PathStepElementKeyValue-equal": { steps: path.PathSteps{ path.PathStepAttributeName("test"), - path.PathStepElementKeyValue{Value: types.String{Value: "test-value"}}, + path.PathStepElementKeyValue{Value: types.StringValue("test-value")}, }, other: path.PathSteps{ path.PathStepAttributeName("test"), - path.PathStepElementKeyValue{Value: types.String{Value: "test-value"}}, + path.PathStepElementKeyValue{Value: types.StringValue("test-value")}, }, expected: true, }, @@ -278,19 +278,19 @@ func TestPathStepsEqual(t *testing.T) { }, "PathStepElementKeyValue-different": { steps: path.PathSteps{ - path.PathStepElementKeyValue{Value: types.String{Value: "test-value"}}, + path.PathStepElementKeyValue{Value: types.StringValue("test-value")}, }, other: path.PathSteps{ - path.PathStepElementKeyValue{Value: types.String{Value: "not-test-value"}}, + path.PathStepElementKeyValue{Value: types.StringValue("not-test-value")}, }, expected: false, }, "PathStepElementKeyValue-equal": { steps: path.PathSteps{ - path.PathStepElementKeyValue{Value: types.String{Value: "test-value"}}, + path.PathStepElementKeyValue{Value: types.StringValue("test-value")}, }, other: path.PathSteps{ - path.PathStepElementKeyValue{Value: types.String{Value: "test-value"}}, + path.PathStepElementKeyValue{Value: types.StringValue("test-value")}, }, expected: true, }, @@ -582,23 +582,23 @@ func TestPathStepsString(t *testing.T) { "AttributeName-ElementKeyValue": { steps: path.PathSteps{ path.PathStepAttributeName("test"), - path.PathStepElementKeyValue{Value: types.String{Value: "test-value"}}, + path.PathStepElementKeyValue{Value: types.StringValue("test-value")}, }, expected: `test[Value("test-value")]`, }, "AttributeName-ElementKeyValue-AttributeName": { steps: path.PathSteps{ path.PathStepAttributeName("test"), - path.PathStepElementKeyValue{Value: types.Object{ - Attrs: map[string]attr.Value{ - "test_attr_1": types.Bool{Value: true}, - "test_attr_2": types.String{Value: "test-value"}, - }, - AttrTypes: map[string]attr.Type{ + path.PathStepElementKeyValue{Value: types.ObjectValueMust( + map[string]attr.Type{ "test_attr_1": types.BoolType, "test_attr_2": types.StringType, }, - }}, + map[string]attr.Value{ + "test_attr_1": types.BoolValue(true), + "test_attr_2": types.StringValue("test-value"), + }, + )}, path.PathStepAttributeName("test_attr_1"), }, expected: `test[Value({"test_attr_1":true,"test_attr_2":"test-value"})].test_attr_1`, @@ -617,7 +617,7 @@ func TestPathStepsString(t *testing.T) { }, "ElementKeyValue": { steps: path.PathSteps{ - path.PathStepElementKeyValue{Value: types.String{Value: "test"}}, + path.PathStepElementKeyValue{Value: types.StringValue("test")}, }, expected: `[Value("test")]`, }, diff --git a/path/path_test.go b/path/path_test.go index 711fb23d0..b2227e28c 100644 --- a/path/path_test.go +++ b/path/path_test.go @@ -139,18 +139,18 @@ func TestPathAtSetValue(t *testing.T) { }{ "empty": { path: path.Empty(), - value: types.String{Value: "test"}, - expected: path.Empty().AtSetValue(types.String{Value: "test"}), + value: types.StringValue("test"), + expected: path.Empty().AtSetValue(types.StringValue("test")), }, "shallow": { path: path.Root("test"), - value: types.String{Value: "test"}, - expected: path.Root("test").AtSetValue(types.String{Value: "test"}), + value: types.StringValue("test"), + expected: path.Root("test").AtSetValue(types.StringValue("test")), }, "deep": { path: path.Root("test1").AtListIndex(0).AtName("test2"), - value: types.String{Value: "test"}, - expected: path.Root("test1").AtListIndex(0).AtName("test2").AtSetValue(types.String{Value: "test"}), + value: types.StringValue("test"), + expected: path.Root("test1").AtListIndex(0).AtName("test2").AtSetValue(types.StringValue("test")), }, } @@ -417,20 +417,20 @@ func TestPathString(t *testing.T) { expected: `test["test-key1"]["test-key2"]`, }, "AttributeName-ElementKeyValue": { - path: path.Root("test").AtSetValue(types.String{Value: "test-value"}), + path: path.Root("test").AtSetValue(types.StringValue("test-value")), expected: `test[Value("test-value")]`, }, "AttributeName-ElementKeyValue-AttributeName": { - path: path.Root("test").AtSetValue(types.Object{ - Attrs: map[string]attr.Value{ - "test_attr_1": types.Bool{Value: true}, - "test_attr_2": types.String{Value: "test-value"}, - }, - AttrTypes: map[string]attr.Type{ + path: path.Root("test").AtSetValue(types.ObjectValueMust( + map[string]attr.Type{ "test_attr_1": types.BoolType, "test_attr_2": types.StringType, }, - }).AtName("test_attr_1"), + map[string]attr.Value{ + "test_attr_1": types.BoolValue(true), + "test_attr_2": types.StringValue("test-value"), + }, + )).AtName("test_attr_1"), expected: `test[Value({"test_attr_1":true,"test_attr_2":"test-value"})].test_attr_1`, }, "ElementKeyInt": { @@ -442,7 +442,7 @@ func TestPathString(t *testing.T) { expected: `["test"]`, }, "ElementKeyValue": { - path: path.Empty().AtSetValue(types.String{Value: "test"}), + path: path.Empty().AtSetValue(types.StringValue("test")), expected: `[Value("test")]`, }, } diff --git a/path/paths_test.go b/path/paths_test.go index e8d5acbe6..57a1fe44a 100644 --- a/path/paths_test.go +++ b/path/paths_test.go @@ -185,16 +185,16 @@ func TestPathsContains(t *testing.T) { }, "ElementKeyValue-different": { paths: path.Paths{ - path.Empty().AtSetValue(types.String{Value: "test"}), + path.Empty().AtSetValue(types.StringValue("test")), }, - contains: path.Empty().AtSetValue(types.String{Value: "not-test"}), + contains: path.Empty().AtSetValue(types.StringValue("not-test")), expected: false, }, "ElementKeyValue-equal": { paths: path.Paths{ - path.Empty().AtSetValue(types.String{Value: "test"}), + path.Empty().AtSetValue(types.StringValue("test")), }, - contains: path.Empty().AtSetValue(types.String{Value: "test"}), + contains: path.Empty().AtSetValue(types.StringValue("test")), expected: true, }, } diff --git a/resource/plan_modifiers_test.go b/resource/plan_modifiers_test.go index b5df6482b..ba985bc67 100644 --- a/resource/plan_modifiers_test.go +++ b/resource/plan_modifiers_test.go @@ -29,25 +29,25 @@ func TestUseStateForUnknownModifier(t *testing.T) { // this honestly just shouldn't happen, but let's be // sure we're not going to panic if it does state: nil, - plan: types.String{Unknown: true}, - config: types.String{Null: true}, - expected: types.String{Unknown: true}, + plan: types.StringUnknown(), + config: types.StringNull(), + expected: types.StringUnknown(), }, "nil-plan": { // this honestly just shouldn't happen, but let's be // sure we're not going to panic if it does - state: types.String{Null: true}, + state: types.StringNull(), plan: nil, - config: types.String{Null: true}, + config: types.StringNull(), expected: nil, }, "null-state": { // when we first create the resource, use the unknown // value - state: types.String{Null: true}, - plan: types.String{Unknown: true}, - config: types.String{Null: true}, - expected: types.String{Unknown: true}, + state: types.StringNull(), + plan: types.StringUnknown(), + config: types.StringNull(), + expected: types.StringUnknown(), }, "known-plan": { // this would really only happen if we had a plan @@ -56,18 +56,18 @@ func TestUseStateForUnknownModifier(t *testing.T) { // // but we still want to preserve that value, in this // case - state: types.String{Value: "foo"}, - plan: types.String{Value: "bar"}, - config: types.String{Null: true}, - expected: types.String{Value: "bar"}, + state: types.StringValue("foo"), + plan: types.StringValue("bar"), + config: types.StringNull(), + expected: types.StringValue("bar"), }, "non-null-state-unknown-plan": { // this is the situation we want to preserve the state // in - state: types.String{Value: "foo"}, - plan: types.String{Unknown: true}, - config: types.String{Null: true}, - expected: types.String{Value: "foo"}, + state: types.StringValue("foo"), + plan: types.StringUnknown(), + config: types.StringNull(), + expected: types.StringValue("foo"), }, "unknown-config": { // this is the situation in which a user is @@ -76,10 +76,10 @@ func TestUseStateForUnknownModifier(t *testing.T) { // errors for changing the value even though we knew it // was legitimately possible for it to change and the // provider can't prevent this from happening - state: types.String{Value: "foo"}, - plan: types.String{Unknown: true}, - config: types.String{Unknown: true}, - expected: types.String{Unknown: true}, + state: types.StringValue("foo"), + plan: types.StringUnknown(), + config: types.StringUnknown(), + expected: types.StringUnknown(), }, } @@ -232,7 +232,7 @@ func TestRequiresReplaceModifier(t *testing.T) { }), }, path: path.Root("optional-computed"), - expectedPlan: types.String{Value: "foo"}, + expectedPlan: types.StringValue("foo"), expectedRR: false, }, "null-plan": { @@ -287,7 +287,7 @@ func TestRequiresReplaceModifier(t *testing.T) { }), }, path: path.Root("optional"), - expectedPlan: types.String{Value: "bar"}, + expectedPlan: types.StringValue("bar"), expectedRR: true, }, "null-attribute-plan": { @@ -316,7 +316,7 @@ func TestRequiresReplaceModifier(t *testing.T) { }), }, path: path.Root("optional"), - expectedPlan: types.String{Null: true}, + expectedPlan: types.StringNull(), expectedRR: true, }, "known-state-change": { @@ -344,7 +344,7 @@ func TestRequiresReplaceModifier(t *testing.T) { }), }, path: path.Root("optional"), - expectedPlan: types.String{Value: "quux"}, + expectedPlan: types.StringValue("quux"), expectedRR: true, }, "known-state-no-change": { @@ -372,7 +372,7 @@ func TestRequiresReplaceModifier(t *testing.T) { }), }, path: path.Root("optional-computed"), - expectedPlan: types.String{Value: "foo"}, + expectedPlan: types.StringValue("foo"), expectedRR: false, }, "null-config-computed": { @@ -407,7 +407,7 @@ func TestRequiresReplaceModifier(t *testing.T) { }), }, path: path.Root("optional-computed"), - expectedPlan: types.String{Unknown: true}, + expectedPlan: types.StringUnknown(), expectedRR: false, }, "null-config-not-computed": { @@ -443,7 +443,7 @@ func TestRequiresReplaceModifier(t *testing.T) { }), }, path: path.Root("optional"), - expectedPlan: types.String{Null: true}, + expectedPlan: types.StringNull(), expectedRR: true, }, "block-no-change": { @@ -520,26 +520,26 @@ func TestRequiresReplaceModifier(t *testing.T) { }), }, path: path.Root("block"), - expectedPlan: types.List{ - ElemType: types.ObjectType{ + expectedPlan: types.ListValueMust( + types.ObjectType{ AttrTypes: map[string]attr.Type{ "optional-computed": types.StringType, "optional": types.StringType, }, }, - Elems: []attr.Value{ - types.Object{ - AttrTypes: map[string]attr.Type{ + []attr.Value{ + types.ObjectValueMust( + map[string]attr.Type{ "optional-computed": types.StringType, "optional": types.StringType, }, - Attrs: map[string]attr.Value{ - "optional-computed": types.String{Value: "samevalue"}, - "optional": types.String{Value: "samevalue"}, + map[string]attr.Value{ + "optional-computed": types.StringValue("samevalue"), + "optional": types.StringValue("samevalue"), }, - }, + ), }, - }, + ), expectedRR: false, }, "block-element-count-change": { @@ -634,36 +634,36 @@ func TestRequiresReplaceModifier(t *testing.T) { }), }, path: path.Root("block"), - expectedPlan: types.List{ - ElemType: types.ObjectType{ + expectedPlan: types.ListValueMust( + types.ObjectType{ AttrTypes: map[string]attr.Type{ "optional-computed": types.StringType, "optional": types.StringType, }, }, - Elems: []attr.Value{ - types.Object{ - AttrTypes: map[string]attr.Type{ + []attr.Value{ + types.ObjectValueMust( + map[string]attr.Type{ "optional-computed": types.StringType, "optional": types.StringType, }, - Attrs: map[string]attr.Value{ - "optional-computed": types.String{Value: "samevalue"}, - "optional": types.String{Value: "samevalue"}, + map[string]attr.Value{ + "optional-computed": types.StringValue("samevalue"), + "optional": types.StringValue("samevalue"), }, - }, - types.Object{ - AttrTypes: map[string]attr.Type{ + ), + types.ObjectValueMust( + map[string]attr.Type{ "optional-computed": types.StringType, "optional": types.StringType, }, - Attrs: map[string]attr.Value{ - "optional-computed": types.String{Value: "newvalue"}, - "optional": types.String{Value: "newvalue"}, + map[string]attr.Value{ + "optional-computed": types.StringValue("newvalue"), + "optional": types.StringValue("newvalue"), }, - }, + ), }, - }, + ), expectedRR: true, }, "block-nested-attribute-change": { @@ -740,26 +740,26 @@ func TestRequiresReplaceModifier(t *testing.T) { }), }, path: path.Root("block"), - expectedPlan: types.List{ - ElemType: types.ObjectType{ + expectedPlan: types.ListValueMust( + types.ObjectType{ AttrTypes: map[string]attr.Type{ "optional-computed": types.StringType, "optional": types.StringType, }, }, - Elems: []attr.Value{ - types.Object{ - AttrTypes: map[string]attr.Type{ + []attr.Value{ + types.ObjectValueMust( + map[string]attr.Type{ "optional-computed": types.StringType, "optional": types.StringType, }, - Attrs: map[string]attr.Value{ - "optional-computed": types.String{Value: "samevalue"}, - "optional": types.String{Value: "newvalue"}, + map[string]attr.Value{ + "optional-computed": types.StringValue("samevalue"), + "optional": types.StringValue("newvalue"), }, - }, + ), }, - }, + ), expectedRR: true, }, } @@ -890,7 +890,7 @@ func TestRequiresReplaceIfModifier(t *testing.T) { priorRR: false, path: path.Root("optional-computed"), ifReturn: true, - expectedPlan: types.String{Value: "foo"}, + expectedPlan: types.StringValue("foo"), expectedRR: false, }, "null-plan": { @@ -949,7 +949,7 @@ func TestRequiresReplaceIfModifier(t *testing.T) { priorRR: false, path: path.Root("optional"), ifReturn: true, - expectedPlan: types.String{Value: "bar"}, + expectedPlan: types.StringValue("bar"), expectedRR: true, }, "null-attribute-plan": { @@ -980,7 +980,7 @@ func TestRequiresReplaceIfModifier(t *testing.T) { priorRR: false, ifReturn: true, path: path.Root("optional"), - expectedPlan: types.String{Null: true}, + expectedPlan: types.StringNull(), expectedRR: true, }, "known-state-change-true": { @@ -1011,7 +1011,7 @@ func TestRequiresReplaceIfModifier(t *testing.T) { priorRR: false, path: path.Root("optional"), ifReturn: true, - expectedPlan: types.String{Value: "quux"}, + expectedPlan: types.StringValue("quux"), expectedRR: true, }, "known-state-change-false": { @@ -1042,7 +1042,7 @@ func TestRequiresReplaceIfModifier(t *testing.T) { priorRR: false, path: path.Root("optional"), ifReturn: false, - expectedPlan: types.String{Value: "quux"}, + expectedPlan: types.StringValue("quux"), expectedRR: false, }, "known-state-change-false-dont-override": { @@ -1074,7 +1074,7 @@ func TestRequiresReplaceIfModifier(t *testing.T) { priorRR: true, path: path.Root("optional"), ifReturn: false, - expectedPlan: types.String{Value: "quux"}, + expectedPlan: types.StringValue("quux"), expectedRR: true, }, "known-state-no-change": { @@ -1104,7 +1104,7 @@ func TestRequiresReplaceIfModifier(t *testing.T) { priorRR: false, path: path.Root("optional-computed"), ifReturn: true, - expectedPlan: types.String{Value: "foo"}, + expectedPlan: types.StringValue("foo"), expectedRR: false, }, "null-config-computed": { @@ -1141,7 +1141,7 @@ func TestRequiresReplaceIfModifier(t *testing.T) { priorRR: false, path: path.Root("optional-computed"), ifReturn: true, - expectedPlan: types.String{Unknown: true}, + expectedPlan: types.StringUnknown(), expectedRR: false, }, "null-config-not-computed": { @@ -1179,7 +1179,7 @@ func TestRequiresReplaceIfModifier(t *testing.T) { priorRR: false, path: path.Root("optional"), ifReturn: true, - expectedPlan: types.String{Null: true}, + expectedPlan: types.StringNull(), expectedRR: true, }, "block-no-change": { @@ -1256,26 +1256,26 @@ func TestRequiresReplaceIfModifier(t *testing.T) { }), }, path: path.Root("block"), - expectedPlan: types.List{ - ElemType: types.ObjectType{ + expectedPlan: types.ListValueMust( + types.ObjectType{ AttrTypes: map[string]attr.Type{ "optional-computed": types.StringType, "optional": types.StringType, }, }, - Elems: []attr.Value{ - types.Object{ - AttrTypes: map[string]attr.Type{ + []attr.Value{ + types.ObjectValueMust( + map[string]attr.Type{ "optional-computed": types.StringType, "optional": types.StringType, }, - Attrs: map[string]attr.Value{ - "optional-computed": types.String{Value: "samevalue"}, - "optional": types.String{Value: "samevalue"}, + map[string]attr.Value{ + "optional-computed": types.StringValue("samevalue"), + "optional": types.StringValue("samevalue"), }, - }, + ), }, - }, + ), ifReturn: false, expectedRR: false, }, @@ -1371,36 +1371,36 @@ func TestRequiresReplaceIfModifier(t *testing.T) { }), }, path: path.Root("block"), - expectedPlan: types.List{ - ElemType: types.ObjectType{ + expectedPlan: types.ListValueMust( + types.ObjectType{ AttrTypes: map[string]attr.Type{ "optional-computed": types.StringType, "optional": types.StringType, }, }, - Elems: []attr.Value{ - types.Object{ - AttrTypes: map[string]attr.Type{ + []attr.Value{ + types.ObjectValueMust( + map[string]attr.Type{ "optional-computed": types.StringType, "optional": types.StringType, }, - Attrs: map[string]attr.Value{ - "optional-computed": types.String{Value: "samevalue"}, - "optional": types.String{Value: "samevalue"}, + map[string]attr.Value{ + "optional-computed": types.StringValue("samevalue"), + "optional": types.StringValue("samevalue"), }, - }, - types.Object{ - AttrTypes: map[string]attr.Type{ + ), + types.ObjectValueMust( + map[string]attr.Type{ "optional-computed": types.StringType, "optional": types.StringType, }, - Attrs: map[string]attr.Value{ - "optional-computed": types.String{Value: "newvalue"}, - "optional": types.String{Value: "newvalue"}, + map[string]attr.Value{ + "optional-computed": types.StringValue("newvalue"), + "optional": types.StringValue("newvalue"), }, - }, + ), }, - }, + ), ifReturn: true, expectedRR: true, }, @@ -1478,26 +1478,26 @@ func TestRequiresReplaceIfModifier(t *testing.T) { }), }, path: path.Root("block"), - expectedPlan: types.List{ - ElemType: types.ObjectType{ + expectedPlan: types.ListValueMust( + types.ObjectType{ AttrTypes: map[string]attr.Type{ "optional-computed": types.StringType, "optional": types.StringType, }, }, - Elems: []attr.Value{ - types.Object{ - AttrTypes: map[string]attr.Type{ + []attr.Value{ + types.ObjectValueMust( + map[string]attr.Type{ "optional-computed": types.StringType, "optional": types.StringType, }, - Attrs: map[string]attr.Value{ - "optional-computed": types.String{Value: "samevalue"}, - "optional": types.String{Value: "newvalue"}, + map[string]attr.Value{ + "optional-computed": types.StringValue("samevalue"), + "optional": types.StringValue("newvalue"), }, - }, + ), }, - }, + ), ifReturn: true, expectedRR: true, }, diff --git a/tfsdk/config_test.go b/tfsdk/config_test.go index 44d5439e1..402e009a7 100644 --- a/tfsdk/config_test.go +++ b/tfsdk/config_test.go @@ -53,7 +53,7 @@ func TestConfigGet(t *testing.T) { expected: &struct { String types.String `tfsdk:"string"` }{ - String: types.String{Value: "test"}, + String: types.StringValue("test"), }, }, "diagnostic": { @@ -171,7 +171,7 @@ func TestConfigGetAttribute(t *testing.T) { }, }, target: new(testtypes.String), - expected: &testtypes.String{InternalString: types.String{Value: "namevalue"}, CreatedBy: testtypes.StringTypeWithValidateWarning{}}, + expected: &testtypes.String{InternalString: types.StringValue("namevalue"), CreatedBy: testtypes.StringTypeWithValidateWarning{}}, expectedDiags: diag.Diagnostics{testtypes.TestWarningDiagnostic(path.Root("name"))}, }, } diff --git a/tfsdk/convert_test.go b/tfsdk/convert_test.go index 2d0a3f088..de7593d76 100644 --- a/tfsdk/convert_test.go +++ b/tfsdk/convert_test.go @@ -23,23 +23,23 @@ func TestConvert(t *testing.T) { tests := map[string]testCase{ "string-to-testtype-string": { - val: types.String{Value: "hello"}, + val: types.StringValue("hello"), typ: testtypes.StringType{}, expected: testtypes.String{ - InternalString: types.String{Value: "hello"}, + InternalString: types.StringValue("hello"), CreatedBy: testtypes.StringType{}, }, }, "testtype-string-to-string": { val: testtypes.String{ - InternalString: types.String{Value: "hello"}, + InternalString: types.StringValue("hello"), CreatedBy: testtypes.StringType{}, }, typ: types.StringType, - expected: types.String{Value: "hello"}, + expected: types.StringValue("hello"), }, "string-to-number": { - val: types.String{Value: "hello"}, + val: types.StringValue("hello"), typ: types.NumberType, expectedDiags: diag.Diagnostics{diag.NewErrorDiagnostic( "Error converting value", diff --git a/tfsdk/plan_test.go b/tfsdk/plan_test.go index 5c7574622..dadec120d 100644 --- a/tfsdk/plan_test.go +++ b/tfsdk/plan_test.go @@ -53,7 +53,7 @@ func TestPlanGet(t *testing.T) { expected: &struct { String types.String `tfsdk:"string"` }{ - String: types.String{Value: "test"}, + String: types.StringValue("test"), }, }, "diagnostic": { @@ -171,7 +171,7 @@ func TestPlanGetAttribute(t *testing.T) { }, }, target: new(testtypes.String), - expected: &testtypes.String{InternalString: types.String{Value: "namevalue"}, CreatedBy: testtypes.StringTypeWithValidateWarning{}}, + expected: &testtypes.String{InternalString: types.StringValue("namevalue"), CreatedBy: testtypes.StringTypeWithValidateWarning{}}, expectedDiags: diag.Diagnostics{testtypes.TestWarningDiagnostic(path.Root("name"))}, }, } diff --git a/tfsdk/schema_test.go b/tfsdk/schema_test.go index 5af63077a..d7181a536 100644 --- a/tfsdk/schema_test.go +++ b/tfsdk/schema_test.go @@ -235,11 +235,11 @@ func TestSchemaAttributeAtPath(t *testing.T) { }, }, }, - path: path.Root("test").AtSetValue(types.String{Value: "sub_test"}), + path: path.Root("test").AtSetValue(types.StringValue("sub_test")), expected: nil, expectedDiags: diag.Diagnostics{ diag.NewAttributeErrorDiagnostic( - path.Root("test").AtSetValue(types.String{Value: "sub_test"}), + path.Root("test").AtSetValue(types.StringValue("sub_test")), "Invalid Schema Path", "When attempting to get the framework attribute associated with a schema path, an unexpected error was returned. "+ "This is always an issue with the provider. Please report this to the provider developers.\n\n"+ @@ -458,11 +458,11 @@ func TestSchemaAttributeAtPath(t *testing.T) { }, }, }, - path: path.Root("test").AtSetValue(types.String{Value: "sub_test"}), + path: path.Root("test").AtSetValue(types.StringValue("sub_test")), expected: nil, expectedDiags: diag.Diagnostics{ diag.NewAttributeErrorDiagnostic( - path.Root("test").AtSetValue(types.String{Value: "sub_test"}), + path.Root("test").AtSetValue(types.StringValue("sub_test")), "Invalid Schema Path", "When attempting to get the framework attribute associated with a schema path, an unexpected error was returned. "+ "This is always an issue with the provider. Please report this to the provider developers.\n\n"+ @@ -626,11 +626,11 @@ func TestSchemaAttributeAtPath(t *testing.T) { }, }, }, - path: path.Root("test").AtSetValue(types.String{Value: "sub_test"}), + path: path.Root("test").AtSetValue(types.StringValue("sub_test")), expected: nil, expectedDiags: diag.Diagnostics{ diag.NewAttributeErrorDiagnostic( - path.Root("test").AtSetValue(types.String{Value: "sub_test"}), + path.Root("test").AtSetValue(types.StringValue("sub_test")), "Invalid Schema Path", "When attempting to get the framework attribute associated with a schema path, an unexpected error was returned. "+ "This is always an issue with the provider. Please report this to the provider developers.\n\n"+ @@ -766,11 +766,11 @@ func TestSchemaAttributeAtPath(t *testing.T) { }, }, }, - path: path.Root("test").AtSetValue(types.String{Value: "sub_test"}), + path: path.Root("test").AtSetValue(types.StringValue("sub_test")), expected: nil, expectedDiags: diag.Diagnostics{ diag.NewAttributeErrorDiagnostic( - path.Root("test").AtSetValue(types.String{Value: "sub_test"}), + path.Root("test").AtSetValue(types.StringValue("sub_test")), "Invalid Schema Path", "When attempting to get the framework attribute associated with a schema path, an unexpected error was returned. "+ "This is always an issue with the provider. Please report this to the provider developers.\n\n"+ @@ -801,7 +801,7 @@ func TestSchemaAttributeAtPath(t *testing.T) { }, }, }, - path: path.Root("test").AtSetValue(types.String{Value: "element"}).AtName("sub_test"), + path: path.Root("test").AtSetValue(types.StringValue("element")).AtName("sub_test"), expected: Attribute{ Type: types.StringType, Required: true, @@ -978,11 +978,11 @@ func TestSchemaAttributeAtPath(t *testing.T) { }, }, }, - path: path.Root("test").AtSetValue(types.String{Value: "sub_test"}), + path: path.Root("test").AtSetValue(types.StringValue("sub_test")), expected: nil, expectedDiags: diag.Diagnostics{ diag.NewAttributeErrorDiagnostic( - path.Root("test").AtSetValue(types.String{Value: "sub_test"}), + path.Root("test").AtSetValue(types.StringValue("sub_test")), "Invalid Schema Path", "When attempting to get the framework attribute associated with a schema path, an unexpected error was returned. "+ "This is always an issue with the provider. Please report this to the provider developers.\n\n"+ @@ -1024,7 +1024,7 @@ func TestSchemaAttributeAtPath(t *testing.T) { }, }, }, - path: path.Root("test").AtSetValue(types.String{Value: "element"}).AtName("sub_test"), + path: path.Root("test").AtSetValue(types.StringValue("element")).AtName("sub_test"), expected: Attribute{ Type: types.StringType, Required: true, @@ -1150,11 +1150,11 @@ func TestSchemaAttributeAtPath(t *testing.T) { }, }, }, - path: path.Root("test").AtSetValue(types.String{Value: "sub_test"}), + path: path.Root("test").AtSetValue(types.StringValue("sub_test")), expected: nil, expectedDiags: diag.Diagnostics{ diag.NewAttributeErrorDiagnostic( - path.Root("test").AtSetValue(types.String{Value: "sub_test"}), + path.Root("test").AtSetValue(types.StringValue("sub_test")), "Invalid Schema Path", "When attempting to get the framework attribute associated with a schema path, an unexpected error was returned. "+ "This is always an issue with the provider. Please report this to the provider developers.\n\n"+ @@ -1327,11 +1327,11 @@ func TestSchemaAttributeAtPath(t *testing.T) { }, }, }, - path: path.Root("test").AtSetValue(types.String{Value: "sub_test"}), + path: path.Root("test").AtSetValue(types.StringValue("sub_test")), expected: nil, expectedDiags: diag.Diagnostics{ diag.NewAttributeErrorDiagnostic( - path.Root("test").AtSetValue(types.String{Value: "sub_test"}), + path.Root("test").AtSetValue(types.StringValue("sub_test")), "Invalid Schema Path", "When attempting to get the framework attribute associated with a schema path, an unexpected error was returned. "+ "This is always an issue with the provider. Please report this to the provider developers.\n\n"+ @@ -1491,11 +1491,11 @@ func TestSchemaAttributeAtPath(t *testing.T) { }, }, }, - path: path.Root("test").AtSetValue(types.String{Value: "element"}), + path: path.Root("test").AtSetValue(types.StringValue("element")), expected: nil, expectedDiags: diag.Diagnostics{ diag.NewAttributeErrorDiagnostic( - path.Root("test").AtSetValue(types.String{Value: "element"}), + path.Root("test").AtSetValue(types.StringValue("element")), "Invalid Schema Path", "When attempting to get the framework attribute associated with a schema path, an unexpected error was returned. "+ "This is always an issue with the provider. Please report this to the provider developers.\n\n"+ @@ -1519,11 +1519,11 @@ func TestSchemaAttributeAtPath(t *testing.T) { }, }, }, - path: path.Root("test").AtSetValue(types.String{Value: "element"}), + path: path.Root("test").AtSetValue(types.StringValue("element")), expected: nil, expectedDiags: diag.Diagnostics{ diag.NewAttributeErrorDiagnostic( - path.Root("test").AtSetValue(types.String{Value: "element"}), + path.Root("test").AtSetValue(types.StringValue("element")), "Invalid Schema Path", "When attempting to get the framework attribute associated with a schema path, an unexpected error was returned. "+ "This is always an issue with the provider. Please report this to the provider developers.\n\n"+ @@ -1585,11 +1585,11 @@ func TestSchemaAttributeAtPath(t *testing.T) { }, }, }, - path: path.Empty().AtSetValue(types.String{Value: "test"}), + path: path.Empty().AtSetValue(types.StringValue("test")), expected: nil, expectedDiags: diag.Diagnostics{ diag.NewAttributeErrorDiagnostic( - path.Empty().AtSetValue(types.String{Value: "test"}), + path.Empty().AtSetValue(types.StringValue("test")), "Invalid Schema Path", "When attempting to get the framework attribute associated with a schema path, an unexpected error was returned. "+ "This is always an issue with the provider. Please report this to the provider developers.\n\n"+ @@ -3214,10 +3214,10 @@ func TestSchemaTypeAtPath(t *testing.T) { }, "ElementKeyValue": { schema: Schema{}, - path: path.Empty().AtSetValue(types.String{Null: true}), + path: path.Empty().AtSetValue(types.StringNull()), expectedDiags: diag.Diagnostics{ diag.NewAttributeErrorDiagnostic( - path.Empty().AtSetValue(types.String{Null: true}), + path.Empty().AtSetValue(types.StringNull()), "Invalid Schema Path", "When attempting to get the framework type associated with a schema path, an unexpected error was returned. This is always an issue with the provider. Please report this to the provider developers.\n\n"+ "Path: [Value()]\n"+ diff --git a/tfsdk/state_test.go b/tfsdk/state_test.go index 7817b2543..23ab826a0 100644 --- a/tfsdk/state_test.go +++ b/tfsdk/state_test.go @@ -53,7 +53,7 @@ func TestStateGet(t *testing.T) { expected: &struct { String types.String `tfsdk:"string"` }{ - String: types.String{Value: "test"}, + String: types.StringValue("test"), }, }, "diagnostic": { @@ -171,7 +171,7 @@ func TestStateGetAttribute(t *testing.T) { }, }, target: new(testtypes.String), - expected: &testtypes.String{InternalString: types.String{Value: "namevalue"}, CreatedBy: testtypes.StringTypeWithValidateWarning{}}, + expected: &testtypes.String{InternalString: types.StringValue("namevalue"), CreatedBy: testtypes.StringTypeWithValidateWarning{}}, expectedDiags: diag.Diagnostics{testtypes.TestWarningDiagnostic(path.Root("name"))}, }, } diff --git a/tfsdk/value_as_test.go b/tfsdk/value_as_test.go index 76296225b..5689fd7b2 100644 --- a/tfsdk/value_as_test.go +++ b/tfsdk/value_as_test.go @@ -87,32 +87,32 @@ func TestValueAs(t *testing.T) { tests := map[string]testCase{ "primitive bool pointer": { - val: types.Bool{Value: true}, + val: types.BoolValue(true), target: newBoolPointer(false), expected: newBoolPointer(true), }, "primitive bool pointer pointer": { - val: types.Bool{Value: true}, + val: types.BoolValue(true), target: newBoolPointerPointer(false), expected: newBoolPointerPointer(true), }, "primitive float64 pointer": { - val: types.Float64{Value: 12.3}, + val: types.Float64Value(12.3), target: newFloatPointer(0.0), expected: newFloatPointer(12.3), }, "primitive float64 pointer pointer": { - val: types.Float64{Value: 12.3}, + val: types.Float64Value(12.3), target: newFloatPointerPointer(0.0), expected: newFloatPointerPointer(12.3), }, "primitive int64 pointer": { - val: types.Int64{Value: 12}, + val: types.Int64Value(12), target: newInt64Pointer(0), expected: newInt64Pointer(12), }, "primitive int64 pointer pointer": { - val: types.Int64{Value: 12}, + val: types.Int64Value(12), target: newInt64PointerPointer(0), expected: newInt64PointerPointer(12), }, @@ -127,28 +127,28 @@ func TestValueAs(t *testing.T) { // expected: newBigFloatPointer(722770156065510359), // }, "primitive number pointer pointer": { - val: types.Number{Value: new(big.Float).SetUint64(722770156065510359)}, + val: types.NumberValue(new(big.Float).SetUint64(722770156065510359)), target: newBigFloatPointerPointer(0), expected: newBigFloatPointerPointer(722770156065510359), }, "primitive string pointer": { - val: types.String{Value: "hello"}, + val: types.StringValue("hello"), target: newStringPointer(""), expected: newStringPointer("hello"), }, "primitive string pointer pointer": { - val: types.String{Value: "hello"}, + val: types.StringValue("hello"), target: newStringPointerPointer(""), expected: newStringPointerPointer("hello"), }, "list": { - val: types.List{ - Elems: []attr.Value{ - types.String{Value: "hello"}, - types.String{Value: "world"}, + val: types.ListValueMust( + types.StringType, + []attr.Value{ + types.StringValue("hello"), + types.StringValue("world"), }, - ElemType: types.StringType, - }, + ), target: &[]string{}, expected: &[]string{ "hello", @@ -156,13 +156,13 @@ func TestValueAs(t *testing.T) { }, }, "map": { - val: types.Map{ - Elems: map[string]attr.Value{ - "hello": types.String{Value: "world"}, - "goodbye": types.String{Value: "world"}, + val: types.MapValueMust( + types.StringType, + map[string]attr.Value{ + "hello": types.StringValue("world"), + "goodbye": types.StringValue("world"), }, - ElemType: types.StringType, - }, + ), target: &map[string]string{}, expected: &map[string]string{ "hello": "world", @@ -170,18 +170,18 @@ func TestValueAs(t *testing.T) { }, }, "object": { - val: types.Object{ - Attrs: map[string]attr.Value{ - "name": types.String{Value: "Boris"}, - "age": types.Int64{Value: 25}, - "opted_in": types.Bool{Value: true}, - }, - AttrTypes: map[string]attr.Type{ + val: types.ObjectValueMust( + map[string]attr.Type{ "name": types.StringType, "age": types.Int64Type, "opted_in": types.BoolType, }, - }, + map[string]attr.Value{ + "name": types.StringValue("Boris"), + "age": types.Int64Value(25), + "opted_in": types.BoolValue(true), + }, + ), target: &struct { Name string `tfsdk:"name"` Age int64 `tfsdk:"age"` @@ -198,13 +198,13 @@ func TestValueAs(t *testing.T) { }, }, "set": { - val: types.Set{ - Elems: []attr.Value{ - types.Bool{Value: true}, - types.Bool{}, + val: types.SetValueMust( + types.BoolType, + []attr.Value{ + types.BoolValue(true), + types.BoolValue(false), }, - ElemType: types.BoolType, - }, + ), target: &[]bool{}, expected: &[]bool{ true, @@ -212,87 +212,87 @@ func TestValueAs(t *testing.T) { }, }, "struct framework types": { - val: types.Object{ - Attrs: map[string]attr.Value{ - "name": types.String{Value: "Boris"}, - "age": types.Int64{Value: 25}, - "opted_in": types.Bool{Value: true}, - "address": types.Map{ - Elems: map[string]attr.Value{ - "first_line": types.String{Value: "10 Downing Street"}, - "postcode": types.String{Value: "SW1A 2AA"}, - }, - ElemType: types.StringType, - }, - "colours": types.List{ - Elems: []attr.Value{ - types.String{Value: "red"}, - types.String{Value: "green"}, - types.String{Value: "blue"}, - }, - ElemType: types.StringType, - }, - }, - AttrTypes: map[string]attr.Type{ + val: types.ObjectValueMust( + map[string]attr.Type{ "name": types.StringType, "age": types.Int64Type, "opted_in": types.BoolType, "address": types.MapType{ElemType: types.StringType}, "colours": types.ListType{ElemType: types.StringType}, }, - }, + map[string]attr.Value{ + "name": types.StringValue("Boris"), + "age": types.Int64Value(25), + "opted_in": types.BoolValue(true), + "address": types.MapValueMust( + types.StringType, + map[string]attr.Value{ + "first_line": types.StringValue("10 Downing Street"), + "postcode": types.StringValue("SW1A 2AA"), + }, + ), + "colours": types.ListValueMust( + types.StringType, + []attr.Value{ + types.StringValue("red"), + types.StringValue("green"), + types.StringValue("blue"), + }, + ), + }, + ), target: &personFrameworkTypes{}, expected: &personFrameworkTypes{ - Name: types.String{Value: "Boris"}, - Age: types.Int64{Value: 25}, - OptedIn: types.Bool{Value: true}, - Address: types.Map{ - Elems: map[string]attr.Value{ - "first_line": types.String{Value: "10 Downing Street"}, - "postcode": types.String{Value: "SW1A 2AA"}, + Name: types.StringValue("Boris"), + Age: types.Int64Value(25), + OptedIn: types.BoolValue(true), + Address: types.MapValueMust( + types.StringType, + map[string]attr.Value{ + "first_line": types.StringValue("10 Downing Street"), + "postcode": types.StringValue("SW1A 2AA"), }, - ElemType: types.StringType, - }, - Colours: types.List{ - Elems: []attr.Value{ - types.String{Value: "red"}, - types.String{Value: "green"}, - types.String{Value: "blue"}, + ), + Colours: types.ListValueMust( + types.StringType, + []attr.Value{ + types.StringValue("red"), + types.StringValue("green"), + types.StringValue("blue"), }, - ElemType: types.StringType, - }, + ), }, }, "struct go types": { - val: types.Object{ - Attrs: map[string]attr.Value{ - "name": types.String{Value: "Boris"}, - "age": types.Int64{Value: 25}, - "opted_in": types.Bool{Value: true}, - "address": types.Map{ - Elems: map[string]attr.Value{ - "first_line": types.String{Value: "10 Downing Street"}, - "postcode": types.String{Value: "SW1A 2AA"}, - }, - ElemType: types.StringType, - }, - "colours": types.List{ - Elems: []attr.Value{ - types.String{Value: "red"}, - types.String{Value: "green"}, - types.String{Value: "blue"}, - }, - ElemType: types.StringType, - }, - }, - AttrTypes: map[string]attr.Type{ + val: types.ObjectValueMust( + map[string]attr.Type{ "name": types.StringType, "age": types.Int64Type, "opted_in": types.BoolType, "address": types.MapType{ElemType: types.StringType}, "colours": types.ListType{ElemType: types.StringType}, }, - }, + map[string]attr.Value{ + "name": types.StringValue("Boris"), + "age": types.Int64Value(25), + "opted_in": types.BoolValue(true), + "address": types.MapValueMust( + types.StringType, + map[string]attr.Value{ + "first_line": types.StringValue("10 Downing Street"), + "postcode": types.StringValue("SW1A 2AA"), + }, + ), + "colours": types.ListValueMust( + types.StringType, + []attr.Value{ + types.StringValue("red"), + types.StringValue("green"), + types.StringValue("blue"), + }, + ), + }, + ), target: &personGoTypes{}, expected: &personGoTypes{ Name: "Boris", @@ -306,7 +306,7 @@ func TestValueAs(t *testing.T) { }, }, "incompatible-type": { - val: types.String{Value: "hello"}, + val: types.StringValue("hello"), target: newInt64Pointer(0), expectedDiags: diag.Diagnostics{ diag.WithPath( @@ -320,13 +320,13 @@ func TestValueAs(t *testing.T) { }, }, "different-type": { - val: types.String{Value: "hello"}, + val: types.StringValue("hello"), target: &testtypes.String{}, expectedDiags: diag.Diagnostics{ diag.WithPath( path.Empty(), reflect.DiagNewAttributeValueIntoWrongType{ - ValType: goreflect.TypeOf(types.String{Value: "hello"}), + ValType: goreflect.TypeOf(types.StringValue("hello")), TargetType: goreflect.TypeOf(testtypes.String{}), SchemaType: types.StringType, }, @@ -371,7 +371,7 @@ func TestValueAs_generic(t *testing.T) { t.Parallel() var target attr.Value - val := types.String{Value: "hello"} + val := types.StringValue("hello") diags := ValueAs(context.Background(), val, &target) if len(diags) > 0 { t.Fatalf("Unexpected diagnostics: %s", diags) diff --git a/tfsdk/value_from_test.go b/tfsdk/value_from_test.go index 3c4c9be2f..dea960b7b 100644 --- a/tfsdk/value_from_test.go +++ b/tfsdk/value_from_test.go @@ -35,98 +35,98 @@ func TestValueFrom(t *testing.T) { } mrX := person{ - Name: types.String{Value: "x"}, - Age: types.Int64{Value: 30}, - OptedIn: types.Bool{Value: true}, - Address: types.List{ - ElemType: types.StringType, - Elems: []attr.Value{ - types.String{Value: "1"}, - types.String{Value: "Beckford Close"}, - types.String{Value: "Gotham"}, + Name: types.StringValue("x"), + Age: types.Int64Value(30), + OptedIn: types.BoolValue(true), + Address: types.ListValueMust( + types.StringType, + []attr.Value{ + types.StringValue("1"), + types.StringValue("Beckford Close"), + types.StringValue("Gotham"), }, - }, - FullName: types.Map{ - ElemType: types.StringType, - Elems: map[string]attr.Value{ - "first": types.String{Value: "x"}, - "middle": types.String{Value: "b"}, - "last": types.String{Value: "c"}, + ), + FullName: types.MapValueMust( + types.StringType, + map[string]attr.Value{ + "first": types.StringValue("x"), + "middle": types.StringValue("b"), + "last": types.StringValue("c"), }, - }, + ), } mrsY := person{ - Name: types.String{Value: "y"}, - Age: types.Int64{Value: 23}, - OptedIn: types.Bool{Value: false}, - Address: types.List{ - ElemType: types.StringType, - Elems: []attr.Value{ - types.String{Value: "2"}, - types.String{Value: "Windmill Close"}, - types.String{Value: "Smallville"}, + Name: types.StringValue("y"), + Age: types.Int64Value(23), + OptedIn: types.BoolValue(false), + Address: types.ListValueMust( + types.StringType, + []attr.Value{ + types.StringValue("2"), + types.StringValue("Windmill Close"), + types.StringValue("Smallville"), }, - }, - FullName: types.Map{ - ElemType: types.StringType, - Elems: map[string]attr.Value{ - "first": types.String{Value: "y"}, - "middle": types.String{Value: "e"}, - "last": types.String{Value: "f"}, + ), + FullName: types.MapValueMust( + types.StringType, + map[string]attr.Value{ + "first": types.StringValue("y"), + "middle": types.StringValue("e"), + "last": types.StringValue("f"), }, - }, + ), } - expectedMrXObj := types.Object{ - AttrTypes: personAttrTypes, - Attrs: map[string]attr.Value{ - "name": types.String{Value: "x", Unknown: false, Null: false}, - "age": types.Int64{Value: 30, Unknown: false, Null: false}, - "opted_in": types.Bool{Value: true, Unknown: false, Null: false}, - "address": types.List{ - ElemType: types.StringType, - Elems: []attr.Value{ - types.String{Value: "1"}, - types.String{Value: "Beckford Close"}, - types.String{Value: "Gotham"}, + expectedMrXObj := types.ObjectValueMust( + personAttrTypes, + map[string]attr.Value{ + "name": types.StringValue("x"), + "age": types.Int64Value(30), + "opted_in": types.BoolValue(true), + "address": types.ListValueMust( + types.StringType, + []attr.Value{ + types.StringValue("1"), + types.StringValue("Beckford Close"), + types.StringValue("Gotham"), }, - }, - "full_name": types.Map{ - ElemType: types.StringType, - Elems: map[string]attr.Value{ - "first": types.String{Value: "x"}, - "middle": types.String{Value: "b"}, - "last": types.String{Value: "c"}, + ), + "full_name": types.MapValueMust( + types.StringType, + map[string]attr.Value{ + "first": types.StringValue("x"), + "middle": types.StringValue("b"), + "last": types.StringValue("c"), }, - }, + ), }, - } - - expectedMrsYObj := types.Object{ - AttrTypes: personAttrTypes, - Attrs: map[string]attr.Value{ - "name": types.String{Value: "y", Unknown: false, Null: false}, - "age": types.Int64{Value: 23, Unknown: false, Null: false}, - "opted_in": types.Bool{Value: false, Unknown: false, Null: false}, - "address": types.List{ - ElemType: types.StringType, - Elems: []attr.Value{ - types.String{Value: "2"}, - types.String{Value: "Windmill Close"}, - types.String{Value: "Smallville"}, + ) + + expectedMrsYObj := types.ObjectValueMust( + personAttrTypes, + map[string]attr.Value{ + "name": types.StringValue("y"), + "age": types.Int64Value(23), + "opted_in": types.BoolValue(false), + "address": types.ListValueMust( + types.StringType, + []attr.Value{ + types.StringValue("2"), + types.StringValue("Windmill Close"), + types.StringValue("Smallville"), }, - }, - "full_name": types.Map{ - ElemType: types.StringType, - Elems: map[string]attr.Value{ - "first": types.String{Value: "y"}, - "middle": types.String{Value: "e"}, - "last": types.String{Value: "f"}, + ), + "full_name": types.MapValueMust( + types.StringType, + map[string]attr.Value{ + "first": types.StringValue("y"), + "middle": types.StringValue("e"), + "last": types.StringValue("f"), }, - }, + ), }, - } + ) type testCase struct { val interface{} @@ -139,48 +139,46 @@ func TestValueFrom(t *testing.T) { "primitive": { val: "hello", target: types.String{}, - expected: types.String{Value: "hello", Unknown: false, Null: false}, + expected: types.StringValue("hello"), }, "struct": { - val: mrX, - target: types.Object{ - AttrTypes: personAttrTypes, - }, + val: mrX, + target: types.ObjectNull(personAttrTypes), expected: expectedMrXObj, }, "list": { val: []person{mrX, mrsY}, - target: types.List{ - ElemType: types.ObjectType{ + target: types.ListNull( + types.ObjectType{ AttrTypes: personAttrTypes, }, - }, - expected: types.List{ - ElemType: types.ObjectType{ + ), + expected: types.ListValueMust( + types.ObjectType{ AttrTypes: personAttrTypes, }, - Elems: []attr.Value{expectedMrXObj, expectedMrsYObj}, - }, + []attr.Value{expectedMrXObj, expectedMrsYObj}, + ), }, "map": { val: map[string]person{ "x": mrX, "y": mrsY, }, - target: types.Map{ - ElemType: types.ObjectType{ + target: types.MapNull( + types.ObjectType{ AttrTypes: personAttrTypes, }, - }, - expected: types.Map{ - ElemType: types.ObjectType{ + ), + expected: types.MapValueMust( + types.ObjectType{ AttrTypes: personAttrTypes, }, - Elems: map[string]attr.Value{ + map[string]attr.Value{ "x": expectedMrXObj, "y": expectedMrsYObj, }, - }, + ), }, "incompatible-type": { val: 0, diff --git a/types/bool.go b/types/bool.go index 924e98400..e97beafa9 100644 --- a/types/bool.go +++ b/types/bool.go @@ -19,7 +19,7 @@ var ( // creating a Bool with this function has no effect. func BoolNull() Bool { return Bool{ - state: valueStateNull, + state: attr.ValueStateNull, } } @@ -30,7 +30,7 @@ func BoolNull() Bool { // creating a Bool with this function has no effect. func BoolUnknown() Bool { return Bool{ - state: valueStateUnknown, + state: attr.ValueStateUnknown, } } @@ -41,74 +41,31 @@ func BoolUnknown() Bool { // creating a Bool with this function has no effect. func BoolValue(value bool) Bool { return Bool{ - state: valueStateKnown, + state: attr.ValueStateKnown, value: value, } } func boolValueFromTerraform(ctx context.Context, in tftypes.Value) (attr.Value, error) { if in.IsNull() { - return Bool{ - Null: true, - state: valueStateDeprecated, - }, nil + return BoolNull(), nil } if !in.IsKnown() { - return Bool{ - Unknown: true, - state: valueStateDeprecated, - }, nil + return BoolUnknown(), nil } var b bool err := in.As(&b) if err != nil { return nil, err } - return Bool{ - Value: b, - state: valueStateDeprecated, - }, nil + return BoolValue(b), nil } // Bool represents a boolean value. type Bool struct { - // Unknown will be true if the value is not yet known. - // - // If the Bool was created with the BoolValue, BoolNull, or BoolUnknown - // functions, changing this field has no effect. - // - // Deprecated: Use the BoolUnknown function to create an unknown Bool - // value or use the IsUnknown method to determine whether the Bool value - // is unknown instead. - Unknown bool - - // Null will be true if the value was not set, or was explicitly set to - // null. - // - // If the Bool was created with the BoolValue, BoolNull, or BoolUnknown - // functions, changing this field has no effect. - // - // Deprecated: Use the BoolNull function to create a null Bool value or - // use the IsNull method to determine whether the Bool value is null - // instead. - Null bool - - // Value contains the set value, as long as Unknown and Null are both - // false. - // - // If the Bool was created with the BoolValue, BoolNull, or BoolUnknown - // functions, changing this field has no effect. - // - // Deprecated: Use the BoolValue function to create a known Bool value or - // use the ValueBool method to retrieve the Bool value instead. - Value bool - - // state represents whether the Bool is null, unknown, or known. During the - // exported field deprecation period, this state can also be "deprecated", - // which remains the zero-value for compatibility to ensure exported field - // updates take effect. The zero-value will be changed to null in a future - // version. - state valueState + // state represents whether the value is null, unknown, or known. The + // zero-value is null. + state attr.ValueState // value contains the known value, if not null or unknown. value bool @@ -122,26 +79,15 @@ func (b Bool) Type(_ context.Context) attr.Type { // ToTerraformValue returns the data contained in the Bool as a tftypes.Value. func (b Bool) ToTerraformValue(_ context.Context) (tftypes.Value, error) { switch b.state { - case valueStateDeprecated: - if b.Null { - return tftypes.NewValue(tftypes.Bool, nil), nil - } - if b.Unknown { - return tftypes.NewValue(tftypes.Bool, tftypes.UnknownValue), nil - } - if err := tftypes.ValidateValue(tftypes.Bool, b.Value); err != nil { - return tftypes.NewValue(tftypes.Bool, tftypes.UnknownValue), err - } - return tftypes.NewValue(tftypes.Bool, b.Value), nil - case valueStateKnown: + case attr.ValueStateKnown: if err := tftypes.ValidateValue(tftypes.Bool, b.value); err != nil { return tftypes.NewValue(tftypes.Bool, tftypes.UnknownValue), err } return tftypes.NewValue(tftypes.Bool, b.value), nil - case valueStateNull: + case attr.ValueStateNull: return tftypes.NewValue(tftypes.Bool, nil), nil - case valueStateUnknown: + case attr.ValueStateUnknown: return tftypes.NewValue(tftypes.Bool, tftypes.UnknownValue), nil default: panic(fmt.Sprintf("unhandled Bool state in ToTerraformValue: %s", b.state)) @@ -151,40 +97,30 @@ func (b Bool) ToTerraformValue(_ context.Context) (tftypes.Value, error) { // Equal returns true if `other` is a *Bool and has the same value as `b`. func (b Bool) Equal(other attr.Value) bool { o, ok := other.(Bool) + if !ok { return false } + if b.state != o.state { return false } - if b.state == valueStateKnown { - return b.value == o.value - } - if b.Unknown != o.Unknown { - return false - } - if b.Null != o.Null { - return false + + if b.state != attr.ValueStateKnown { + return true } - return b.Value == o.Value + + return b.value == o.value } // IsNull returns true if the Bool represents a null value. func (b Bool) IsNull() bool { - if b.state == valueStateNull { - return true - } - - return b.state == valueStateDeprecated && b.Null + return b.state == attr.ValueStateNull } // IsUnknown returns true if the Bool represents a currently unknown value. func (b Bool) IsUnknown() bool { - if b.state == valueStateUnknown { - return true - } - - return b.state == valueStateDeprecated && b.Unknown + return b.state == attr.ValueStateUnknown } // String returns a human-readable representation of the Bool value. @@ -199,19 +135,11 @@ func (b Bool) String() string { return attr.NullValueString } - if b.state == valueStateKnown { - return fmt.Sprintf("%t", b.value) - } - - return fmt.Sprintf("%t", b.Value) + return fmt.Sprintf("%t", b.value) } // ValueBool returns the known bool value. If Bool is null or unknown, returns // false. func (b Bool) ValueBool() bool { - if b.state == valueStateDeprecated { - return b.Value - } - return b.value } diff --git a/types/bool_test.go b/types/bool_test.go index dd3132753..66c208aa0 100644 --- a/types/bool_test.go +++ b/types/bool_test.go @@ -9,84 +9,6 @@ import ( "github.com/hashicorp/terraform-plugin-go/tftypes" ) -// This test verifies the assumptions that creating the Value via function then -// setting the fields directly has no effects. -func TestBoolValueDeprecatedFieldSetting(t *testing.T) { - t.Parallel() - - knownBool := BoolValue(false) - - knownBool.Null = true - - if knownBool.IsNull() { - t.Error("unexpected null update after Null field setting") - } - - knownBool.Unknown = true - - if knownBool.IsUnknown() { - t.Error("unexpected unknown update after Unknown field setting") - } - - knownBool.Value = true - - if knownBool.ValueBool() { - t.Error("unexpected value update after Value field setting") - } -} - -// This test verifies the assumptions that creating the Value via function then -// setting the fields directly has no effects. -func TestBoolNullDeprecatedFieldSetting(t *testing.T) { - t.Parallel() - - nullBool := BoolNull() - - nullBool.Null = false - - if !nullBool.IsNull() { - t.Error("unexpected null update after Null field setting") - } - - nullBool.Unknown = true - - if nullBool.IsUnknown() { - t.Error("unexpected unknown update after Unknown field setting") - } - - nullBool.Value = true - - if nullBool.ValueBool() { - t.Error("unexpected value update after Value field setting") - } -} - -// This test verifies the assumptions that creating the Value via function then -// setting the fields directly has no effects. -func TestBoolUnknownDeprecatedFieldSetting(t *testing.T) { - t.Parallel() - - unknownBool := BoolUnknown() - - unknownBool.Null = true - - if unknownBool.IsNull() { - t.Error("unexpected null update after Null field setting") - } - - unknownBool.Unknown = false - - if !unknownBool.IsUnknown() { - t.Error("unexpected unknown update after Unknown field setting") - } - - unknownBool.Value = true - - if unknownBool.ValueBool() { - t.Error("unexpected value update after Value field setting") - } -} - func TestBoolValueFromTerraform(t *testing.T) { t.Parallel() @@ -102,19 +24,19 @@ func testBoolValueFromTerraform(t *testing.T, direct bool) { tests := map[string]testCase{ "true": { input: tftypes.NewValue(tftypes.Bool, true), - expectation: Bool{Value: true}, + expectation: BoolValue(true), }, "false": { input: tftypes.NewValue(tftypes.Bool, false), - expectation: Bool{Value: false}, + expectation: BoolValue(false), }, "unknown": { input: tftypes.NewValue(tftypes.Bool, tftypes.UnknownValue), - expectation: Bool{Unknown: true}, + expectation: BoolUnknown(), }, "null": { input: tftypes.NewValue(tftypes.Bool, nil), - expectation: Bool{Null: true}, + expectation: BoolNull(), }, "wrongType": { input: tftypes.NewValue(tftypes.String, "oops"), @@ -186,22 +108,6 @@ func TestBoolToTerraformValue(t *testing.T) { input: BoolNull(), expectation: tftypes.NewValue(tftypes.Bool, nil), }, - "deprecated-true": { - input: Bool{Value: true}, - expectation: tftypes.NewValue(tftypes.Bool, true), - }, - "deprecated-false": { - input: Bool{Value: false}, - expectation: tftypes.NewValue(tftypes.Bool, false), - }, - "deprecated-unknown": { - input: Bool{Unknown: true}, - expectation: tftypes.NewValue(tftypes.Bool, tftypes.UnknownValue), - }, - "deprecated-null": { - input: Bool{Null: true}, - expectation: tftypes.NewValue(tftypes.Bool, nil), - }, } for name, test := range tests { name, test := name, test @@ -237,7 +143,7 @@ func TestBoolEqual(t *testing.T) { }, "known-true-wrongtype": { input: BoolValue(true), - candidate: String{Value: "true"}, + candidate: StringValue("true"), expectation: false, }, "known-true-known-false": { @@ -250,36 +156,16 @@ func TestBoolEqual(t *testing.T) { candidate: BoolValue(true), expectation: true, }, - "known-true-deprecated-false": { - input: BoolValue(true), - candidate: Bool{Value: false}, - expectation: false, - }, - "known-true-deprecated-true": { - input: BoolValue(true), - candidate: Bool{Value: true}, - expectation: false, // intentional - }, "known-true-null": { input: BoolValue(true), candidate: BoolNull(), expectation: false, }, - "known-true-deprecated-null": { - input: BoolValue(true), - candidate: Bool{Null: true}, - expectation: false, - }, "known-true-unknown": { input: BoolValue(true), candidate: BoolUnknown(), expectation: false, }, - "known-true-deprecated-unknown": { - input: BoolValue(true), - candidate: Bool{Unknown: true}, - expectation: false, - }, "known-false-nil": { input: BoolValue(false), candidate: nil, @@ -287,7 +173,7 @@ func TestBoolEqual(t *testing.T) { }, "known-false-wrongtype": { input: BoolValue(false), - candidate: String{Value: "false"}, + candidate: StringValue("false"), expectation: false, }, "known-false-known-false": { @@ -300,36 +186,16 @@ func TestBoolEqual(t *testing.T) { candidate: BoolValue(true), expectation: false, }, - "known-false-deprecated-false": { - input: BoolValue(false), - candidate: Bool{Value: false}, - expectation: false, // intentional - }, - "known-false-deprecated-true": { - input: BoolValue(false), - candidate: Bool{Value: true}, - expectation: false, - }, "known-false-null": { input: BoolValue(false), candidate: BoolNull(), expectation: false, }, - "known-false-deprecated-null": { - input: BoolValue(false), - candidate: Bool{Null: true}, - expectation: false, - }, "known-false-unknown": { input: BoolValue(false), candidate: BoolUnknown(), expectation: false, }, - "known-false-deprecated-unknown": { - input: BoolValue(false), - candidate: Bool{Unknown: true}, - expectation: false, - }, "null-nil": { input: BoolNull(), candidate: nil, @@ -337,7 +203,7 @@ func TestBoolEqual(t *testing.T) { }, "null-wrongtype": { input: BoolNull(), - candidate: String{Value: "true"}, + candidate: StringValue("true"), expectation: false, }, "null-known-false": { @@ -350,226 +216,16 @@ func TestBoolEqual(t *testing.T) { candidate: BoolValue(true), expectation: false, }, - "null-deprecated-true": { - input: BoolNull(), - candidate: Bool{Value: true}, - expectation: false, - }, - "null-deprecated-false": { - input: BoolNull(), - candidate: Bool{Value: false}, - expectation: false, - }, "null-null": { input: BoolNull(), candidate: BoolNull(), expectation: true, }, - "null-deprecated-null": { - input: BoolNull(), - candidate: Bool{Null: true}, - expectation: false, // intentional - }, "null-unknown": { input: BoolNull(), candidate: BoolUnknown(), expectation: false, }, - "null-deprecated-unknown": { - input: BoolNull(), - candidate: Bool{Unknown: true}, - expectation: false, - }, - "deprecated-true-known-false": { - input: Bool{Value: true}, - candidate: BoolValue(false), - expectation: false, - }, - "deprecated-true-known-true": { - input: Bool{Value: true}, - candidate: BoolValue(true), - expectation: false, // intentional - }, - "deprecated-true-deprecated-true": { - input: Bool{Value: true}, - candidate: Bool{Value: true}, - expectation: true, - }, - "deprecated-true-deprecated-false": { - input: Bool{Value: true}, - candidate: Bool{Value: false}, - expectation: false, - }, - "deprecated-true-unknown": { - input: Bool{Value: true}, - candidate: BoolUnknown(), - expectation: false, - }, - "deprecated-true-deprecated-unknown": { - input: Bool{Value: true}, - candidate: Bool{Unknown: true}, - expectation: false, - }, - "deprecated-true-null": { - input: Bool{Value: true}, - candidate: BoolNull(), - expectation: false, - }, - "deprecated-true-deprecated-null": { - input: Bool{Value: true}, - candidate: Bool{Null: true}, - expectation: false, - }, - "deprecated-true-wrongType": { - input: Bool{Value: true}, - candidate: &String{Value: "oops"}, - expectation: false, - }, - "deprecated-true-nil": { - input: Bool{Value: true}, - candidate: nil, - expectation: false, - }, - "deprecated-false-known-false": { - input: Bool{Value: false}, - candidate: BoolValue(false), - expectation: false, // intentional - }, - "deprecated-false-known-true": { - input: Bool{Value: false}, - candidate: BoolValue(true), - expectation: false, - }, - "deprecated-false-deprecated-true": { - input: Bool{Value: false}, - candidate: Bool{Value: true}, - expectation: false, - }, - "deprecated-false-deprecated-false": { - input: Bool{Value: false}, - candidate: Bool{Value: false}, - expectation: true, - }, - "deprecated-false-unknown": { - input: Bool{Value: false}, - candidate: BoolUnknown(), - expectation: false, - }, - "deprecated-false-deprecated-unknown": { - input: Bool{Value: false}, - candidate: Bool{Unknown: true}, - expectation: false, - }, - "deprecated-false-null": { - input: Bool{Value: false}, - candidate: BoolNull(), - expectation: false, - }, - "deprecated-false-deprecated-null": { - input: Bool{Value: false}, - candidate: Bool{Null: true}, - expectation: false, - }, - "deprecated-false-wrongType": { - input: Bool{Value: false}, - candidate: &String{Value: "oops"}, - expectation: false, - }, - "deprecated-false-nil": { - input: Bool{Value: false}, - candidate: nil, - expectation: false, - }, - "deprecated-unknown-known-false": { - input: Bool{Unknown: true}, - candidate: BoolValue(false), - expectation: false, - }, - "deprecated-unknown-known-true": { - input: Bool{Unknown: true}, - candidate: BoolValue(true), - expectation: false, - }, - "deprecated-unknown-deprecated-true": { - input: Bool{Unknown: true}, - candidate: Bool{Value: true}, - expectation: false, - }, - "deprecated-unknown-deprecated-false": { - input: Bool{Unknown: true}, - candidate: Bool{Value: false}, - expectation: false, - }, - "deprecated-unknown-deprecated-unknown": { - input: Bool{Unknown: true}, - candidate: Bool{Unknown: true}, - expectation: true, - }, - "deprecated-unknown-deprecated-null": { - input: Bool{Unknown: true}, - candidate: Bool{Null: true}, - expectation: false, - }, - "deprecated-unknown-wrongType": { - input: Bool{Unknown: true}, - candidate: &String{Value: "oops"}, - expectation: false, - }, - "deprecated-unknown-nil": { - input: Bool{Unknown: true}, - candidate: nil, - expectation: false, - }, - "deprecated-null-deprecated-true": { - input: Bool{Null: true}, - candidate: Bool{Value: true}, - expectation: false, - }, - "deprecated-null-deprecated-false": { - input: Bool{Null: true}, - candidate: Bool{Value: false}, - expectation: false, - }, - "deprecated-null-known-false": { - input: Bool{Null: true}, - candidate: BoolValue(false), - expectation: false, - }, - "deprecated-null-known-true": { - input: Bool{Null: true}, - candidate: BoolValue(true), - expectation: false, - }, - "deprecated-null-unknown": { - input: Bool{Null: true}, - candidate: BoolUnknown(), - expectation: false, - }, - "deprecated-null-deprecated-unknown": { - input: Bool{Null: true}, - candidate: Bool{Unknown: true}, - expectation: false, - }, - "deprecated-null-null": { - input: Bool{Null: true}, - candidate: BoolNull(), - expectation: false, // intentional - }, - "deprecated-null-deprecated-null": { - input: Bool{Null: true}, - candidate: Bool{Null: true}, - expectation: true, - }, - "deprecated-null-wrongType": { - input: Bool{Null: true}, - candidate: &String{Value: "oops"}, - expectation: false, - }, - "deprecated-null-nil": { - input: Bool{Null: true}, - candidate: nil, - expectation: false, - }, } for name, test := range tests { name, test := name, test @@ -595,30 +251,14 @@ func TestBoolIsNull(t *testing.T) { input: BoolValue(true), expected: false, }, - "deprecated-known": { - input: Bool{Value: true}, - expected: false, - }, "null": { input: BoolNull(), expected: true, }, - "deprecated-null": { - input: Bool{Null: true}, - expected: true, - }, "unknown": { input: BoolUnknown(), expected: false, }, - "deprecated-unknown": { - input: Bool{Unknown: true}, - expected: false, - }, - "deprecated-invalid": { - input: Bool{Null: true, Unknown: true}, - expected: true, - }, } for name, testCase := range testCases { @@ -647,30 +287,14 @@ func TestBoolIsUnknown(t *testing.T) { input: BoolValue(true), expected: false, }, - "deprecated-known": { - input: Bool{Value: true}, - expected: false, - }, "null": { input: BoolNull(), expected: false, }, - "deprecated-null": { - input: Bool{Null: true}, - expected: false, - }, "unknown": { input: BoolUnknown(), expected: true, }, - "deprecated-unknown": { - input: Bool{Unknown: true}, - expected: true, - }, - "deprecated-invalid": { - input: Bool{Null: true, Unknown: true}, - expected: true, - }, } for name, testCase := range testCases { @@ -712,26 +336,6 @@ func TestBoolString(t *testing.T) { input: BoolUnknown(), expectation: "", }, - "deprecated-true": { - input: Bool{Value: true}, - expectation: "true", - }, - "deprecated-false": { - input: Bool{Value: false}, - expectation: "false", - }, - "deprecated-unknown": { - input: Bool{Unknown: true}, - expectation: "", - }, - "deprecated-null": { - input: Bool{Null: true}, - expectation: "", - }, - "default-false": { - input: Bool{}, - expectation: "false", - }, } for name, test := range tests { @@ -762,34 +366,14 @@ func TestBoolValueBool(t *testing.T) { input: BoolValue(true), expected: true, }, - "deprecated-known-false": { - input: Bool{Value: false}, - expected: false, - }, - "deprecated-known-true": { - input: Bool{Value: true}, - expected: true, - }, "null": { input: BoolNull(), expected: false, }, - "deprecated-null": { - input: Bool{Null: true}, - expected: false, - }, "unknown": { input: BoolUnknown(), expected: false, }, - "deprecated-unknown": { - input: Bool{Unknown: true}, - expected: false, - }, - "deprecated-invalid": { - input: Bool{Null: true, Unknown: true}, - expected: false, - }, } for name, testCase := range testCases { diff --git a/types/float64.go b/types/float64.go index 04c1031f6..38382e2ac 100644 --- a/types/float64.go +++ b/types/float64.go @@ -22,7 +22,7 @@ var ( // creating a Float64 with this function has no effect. func Float64Null() Float64 { return Float64{ - state: valueStateNull, + state: attr.ValueStateNull, } } @@ -33,7 +33,7 @@ func Float64Null() Float64 { // creating a Float64 with this function has no effect. func Float64Unknown() Float64 { return Float64{ - state: valueStateUnknown, + state: attr.ValueStateUnknown, } } @@ -44,7 +44,7 @@ func Float64Unknown() Float64 { // creating a Float64 with this function has no effect. func Float64Value(value float64) Float64 { return Float64{ - state: valueStateKnown, + state: attr.ValueStateKnown, value: value, } } @@ -99,17 +99,11 @@ func float64Validate(_ context.Context, in tftypes.Value, path path.Path) diag.D func float64ValueFromTerraform(ctx context.Context, in tftypes.Value) (attr.Value, error) { if !in.IsKnown() { - return Float64{ - Unknown: true, - state: valueStateDeprecated, - }, nil + return Float64Unknown(), nil } if in.IsNull() { - return Float64{ - Null: true, - state: valueStateDeprecated, - }, nil + return Float64Null(), nil } var bigF *big.Float @@ -125,51 +119,14 @@ func float64ValueFromTerraform(ctx context.Context, in tftypes.Value) (attr.Valu return nil, fmt.Errorf("Value %s cannot be represented as a 64-bit floating point.", bigF) } - return Float64{ - Value: f, - state: valueStateDeprecated, - }, nil + return Float64Value(f), nil } // Float64 represents a 64-bit floating point value, exposed as a float64. type Float64 struct { - // Unknown will be true if the value is not yet known. - // - // If the Float64 was created with the Float64Value, Float64Null, or Float64Unknown - // functions, changing this field has no effect. - // - // Deprecated: Use the Float64Unknown function to create an unknown Float64 - // value or use the IsUnknown method to determine whether the Float64 value - // is unknown instead. - Unknown bool - - // Null will be true if the value was not set, or was explicitly set to - // null. - // - // If the Float64 was created with the Float64Value, Float64Null, or Float64Unknown - // functions, changing this field has no effect. - // - // Deprecated: Use the Float64Null function to create a null Float64 value or - // use the IsNull method to determine whether the Float64 value is null - // instead. - Null bool - - // Value contains the set value, as long as Unknown and Null are both - // false. - // - // If the Float64 was created with the Float64Value, Float64Null, or Float64Unknown - // functions, changing this field has no effect. - // - // Deprecated: Use the Float64Value function to create a known Float64 value or - // use the ValueFloat64 method to retrieve the Float64 value instead. - Value float64 - - // state represents whether the Float64 is null, unknown, or known. During the - // exported field deprecation period, this state can also be "deprecated", - // which remains the zero-value for compatibility to ensure exported field - // updates take effect. The zero-value will be changed to null in a future - // version. - state valueState + // state represents whether the value is null, unknown, or known. The + // zero-value is null. + state attr.ValueState // value contains the known value, if not null or unknown. value float64 @@ -187,44 +144,25 @@ func (f Float64) Equal(other attr.Value) bool { return false } - if f.state == valueStateKnown { - return f.value == o.value - } - - if f.Unknown != o.Unknown { - return false - } - - if f.Null != o.Null { - return false + if f.state != attr.ValueStateKnown { + return true } - return f.Value == o.Value + return f.value == o.value } // ToTerraformValue returns the data contained in the Float64 as a tftypes.Value. func (f Float64) ToTerraformValue(ctx context.Context) (tftypes.Value, error) { switch f.state { - case valueStateDeprecated: - if f.Null { - return tftypes.NewValue(tftypes.Number, nil), nil - } - if f.Unknown { - return tftypes.NewValue(tftypes.Number, tftypes.UnknownValue), nil - } - if err := tftypes.ValidateValue(tftypes.Number, f.Value); err != nil { - return tftypes.NewValue(tftypes.Number, tftypes.UnknownValue), err - } - return tftypes.NewValue(tftypes.Number, f.Value), nil - case valueStateKnown: + case attr.ValueStateKnown: if err := tftypes.ValidateValue(tftypes.Number, f.value); err != nil { return tftypes.NewValue(tftypes.Number, tftypes.UnknownValue), err } return tftypes.NewValue(tftypes.Number, f.value), nil - case valueStateNull: + case attr.ValueStateNull: return tftypes.NewValue(tftypes.Number, nil), nil - case valueStateUnknown: + case attr.ValueStateUnknown: return tftypes.NewValue(tftypes.Number, tftypes.UnknownValue), nil default: panic(fmt.Sprintf("unhandled Float64 state in ToTerraformValue: %s", f.state)) @@ -238,20 +176,12 @@ func (f Float64) Type(ctx context.Context) attr.Type { // IsNull returns true if the Float64 represents a null value. func (f Float64) IsNull() bool { - if f.state == valueStateNull { - return true - } - - return f.state == valueStateDeprecated && f.Null + return f.state == attr.ValueStateNull } // IsUnknown returns true if the Float64 represents a currently unknown value. func (f Float64) IsUnknown() bool { - if f.state == valueStateUnknown { - return true - } - - return f.state == valueStateDeprecated && f.Unknown + return f.state == attr.ValueStateUnknown } // String returns a human-readable representation of the Float64 value. @@ -266,19 +196,11 @@ func (f Float64) String() string { return attr.NullValueString } - if f.state == valueStateKnown { - return fmt.Sprintf("%f", f.value) - } - - return fmt.Sprintf("%f", f.Value) + return fmt.Sprintf("%f", f.value) } // ValueFloat64 returns the known float64 value. If Float64 is null or unknown, returns // 0.0. func (f Float64) ValueFloat64() float64 { - if f.state == valueStateDeprecated { - return f.Value - } - return f.value } diff --git a/types/float64_test.go b/types/float64_test.go index 6a46edd39..79c6e0ca9 100644 --- a/types/float64_test.go +++ b/types/float64_test.go @@ -11,84 +11,6 @@ import ( "github.com/hashicorp/terraform-plugin-go/tftypes" ) -// This test verifies the assumptions that creating the Value via function then -// setting the fields directly has no effects. -func TestFloat64ValueDeprecatedFieldSetting(t *testing.T) { - t.Parallel() - - knownFloat64 := Float64Value(2.4) - - knownFloat64.Null = true - - if knownFloat64.IsNull() { - t.Error("unexpected null update after Null field setting") - } - - knownFloat64.Unknown = true - - if knownFloat64.IsUnknown() { - t.Error("unexpected unknown update after Unknown field setting") - } - - knownFloat64.Value = 4.8 - - if knownFloat64.ValueFloat64() == 4.8 { - t.Error("unexpected value update after Value field setting") - } -} - -// This test verifies the assumptions that creating the Value via function then -// setting the fields directly has no effects. -func TestFloat64NullDeprecatedFieldSetting(t *testing.T) { - t.Parallel() - - nullFloat64 := Float64Null() - - nullFloat64.Null = false - - if !nullFloat64.IsNull() { - t.Error("unexpected null update after Null field setting") - } - - nullFloat64.Unknown = true - - if nullFloat64.IsUnknown() { - t.Error("unexpected unknown update after Unknown field setting") - } - - nullFloat64.Value = 4.8 - - if nullFloat64.ValueFloat64() == 4.8 { - t.Error("unexpected value update after Value field setting") - } -} - -// This test verifies the assumptions that creating the Value via function then -// setting the fields directly has no effects. -func TestFloat64UnknownDeprecatedFieldSetting(t *testing.T) { - t.Parallel() - - unknownFloat64 := Float64Unknown() - - unknownFloat64.Null = true - - if unknownFloat64.IsNull() { - t.Error("unexpected null update after Null field setting") - } - - unknownFloat64.Unknown = false - - if !unknownFloat64.IsUnknown() { - t.Error("unexpected unknown update after Unknown field setting") - } - - unknownFloat64.Value = 4.8 - - if unknownFloat64.ValueFloat64() == 4.8 { - t.Error("unexpected value update after Value field setting") - } -} - func TestFloat64ValueFromTerraform(t *testing.T) { t.Parallel() @@ -104,19 +26,19 @@ func testFloat64ValueFromTerraform(t *testing.T, direct bool) { tests := map[string]testCase{ "value-int": { input: tftypes.NewValue(tftypes.Number, 123), - expectation: Float64{Value: 123.0}, + expectation: Float64Value(123.0), }, "value-float": { input: tftypes.NewValue(tftypes.Number, 123.456), - expectation: Float64{Value: 123.456}, + expectation: Float64Value(123.456), }, "unknown": { input: tftypes.NewValue(tftypes.Number, tftypes.UnknownValue), - expectation: Float64{Unknown: true}, + expectation: Float64Unknown(), }, "null": { input: tftypes.NewValue(tftypes.Number, nil), - expectation: Float64{Null: true}, + expectation: Float64Null(), }, "wrongType": { input: tftypes.NewValue(tftypes.String, "oops"), @@ -189,19 +111,19 @@ func TestFloat64ToTerraformValue(t *testing.T) { expectation: tftypes.NewValue(tftypes.Number, nil), }, "deprecated-value-int": { - input: Float64{Value: 123}, + input: Float64Value(123), expectation: tftypes.NewValue(tftypes.Number, big.NewFloat(123.0)), }, "deprecated-value-float": { - input: Float64{Value: 123.456}, + input: Float64Value(123.456), expectation: tftypes.NewValue(tftypes.Number, big.NewFloat(123.456)), }, "deprecated-unknown": { - input: Float64{Unknown: true}, + input: Float64Unknown(), expectation: tftypes.NewValue(tftypes.Number, tftypes.UnknownValue), }, "deprecated-null": { - input: Float64{Null: true}, + input: Float64Null(), expectation: tftypes.NewValue(tftypes.Number, nil), }, } @@ -282,136 +204,6 @@ func TestFloat64Equal(t *testing.T) { candidate: Float64Null(), expectation: true, }, - "deprecated-known-known-same": { - input: Float64{Value: 123}, - candidate: Float64Value(123), - expectation: false, // intentional - }, - "deprecated-known-known-diff": { - input: Float64{Value: 123}, - candidate: Float64Value(456), - expectation: false, - }, - "deprecated-known-unknown": { - input: Float64{Value: 123}, - candidate: Float64Unknown(), - expectation: false, - }, - "deprecated-known-null": { - input: Float64{Value: 123}, - candidate: Float64Null(), - expectation: false, - }, - "deprecated-known-deprecated-known-same": { - input: Float64{Value: 123}, - candidate: Float64{Value: 123}, - expectation: true, - }, - "deprecated-known-deprecated-known-diff": { - input: Float64{Value: 123}, - candidate: Float64{Value: 456}, - expectation: false, - }, - "deprecated-known-deprecated-unknown": { - input: Float64{Value: 123}, - candidate: Float64{Unknown: true}, - expectation: false, - }, - "deprecated-known-deprecated-null": { - input: Float64{Value: 123}, - candidate: Float64{Null: true}, - expectation: false, - }, - "deprecated-known-wrongType": { - input: Float64{Value: 123}, - candidate: &String{Value: "oops"}, - expectation: false, - }, - "deprecated-known-nil": { - input: Float64{Value: 123}, - candidate: nil, - expectation: false, - }, - "deprecated-unknown-value": { - input: Float64{Unknown: true}, - candidate: Float64Value(123), - expectation: false, - }, - "deprecated-unknown-unknown": { - input: Float64{Unknown: true}, - candidate: Float64Unknown(), - expectation: false, // intentional - }, - "deprecated-unknown-null": { - input: Float64{Unknown: true}, - candidate: Float64Null(), - expectation: false, - }, - "deprecated-unknown-deprecated-value": { - input: Float64{Unknown: true}, - candidate: Float64{Value: 123}, - expectation: false, - }, - "deprecated-unknown-deprecated-unknown": { - input: Float64{Unknown: true}, - candidate: Float64{Unknown: true}, - expectation: true, - }, - "deprecated-unknown-deprecated-null": { - input: Float64{Unknown: true}, - candidate: Float64{Null: true}, - expectation: false, - }, - "deprecated-unknown-wrongType": { - input: Float64{Unknown: true}, - candidate: &String{Value: "oops"}, - expectation: false, - }, - "deprecated-unknown-nil": { - input: Float64{Unknown: true}, - candidate: nil, - expectation: false, - }, - "deprecated-null-known": { - input: Float64{Null: true}, - candidate: Float64Value(123), - expectation: false, - }, - "deprecated-null-unknown": { - input: Float64{Null: true}, - candidate: Float64Unknown(), - expectation: false, - }, - "deprecated-null-null": { - input: Float64{Null: true}, - candidate: Float64Null(), - expectation: false, // intentional - }, - "deprecated-null-deprecated-known": { - input: Float64{Null: true}, - candidate: Float64{Value: 123}, - expectation: false, - }, - "deprecated-null-deprecated-unknown": { - input: Float64{Null: true}, - candidate: Float64{Unknown: true}, - expectation: false, - }, - "deprecated-null-deprecated-null": { - input: Float64{Null: true}, - candidate: Float64{Null: true}, - expectation: true, - }, - "deprecated-null-wrongType": { - input: Float64{Null: true}, - candidate: &String{Value: "oops"}, - expectation: false, - }, - "deprecated-null-nil": { - input: Float64{Null: true}, - candidate: nil, - expectation: false, - }, } for name, test := range tests { name, test := name, test @@ -437,30 +229,14 @@ func TestFloat64IsNull(t *testing.T) { input: Float64Value(2.4), expected: false, }, - "deprecated-known": { - input: Float64{Value: 2.4}, - expected: false, - }, "null": { input: Float64Null(), expected: true, }, - "deprecated-null": { - input: Float64{Null: true}, - expected: true, - }, "unknown": { input: Float64Unknown(), expected: false, }, - "deprecated-unknown": { - input: Float64{Unknown: true}, - expected: false, - }, - "deprecated-invalid": { - input: Float64{Null: true, Unknown: true}, - expected: true, - }, } for name, testCase := range testCases { @@ -489,30 +265,14 @@ func TestFloat64IsUnknown(t *testing.T) { input: Float64Value(2.4), expected: false, }, - "deprecated-known": { - input: Float64{Value: 2.4}, - expected: false, - }, "null": { input: Float64Null(), expected: false, }, - "deprecated-null": { - input: Float64{Null: true}, - expected: false, - }, "unknown": { input: Float64Unknown(), expected: true, }, - "deprecated-unknown": { - input: Float64{Unknown: true}, - expected: true, - }, - "deprecated-invalid": { - input: Float64{Null: true, Unknown: true}, - expected: true, - }, } for name, testCase := range testCases { @@ -570,41 +330,9 @@ func TestFloat64String(t *testing.T) { input: Float64Null(), expectation: "", }, - "deprecated-known-less-than-one": { - input: Float64{Value: 0.12340984302980000}, - expectation: "0.123410", - }, - "deprecated-known-more-than-one": { - input: Float64{Value: 92387938173219.327663}, - expectation: "92387938173219.328125", - }, - "deprecated-known-negative-more-than-one": { - input: Float64{Value: -0.12340984302980000}, - expectation: "-0.123410", - }, - "deprecated-known-negative-less-than-one": { - input: Float64{Value: -92387938173219.327663}, - expectation: "-92387938173219.328125", - }, - "deprecated-known-min-float64": { - input: Float64{Value: math.SmallestNonzeroFloat64}, - expectation: "0.000000", - }, - "deprecated-known-max-float64": { - input: Float64{Value: math.MaxFloat64}, - expectation: "179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.000000", - }, - "deprecated-known-unknown": { - input: Float64{Unknown: true}, - expectation: "", - }, - "deprecated-known-null": { - input: Float64{Null: true}, - expectation: "", - }, - "default-0": { + "zero-value": { input: Float64{}, - expectation: "0.000000", + expectation: "", }, } @@ -632,30 +360,14 @@ func TestFloat64ValueFloat64(t *testing.T) { input: Float64Value(2.4), expected: 2.4, }, - "deprecated-known": { - input: Float64{Value: 2.4}, - expected: 2.4, - }, "null": { input: Float64Null(), expected: 0.0, }, - "deprecated-null": { - input: Float64{Null: true}, - expected: 0.0, - }, "unknown": { input: Float64Unknown(), expected: 0.0, }, - "deprecated-unknown": { - input: Float64{Unknown: true}, - expected: 0.0, - }, - "deprecated-invalid": { - input: Float64{Null: true, Unknown: true}, - expected: 0.0, - }, } for name, testCase := range testCases { diff --git a/types/int64.go b/types/int64.go index 6d5d2f67c..cda43fbe0 100644 --- a/types/int64.go +++ b/types/int64.go @@ -22,7 +22,7 @@ var ( // creating a Int64 with this function has no effect. func Int64Null() Int64 { return Int64{ - state: valueStateNull, + state: attr.ValueStateNull, } } @@ -33,7 +33,7 @@ func Int64Null() Int64 { // creating a Int64 with this function has no effect. func Int64Unknown() Int64 { return Int64{ - state: valueStateUnknown, + state: attr.ValueStateUnknown, } } @@ -44,7 +44,7 @@ func Int64Unknown() Int64 { // creating a Int64 with this function has no effect. func Int64Value(value int64) Int64 { return Int64{ - state: valueStateKnown, + state: attr.ValueStateKnown, value: value, } } @@ -108,17 +108,11 @@ func int64Validate(_ context.Context, in tftypes.Value, path path.Path) diag.Dia func int64ValueFromTerraform(ctx context.Context, in tftypes.Value) (attr.Value, error) { if !in.IsKnown() { - return Int64{ - Unknown: true, - state: valueStateDeprecated, - }, nil + return Int64Unknown(), nil } if in.IsNull() { - return Int64{ - Null: true, - state: valueStateDeprecated, - }, nil + return Int64Null(), nil } var bigF *big.Float @@ -138,51 +132,14 @@ func int64ValueFromTerraform(ctx context.Context, in tftypes.Value) (attr.Value, return nil, fmt.Errorf("Value %s cannot be represented as a 64-bit integer.", bigF) } - return Int64{ - Value: i, - state: valueStateDeprecated, - }, nil + return Int64Value(i), nil } // Int64 represents a 64-bit integer value, exposed as an int64. type Int64 struct { - // Unknown will be true if the value is not yet known. - // - // If the Int64 was created with the Int64Value, Int64Null, or Int64Unknown - // functions, changing this field has no effect. - // - // Deprecated: Use the Int64Unknown function to create an unknown Int64 - // value or use the IsUnknown method to determine whether the Int64 value - // is unknown instead. - Unknown bool - - // Null will be true if the value was not set, or was explicitly set to - // null. - // - // If the Int64 was created with the Int64Value, Int64Null, or Int64Unknown - // functions, changing this field has no effect. - // - // Deprecated: Use the Int64Null function to create a null Int64 value or - // use the IsNull method to determine whether the Int64 value is null - // instead. - Null bool - - // Value contains the set value, as long as Unknown and Null are both - // false. - // - // If the Int64 was created with the Int64Value, Int64Null, or Int64Unknown - // functions, changing this field has no effect. - // - // Deprecated: Use the Int64Value function to create a known Int64 value or - // use the ValueInt64 method to retrieve the Int64 value instead. - Value int64 - - // state represents whether the Int64 is null, unknown, or known. During the - // exported field deprecation period, this state can also be "deprecated", - // which remains the zero-value for compatibility to ensure exported field - // updates take effect. The zero-value will be changed to null in a future - // version. - state valueState + // state represents whether the value is null, unknown, or known. The + // zero-value is null. + state attr.ValueState // value contains the known value, if not null or unknown. value int64 @@ -200,47 +157,25 @@ func (i Int64) Equal(other attr.Value) bool { return false } - if i.state == valueStateKnown { - return i.value == o.value - } - - if i.Unknown != o.Unknown { - return false - } - - if i.Null != o.Null { - return false + if i.state != attr.ValueStateKnown { + return true } - return i.Value == o.Value + return i.value == o.value } // ToTerraformValue returns the data contained in the Int64 as a tftypes.Value. func (i Int64) ToTerraformValue(ctx context.Context) (tftypes.Value, error) { switch i.state { - case valueStateDeprecated: - if i.Null { - return tftypes.NewValue(tftypes.Number, nil), nil - } - - if i.Unknown { - return tftypes.NewValue(tftypes.Number, tftypes.UnknownValue), nil - } - - bf := new(big.Float).SetInt64(i.Value) - if err := tftypes.ValidateValue(tftypes.Number, bf); err != nil { - return tftypes.NewValue(tftypes.Number, tftypes.UnknownValue), err - } - return tftypes.NewValue(tftypes.Number, bf), nil - case valueStateKnown: + case attr.ValueStateKnown: if err := tftypes.ValidateValue(tftypes.Number, i.value); err != nil { return tftypes.NewValue(tftypes.Number, tftypes.UnknownValue), err } return tftypes.NewValue(tftypes.Number, i.value), nil - case valueStateNull: + case attr.ValueStateNull: return tftypes.NewValue(tftypes.Number, nil), nil - case valueStateUnknown: + case attr.ValueStateUnknown: return tftypes.NewValue(tftypes.Number, tftypes.UnknownValue), nil default: panic(fmt.Sprintf("unhandled Int64 state in ToTerraformValue: %s", i.state)) @@ -254,20 +189,12 @@ func (i Int64) Type(ctx context.Context) attr.Type { // IsNull returns true if the Int64 represents a null value. func (i Int64) IsNull() bool { - if i.state == valueStateNull { - return true - } - - return i.state == valueStateDeprecated && i.Null + return i.state == attr.ValueStateNull } // IsUnknown returns true if the Int64 represents a currently unknown value. func (i Int64) IsUnknown() bool { - if i.state == valueStateUnknown { - return true - } - - return i.state == valueStateDeprecated && i.Unknown + return i.state == attr.ValueStateUnknown } // String returns a human-readable representation of the Int64 value. @@ -282,19 +209,11 @@ func (i Int64) String() string { return attr.NullValueString } - if i.state == valueStateKnown { - return fmt.Sprintf("%d", i.value) - } - - return fmt.Sprintf("%d", i.Value) + return fmt.Sprintf("%d", i.value) } // ValueInt64 returns the known float64 value. If Int64 is null or unknown, returns // 0.0. func (i Int64) ValueInt64() int64 { - if i.state == valueStateDeprecated { - return i.Value - } - return i.value } diff --git a/types/int64_test.go b/types/int64_test.go index 9fb4c544b..0271b6cbc 100644 --- a/types/int64_test.go +++ b/types/int64_test.go @@ -11,84 +11,6 @@ import ( "github.com/hashicorp/terraform-plugin-go/tftypes" ) -// This test verifies the assumptions that creating the Value via function then -// setting the fields directly has no effects. -func TestInt64ValueDeprecatedFieldSetting(t *testing.T) { - t.Parallel() - - knownInt64 := Int64Value(24) - - knownInt64.Null = true - - if knownInt64.IsNull() { - t.Error("unexpected null update after Null field setting") - } - - knownInt64.Unknown = true - - if knownInt64.IsUnknown() { - t.Error("unexpected unknown update after Unknown field setting") - } - - knownInt64.Value = 48 - - if knownInt64.ValueInt64() == 48 { - t.Error("unexpected value update after Value field setting") - } -} - -// This test verifies the assumptions that creating the Value via function then -// setting the fields directly has no effects. -func TestInt64NullDeprecatedFieldSetting(t *testing.T) { - t.Parallel() - - nullInt64 := Int64Null() - - nullInt64.Null = false - - if !nullInt64.IsNull() { - t.Error("unexpected null update after Null field setting") - } - - nullInt64.Unknown = true - - if nullInt64.IsUnknown() { - t.Error("unexpected unknown update after Unknown field setting") - } - - nullInt64.Value = 48 - - if nullInt64.ValueInt64() == 48 { - t.Error("unexpected value update after Value field setting") - } -} - -// This test verifies the assumptions that creating the Value via function then -// setting the fields directly has no effects. -func TestInt64UnknownDeprecatedFieldSetting(t *testing.T) { - t.Parallel() - - unknownInt64 := Int64Unknown() - - unknownInt64.Null = true - - if unknownInt64.IsNull() { - t.Error("unexpected null update after Null field setting") - } - - unknownInt64.Unknown = false - - if !unknownInt64.IsUnknown() { - t.Error("unexpected unknown update after Unknown field setting") - } - - unknownInt64.Value = 48 - - if unknownInt64.ValueInt64() == 48 { - t.Error("unexpected value update after Value field setting") - } -} - func TestInt64ValueFromTerraform(t *testing.T) { t.Parallel() @@ -104,15 +26,15 @@ func testInt64ValueFromTerraform(t *testing.T, direct bool) { tests := map[string]testCase{ "value": { input: tftypes.NewValue(tftypes.Number, 123), - expectation: Int64{Value: 123}, + expectation: Int64Value(123), }, "unknown": { input: tftypes.NewValue(tftypes.Number, tftypes.UnknownValue), - expectation: Int64{Unknown: true}, + expectation: Int64Unknown(), }, "null": { input: tftypes.NewValue(tftypes.Number, nil), - expectation: Int64{Null: true}, + expectation: Int64Null(), }, "wrongType": { input: tftypes.NewValue(tftypes.String, "oops"), @@ -180,18 +102,6 @@ func TestInt64ToTerraformValue(t *testing.T) { input: Int64Null(), expectation: tftypes.NewValue(tftypes.Number, nil), }, - "deprecated-known": { - input: Int64{Value: 123}, - expectation: tftypes.NewValue(tftypes.Number, big.NewFloat(123)), - }, - "deprecated-unknown": { - input: Int64{Unknown: true}, - expectation: tftypes.NewValue(tftypes.Number, tftypes.UnknownValue), - }, - "deprecated-null": { - input: Int64{Null: true}, - expectation: tftypes.NewValue(tftypes.Number, nil), - }, } for name, test := range tests { name, test := name, test @@ -270,136 +180,6 @@ func TestInt64Equal(t *testing.T) { candidate: Int64Null(), expectation: true, }, - "deprecated-known-known-same": { - input: Int64{Value: 123}, - candidate: Int64Value(123), - expectation: false, // intentional - }, - "deprecated-known-known-diff": { - input: Int64{Value: 123}, - candidate: Int64Value(456), - expectation: false, - }, - "deprecated-known-unknown": { - input: Int64{Value: 123}, - candidate: Int64Unknown(), - expectation: false, - }, - "deprecated-known-null": { - input: Int64{Value: 123}, - candidate: Int64Null(), - expectation: false, - }, - "deprecated-known-deprecated-known-same": { - input: Int64{Value: 123}, - candidate: Int64{Value: 123}, - expectation: true, - }, - "deprecated-known-deprecated-known-diff": { - input: Int64{Value: 123}, - candidate: Int64{Value: 456}, - expectation: false, - }, - "deprecated-known-deprecated-unknown": { - input: Int64{Value: 123}, - candidate: Int64{Unknown: true}, - expectation: false, - }, - "deprecated-known-deprecated-null": { - input: Int64{Value: 123}, - candidate: Int64{Null: true}, - expectation: false, - }, - "deprecated-known-wrongType": { - input: Int64{Value: 123}, - candidate: &String{Value: "oops"}, - expectation: false, - }, - "deprecated-known-nil": { - input: Int64{Value: 123}, - candidate: nil, - expectation: false, - }, - "deprecated-unknown-value": { - input: Int64{Unknown: true}, - candidate: Int64Value(123), - expectation: false, - }, - "deprecated-unknown-unknown": { - input: Int64{Unknown: true}, - candidate: Int64Unknown(), - expectation: false, // intentional - }, - "deprecated-unknown-null": { - input: Int64{Unknown: true}, - candidate: Int64Null(), - expectation: false, - }, - "deprecated-unknown-deprecated-known": { - input: Int64{Unknown: true}, - candidate: Int64{Value: 123}, - expectation: false, - }, - "deprecated-unknown-deprecated-unknown": { - input: Int64{Unknown: true}, - candidate: Int64{Unknown: true}, - expectation: true, - }, - "deprecated-unknown-deprecated-null": { - input: Int64{Unknown: true}, - candidate: Int64{Null: true}, - expectation: false, - }, - "deprecated-unknown-wrongType": { - input: Int64{Unknown: true}, - candidate: &String{Value: "oops"}, - expectation: false, - }, - "deprecated-unknown-nil": { - input: Int64{Unknown: true}, - candidate: nil, - expectation: false, - }, - "deprecated-null-known": { - input: Int64{Null: true}, - candidate: Int64Value(123), - expectation: false, - }, - "deprecated-null-unknown": { - input: Int64{Null: true}, - candidate: Int64Unknown(), - expectation: false, - }, - "deprecated-null-null": { - input: Int64{Null: true}, - candidate: Int64Null(), - expectation: false, // intentional - }, - "deprecated-null-deprecated-known": { - input: Int64{Null: true}, - candidate: Int64{Value: 123}, - expectation: false, - }, - "deprecated-null-deprecated-unknown": { - input: Int64{Null: true}, - candidate: Int64{Unknown: true}, - expectation: false, - }, - "deprecated-null-deprecated-null": { - input: Int64{Null: true}, - candidate: Int64{Null: true}, - expectation: true, - }, - "deprecated-null-wrongType": { - input: Int64{Null: true}, - candidate: &String{Value: "oops"}, - expectation: false, - }, - "deprecated-null-nil": { - input: Int64{Null: true}, - candidate: nil, - expectation: false, - }, } for name, test := range tests { name, test := name, test @@ -425,30 +205,14 @@ func TestInt64IsNull(t *testing.T) { input: Int64Value(24), expected: false, }, - "deprecated-known": { - input: Int64{Value: 24}, - expected: false, - }, "null": { input: Int64Null(), expected: true, }, - "deprecated-null": { - input: Int64{Null: true}, - expected: true, - }, "unknown": { input: Int64Unknown(), expected: false, }, - "deprecated-unknown": { - input: Int64{Unknown: true}, - expected: false, - }, - "deprecated-invalid": { - input: Int64{Null: true, Unknown: true}, - expected: true, - }, } for name, testCase := range testCases { @@ -477,30 +241,14 @@ func TestInt64IsUnknown(t *testing.T) { input: Int64Value(24), expected: false, }, - "deprecated-known": { - input: Int64{Value: 24}, - expected: false, - }, "null": { input: Int64Null(), expected: false, }, - "deprecated-null": { - input: Int64{Null: true}, - expected: false, - }, "unknown": { input: Int64Unknown(), expected: true, }, - "deprecated-unknown": { - input: Int64{Unknown: true}, - expected: true, - }, - "deprecated-invalid": { - input: Int64{Null: true, Unknown: true}, - expected: true, - }, } for name, testCase := range testCases { @@ -550,33 +298,9 @@ func TestInt64String(t *testing.T) { input: Int64Null(), expectation: "", }, - "deprecated-known-less-than-one": { - input: Int64{Value: -12340984302980000}, - expectation: "-12340984302980000", - }, - "deprecated-known-more-than-one": { - input: Int64{Value: 92387938173219327}, - expectation: "92387938173219327", - }, - "deprecated-known-min-int64": { - input: Int64{Value: math.MinInt64}, - expectation: "-9223372036854775808", - }, - "deprecated-known-max-int64": { - input: Int64{Value: math.MaxInt64}, - expectation: "9223372036854775807", - }, - "deprecated-unknown": { - input: Int64{Unknown: true}, - expectation: "", - }, - "deprecated-null": { - input: Int64{Null: true}, - expectation: "", - }, - "default-0": { + "zero-value": { input: Int64{}, - expectation: "0", + expectation: "", }, } @@ -604,30 +328,14 @@ func TestInt64ValueInt64(t *testing.T) { input: Int64Value(24), expected: 24, }, - "deprecated-known": { - input: Int64{Value: 24}, - expected: 24, - }, "null": { input: Int64Null(), expected: 0, }, - "deprecated-null": { - input: Int64{Null: true}, - expected: 0, - }, "unknown": { input: Int64Unknown(), expected: 0, }, - "deprecated-unknown": { - input: Int64{Unknown: true}, - expected: 0, - }, - "deprecated-invalid": { - input: Int64{Null: true, Unknown: true}, - expected: 0, - }, } for name, testCase := range testCases { diff --git a/types/list.go b/types/list.go index 8b3cb9e96..1e33fd5ca 100644 --- a/types/list.go +++ b/types/list.go @@ -52,24 +52,17 @@ func (l ListType) TerraformType(ctx context.Context) tftypes.Type { // This is meant to convert the tftypes.Value into a more convenient Go // type for the provider to consume the data with. func (l ListType) ValueFromTerraform(ctx context.Context, in tftypes.Value) (attr.Value, error) { - list := List{ - ElemType: l.ElemType, - state: valueStateDeprecated, - } if in.Type() == nil { - list.Null = true - return list, nil + return ListNull(l.ElemType), nil } if !in.Type().Equal(l.TerraformType(ctx)) { return nil, fmt.Errorf("can't use %s as value of List with ElementType %T, can only use %s values", in.String(), l.ElemType, l.ElemType.TerraformType(ctx).String()) } if !in.IsKnown() { - list.Unknown = true - return list, nil + return ListUnknown(l.ElemType), nil } if in.IsNull() { - list.Null = true - return list, nil + return ListNull(l.ElemType), nil } val := []tftypes.Value{} err := in.As(&val) @@ -84,8 +77,9 @@ func (l ListType) ValueFromTerraform(ctx context.Context, in tftypes.Value) (att } elems = append(elems, av) } - list.Elems = elems - return list, nil + // ValueFromTerraform above on each element should make this safe. + // Otherwise, this will need to do some Diagnostics to error conversion. + return ListValueMust(l.ElemType, elems), nil } // Equal returns true if `o` is also a ListType and has the same ElemType. @@ -167,39 +161,30 @@ func (l ListType) Validate(ctx context.Context, in tftypes.Value, path path.Path // ValueType returns the Value type. func (t ListType) ValueType(_ context.Context) attr.Value { return List{ - ElemType: t.ElemType, + elementType: t.ElemType, } } // ListNull creates a List with a null value. Determine whether the value is // null via the List type IsNull method. -// -// Setting the deprecated List type ElemType, Elems, Null, or Unknown fields -// after creating a List with this function has no effect. func ListNull(elementType attr.Type) List { return List{ elementType: elementType, - state: valueStateNull, + state: attr.ValueStateNull, } } // ListUnknown creates a List with an unknown value. Determine whether the // value is unknown via the List type IsUnknown method. -// -// Setting the deprecated List type ElemType, Elems, Null, or Unknown fields -// after creating a List with this function has no effect. func ListUnknown(elementType attr.Type) List { return List{ elementType: elementType, - state: valueStateUnknown, + state: attr.ValueStateUnknown, } } // ListValue creates a List with a known value. Access the value via the List // type Elements or ElementsAs methods. -// -// Setting the deprecated List type ElemType, Elems, Null, or Unknown fields -// after creating a List with this function has no effect. func ListValue(elementType attr.Type, elements []attr.Value) (List, diag.Diagnostics) { var diags diag.Diagnostics @@ -226,7 +211,7 @@ func ListValue(elementType attr.Type, elements []attr.Value) (List, diag.Diagnos return List{ elementType: elementType, elements: elements, - state: valueStateKnown, + state: attr.ValueStateKnown, }, nil } @@ -266,9 +251,6 @@ func ListValueFrom(ctx context.Context, elementType attr.Type, elements any) (Li // This creation function is only recommended to create List values which will // not potentially effect practitioners, such as testing, or exhaustively // tested provider logic. -// -// Setting the deprecated List type ElemType, Elems, Null, or Unknown fields -// after creating a List with this function has no effect. func ListValueMust(elementType attr.Type, elements []attr.Value) List { list, diags := ListValue(elementType, elements) @@ -293,72 +275,20 @@ func ListValueMust(elementType attr.Type, elements []attr.Value) List { // List represents a list of attr.Values, all of the same type, indicated // by ElemType. type List struct { - // Unknown will be set to true if the entire list is an unknown value. - // If only some of the elements in the list are unknown, their known or - // unknown status will be represented however that attr.Value - // surfaces that information. The List's Unknown property only tracks - // if the number of elements in a List is known, not whether the - // elements that are in the list are known. - // - // If the List was created with the ListValue, ListNull, or ListUnknown - // functions, changing this field has no effect. - // - // Deprecated: Use the ListUnknown function to create an unknown List - // value or use the IsUnknown method to determine whether the List value - // is unknown instead. - Unknown bool - - // Null will be set to true if the list is null, either because it was - // omitted from the configuration, state, or plan, or because it was - // explicitly set to null. - // - // If the List was created with the ListValue, ListNull, or ListUnknown - // functions, changing this field has no effect. - // - // Deprecated: Use the ListNull function to create a null List value or - // use the IsNull method to determine whether the List value is null - // instead. - Null bool - - // Elems are the elements in the list. - // - // If the List was created with the ListValue, ListNull, or ListUnknown - // functions, changing this field has no effect. - // - // Deprecated: Use the ListValue function to create a known List value or - // use the Elements or ElementsAs methods to retrieve the List elements - // instead. - Elems []attr.Value - - // ElemType is the tftypes.Type of the elements in the list. All - // elements in the list must be of this type. - // - // Deprecated: Use the ListValue, ListNull, or ListUnknown functions - // to create a List or use the ElementType method to retrieve the - // List element type instead. - ElemType attr.Type - // elements is the collection of known values in the List. elements []attr.Value // elementType is the type of the elements in the List. elementType attr.Type - // state represents whether the List is null, unknown, or known. During the - // exported field deprecation period, this state can also be "deprecated", - // which remains the zero-value for compatibility to ensure exported field - // updates take effect. The zero-value will be changed to null in a future - // version. - state valueState + // state represents whether the value is null, unknown, or known. The + // zero-value is null. + state attr.ValueState } // Elements returns the collection of elements for the List. Returns nil if the // List is null or unknown. func (l List) Elements() []attr.Value { - if l.state == valueStateDeprecated { - return l.Elems - } - return l.elements } @@ -376,7 +306,7 @@ func (l List) ElementsAs(ctx context.Context, target interface{}, allowUnhandled ), } } - return reflect.Into(ctx, ListType{ElemType: l.ElemType}, values, target, reflect.Options{ + return reflect.Into(ctx, ListType{ElemType: l.elementType}, values, target, reflect.Options{ UnhandledNullAsEmpty: allowUnhandled, UnhandledUnknownAsEmpty: allowUnhandled, }, path.Empty()) @@ -384,10 +314,6 @@ func (l List) ElementsAs(ctx context.Context, target interface{}, allowUnhandled // ElementType returns the element type for the List. func (l List) ElementType(_ context.Context) attr.Type { - if l.state == valueStateDeprecated { - return l.ElemType - } - return l.elementType } @@ -398,32 +324,10 @@ func (l List) Type(ctx context.Context) attr.Type { // ToTerraformValue returns the data contained in the List as a tftypes.Value. func (l List) ToTerraformValue(ctx context.Context) (tftypes.Value, error) { - if l.state == valueStateDeprecated && l.ElemType == nil { - return tftypes.Value{}, fmt.Errorf("cannot convert List to tftypes.Value if ElemType field is not set") - } listType := tftypes.List{ElementType: l.ElementType(ctx).TerraformType(ctx)} switch l.state { - case valueStateDeprecated: - if l.Unknown { - return tftypes.NewValue(listType, tftypes.UnknownValue), nil - } - if l.Null { - return tftypes.NewValue(listType, nil), nil - } - vals := make([]tftypes.Value, 0, len(l.Elems)) - for _, elem := range l.Elems { - val, err := elem.ToTerraformValue(ctx) - if err != nil { - return tftypes.NewValue(listType, tftypes.UnknownValue), err - } - vals = append(vals, val) - } - if err := tftypes.ValidateValue(listType, vals); err != nil { - return tftypes.NewValue(listType, tftypes.UnknownValue), err - } - return tftypes.NewValue(listType, vals), nil - case valueStateKnown: + case attr.ValueStateKnown: vals := make([]tftypes.Value, 0, len(l.elements)) for _, elem := range l.elements { @@ -441,9 +345,9 @@ func (l List) ToTerraformValue(ctx context.Context) (tftypes.Value, error) { } return tftypes.NewValue(listType, vals), nil - case valueStateNull: + case attr.ValueStateNull: return tftypes.NewValue(listType, nil), nil - case valueStateUnknown: + case attr.ValueStateUnknown: return tftypes.NewValue(listType, tftypes.UnknownValue), nil default: panic(fmt.Sprintf("unhandled List state in ToTerraformValue: %s", l.state)) @@ -454,73 +358,48 @@ func (l List) ToTerraformValue(ctx context.Context) (tftypes.Value, error) { // (same type and same value) to the attr.Value passed as an argument. func (l List) Equal(o attr.Value) bool { other, ok := o.(List) + if !ok { return false } - if l.state != other.state { - return false - } - if l.state == valueStateKnown { - if !l.elementType.Equal(other.elementType) { - return false - } - - if len(l.elements) != len(other.elements) { - return false - } - - for idx, lElem := range l.elements { - otherElem := other.elements[idx] - - if !lElem.Equal(otherElem) { - return false - } - } - return true - } - if l.Unknown != other.Unknown { + if !l.elementType.Equal(other.elementType) { return false } - if l.Null != other.Null { - return false - } - if l.ElemType == nil && other.ElemType != nil { + + if l.state != other.state { return false } - if l.ElemType != nil && !l.ElemType.Equal(other.ElemType) { - return false + + if l.state != attr.ValueStateKnown { + return true } - if len(l.Elems) != len(other.Elems) { + + if len(l.elements) != len(other.elements) { return false } - for pos, lElem := range l.Elems { - oElem := other.Elems[pos] - if !lElem.Equal(oElem) { + + for idx, lElem := range l.elements { + otherElem := other.elements[idx] + + if !lElem.Equal(otherElem) { return false } } + return true } // IsNull returns true if the List represents a null value. func (l List) IsNull() bool { - if l.state == valueStateNull { - return true - } - - return l.state == valueStateDeprecated && l.Null + return l.state == attr.ValueStateNull } // IsUnknown returns true if the List represents a currently unknown value. // Returns false if the List has a known number of elements, even if all are // unknown values. func (l List) IsUnknown() bool { - if l.state == valueStateUnknown { - return true - } - - return l.state == valueStateDeprecated && l.Unknown + return l.state == attr.ValueStateUnknown } // String returns a human-readable representation of the List value. diff --git a/types/list_test.go b/types/list_test.go index ad87391dc..202a841b3 100644 --- a/types/list_test.go +++ b/types/list_test.go @@ -87,13 +87,13 @@ func TestListTypeValueFromTerraform(t *testing.T) { tftypes.NewValue(tftypes.String, "hello"), tftypes.NewValue(tftypes.String, "world"), }), - expected: List{ - ElemType: StringType, - Elems: []attr.Value{ - String{Value: "hello"}, - String{Value: "world"}, + expected: ListValueMust( + StringType, + []attr.Value{ + StringValue("hello"), + StringValue("world"), }, - }, + ), }, "unknown-list": { receiver: ListType{ @@ -102,10 +102,7 @@ func TestListTypeValueFromTerraform(t *testing.T) { input: tftypes.NewValue(tftypes.List{ ElementType: tftypes.String, }, tftypes.UnknownValue), - expected: List{ - ElemType: StringType, - Unknown: true, - }, + expected: ListUnknown(StringType), }, "partially-unknown-list": { receiver: ListType{ @@ -117,13 +114,13 @@ func TestListTypeValueFromTerraform(t *testing.T) { tftypes.NewValue(tftypes.String, "hello"), tftypes.NewValue(tftypes.String, tftypes.UnknownValue), }), - expected: List{ - ElemType: StringType, - Elems: []attr.Value{ - String{Value: "hello"}, - String{Unknown: true}, + expected: ListValueMust( + StringType, + []attr.Value{ + StringValue("hello"), + StringUnknown(), }, - }, + ), }, "null-list": { receiver: ListType{ @@ -132,10 +129,7 @@ func TestListTypeValueFromTerraform(t *testing.T) { input: tftypes.NewValue(tftypes.List{ ElementType: tftypes.String, }, nil), - expected: List{ - ElemType: StringType, - Null: true, - }, + expected: ListNull(StringType), }, "partially-null-list": { receiver: ListType{ @@ -147,13 +141,13 @@ func TestListTypeValueFromTerraform(t *testing.T) { tftypes.NewValue(tftypes.String, "hello"), tftypes.NewValue(tftypes.String, nil), }), - expected: List{ - ElemType: StringType, - Elems: []attr.Value{ - String{Value: "hello"}, - String{Null: true}, + expected: ListValueMust( + StringType, + []attr.Value{ + StringValue("hello"), + StringNull(), }, - }, + ), }, "wrong-type": { receiver: ListType{ @@ -177,11 +171,8 @@ func TestListTypeValueFromTerraform(t *testing.T) { receiver: ListType{ ElemType: StringType, }, - input: tftypes.NewValue(nil, nil), - expected: List{ - ElemType: StringType, - Null: true, - }, + input: tftypes.NewValue(nil, nil), + expected: ListNull(StringType), }, } for name, test := range tests { @@ -346,18 +337,18 @@ func TestListValueFrom(t *testing.T) { "valid-StringType-[]attr.Value-empty": { elementType: StringType, elements: []attr.Value{}, - expected: List{ - ElemType: StringType, - Elems: []attr.Value{}, - }, + expected: ListValueMust( + StringType, + []attr.Value{}, + ), }, "valid-StringType-[]types.String-empty": { elementType: StringType, elements: []String{}, - expected: List{ - ElemType: StringType, - Elems: []attr.Value{}, - }, + expected: ListValueMust( + StringType, + []attr.Value{}, + ), }, "valid-StringType-[]types.String": { elementType: StringType, @@ -366,14 +357,14 @@ func TestListValueFrom(t *testing.T) { StringUnknown(), StringValue("test"), }, - expected: List{ - ElemType: StringType, - Elems: []attr.Value{ - String{Null: true}, - String{Unknown: true}, - String{Value: "test"}, + expected: ListValueMust( + StringType, + []attr.Value{ + StringNull(), + StringUnknown(), + StringValue("test"), }, - }, + ), }, "valid-StringType-[]*string": { elementType: StringType, @@ -382,14 +373,14 @@ func TestListValueFrom(t *testing.T) { pointer("test1"), pointer("test2"), }, - expected: List{ - ElemType: StringType, - Elems: []attr.Value{ - String{Null: true}, - String{Value: "test1"}, - String{Value: "test2"}, + expected: ListValueMust( + StringType, + []attr.Value{ + StringNull(), + StringValue("test1"), + StringValue("test2"), }, - }, + ), }, "valid-StringType-[]string": { elementType: StringType, @@ -397,13 +388,13 @@ func TestListValueFrom(t *testing.T) { "test1", "test2", }, - expected: List{ - ElemType: StringType, - Elems: []attr.Value{ - String{Value: "test1"}, - String{Value: "test2"}, + expected: ListValueMust( + StringType, + []attr.Value{ + StringValue("test1"), + StringValue("test2"), }, - }, + ), }, "invalid-not-slice": { elementType: StringType, @@ -452,96 +443,19 @@ func TestListValueFrom(t *testing.T) { } } -// This test verifies the assumptions that creating the Value via function then -// setting the fields directly has no effects. -func TestListValue_DeprecatedFieldSetting(t *testing.T) { - t.Parallel() - - knownList := ListValueMust(StringType, []attr.Value{StringValue("test")}) - - knownList.Null = true - - if knownList.IsNull() { - t.Error("unexpected null update after Null field setting") - } - - knownList.Unknown = true - - if knownList.IsUnknown() { - t.Error("unexpected unknown update after Unknown field setting") - } - - knownList.Elems = []attr.Value{StringValue("not-test")} - - if knownList.Elements()[0].Equal(StringValue("not-test")) { - t.Error("unexpected value update after Value field setting") - } -} - -// This test verifies the assumptions that creating the Value via function then -// setting the fields directly has no effects. -func TestListNull_DeprecatedFieldSetting(t *testing.T) { - t.Parallel() - - nullList := ListNull(StringType) - - nullList.Null = false - - if !nullList.IsNull() { - t.Error("unexpected null update after Null field setting") - } - - nullList.Unknown = true - - if nullList.IsUnknown() { - t.Error("unexpected unknown update after Unknown field setting") - } - - nullList.Elems = []attr.Value{StringValue("test")} - - if len(nullList.Elements()) > 0 { - t.Error("unexpected value update after Value field setting") - } -} - -// This test verifies the assumptions that creating the Value via function then -// setting the fields directly has no effects. -func TestListUnknown_DeprecatedFieldSetting(t *testing.T) { - t.Parallel() - - unknownList := ListUnknown(StringType) - - unknownList.Null = true - - if unknownList.IsNull() { - t.Error("unexpected null update after Null field setting") - } - - unknownList.Unknown = false - - if !unknownList.IsUnknown() { - t.Error("unexpected unknown update after Unknown field setting") - } - - unknownList.Elems = []attr.Value{StringValue("test")} - - if len(unknownList.Elements()) > 0 { - t.Error("unexpected value update after Value field setting") - } -} - func TestListElementsAs_stringSlice(t *testing.T) { t.Parallel() var stringSlice []string expected := []string{"hello", "world"} - diags := (List{ - ElemType: StringType, - Elems: []attr.Value{ - String{Value: "hello"}, - String{Value: "world"}, - }}).ElementsAs(context.Background(), &stringSlice, false) + diags := ListValueMust( + StringType, + []attr.Value{ + StringValue("hello"), + StringValue("world"), + }, + ).ElementsAs(context.Background(), &stringSlice, false) if diags.HasError() { t.Errorf("Unexpected error: %v", diags) } @@ -555,16 +469,17 @@ func TestListElementsAs_attributeValueSlice(t *testing.T) { var stringSlice []String expected := []String{ - {Value: "hello"}, - {Value: "world"}, + StringValue("hello"), + StringValue("world"), } - diags := (List{ - ElemType: StringType, - Elems: []attr.Value{ - String{Value: "hello"}, - String{Value: "world"}, - }}).ElementsAs(context.Background(), &stringSlice, false) + diags := ListValueMust( + StringType, + []attr.Value{ + StringValue("hello"), + StringValue("world"), + }, + ).ElementsAs(context.Background(), &stringSlice, false) if diags.HasError() { t.Errorf("Unexpected error: %v", diags) } @@ -629,78 +544,6 @@ func TestListToTerraformValue(t *testing.T) { input: ListNull(StringType), expectation: tftypes.NewValue(tftypes.List{ElementType: tftypes.String}, nil), }, - "deprecated-known": { - input: List{ - ElemType: StringType, - Elems: []attr.Value{ - String{Value: "hello"}, - String{Value: "world"}, - }, - }, - expectation: tftypes.NewValue(tftypes.List{ElementType: tftypes.String}, []tftypes.Value{ - tftypes.NewValue(tftypes.String, "hello"), - tftypes.NewValue(tftypes.String, "world"), - }), - }, - "deprecated-known-duplicates": { - input: List{ - ElemType: StringType, - Elems: []attr.Value{ - String{Value: "hello"}, - String{Value: "hello"}, - }, - }, - // Duplicate validation does not occur during this method. - // This is okay, as tftypes allows duplicates. - expectation: tftypes.NewValue(tftypes.List{ElementType: tftypes.String}, []tftypes.Value{ - tftypes.NewValue(tftypes.String, "hello"), - tftypes.NewValue(tftypes.String, "hello"), - }), - }, - "deprecated-unknown": { - input: List{ElemType: StringType, Unknown: true}, - expectation: tftypes.NewValue(tftypes.List{ElementType: tftypes.String}, tftypes.UnknownValue), - }, - "deprecated-null": { - input: List{ElemType: StringType, Null: true}, - expectation: tftypes.NewValue(tftypes.List{ElementType: tftypes.String}, nil), - }, - "deprecated-known-partial-unknown": { - input: List{ - ElemType: StringType, - Elems: []attr.Value{ - String{Unknown: true}, - String{Value: "hello, world"}, - }, - }, - expectation: tftypes.NewValue(tftypes.List{ElementType: tftypes.String}, []tftypes.Value{ - tftypes.NewValue(tftypes.String, tftypes.UnknownValue), - tftypes.NewValue(tftypes.String, "hello, world"), - }), - }, - "deprecated-known-partial-null": { - input: List{ - ElemType: StringType, - Elems: []attr.Value{ - String{Null: true}, - String{Value: "hello, world"}, - }, - }, - expectation: tftypes.NewValue(tftypes.List{ElementType: tftypes.String}, []tftypes.Value{ - tftypes.NewValue(tftypes.String, nil), - tftypes.NewValue(tftypes.String, "hello, world"), - }), - }, - "no-elem-type": { - input: List{ - Elems: []attr.Value{ - String{Value: "hello"}, - String{Value: "world"}, - }, - }, - expectation: tftypes.Value{}, - expectedErr: "cannot convert List to tftypes.Value if ElemType field is not set", - }, } for name, test := range tests { name, test := name, test @@ -744,26 +587,14 @@ func TestListElements(t *testing.T) { input: ListValueMust(StringType, []attr.Value{StringValue("test")}), expected: []attr.Value{StringValue("test")}, }, - "deprecated-known": { - input: List{ElemType: StringType, Elems: []attr.Value{StringValue("test")}}, - expected: []attr.Value{StringValue("test")}, - }, "null": { input: ListNull(StringType), expected: nil, }, - "deprecated-null": { - input: List{ElemType: StringType, Null: true}, - expected: nil, - }, "unknown": { input: ListUnknown(StringType), expected: nil, }, - "deprecated-unknown": { - input: List{ElemType: StringType, Unknown: true}, - expected: nil, - }, } for name, testCase := range testCases { @@ -792,26 +623,14 @@ func TestListElementType(t *testing.T) { input: ListValueMust(StringType, []attr.Value{StringValue("test")}), expected: StringType, }, - "deprecated-known": { - input: List{ElemType: StringType, Elems: []attr.Value{StringValue("test")}}, - expected: StringType, - }, "null": { input: ListNull(StringType), expected: StringType, }, - "deprecated-null": { - input: List{ElemType: StringType, Null: true}, - expected: StringType, - }, "unknown": { input: ListUnknown(StringType), expected: StringType, }, - "deprecated-unknown": { - input: List{ElemType: StringType, Unknown: true}, - expected: StringType, - }, } for name, testCase := range testCases { @@ -991,231 +810,6 @@ func TestListEqual(t *testing.T) { input: nil, expected: false, }, - "known-deprecated-known": { - receiver: ListValueMust( - StringType, - []attr.Value{ - StringValue("hello"), - StringValue("world"), - }, - ), - input: List{ - ElemType: StringType, - Elems: []attr.Value{ - String{Value: "hello"}, - String{Value: "world"}, - }, - }, - expected: false, // intentional - }, - "known-deprecated-unknown": { - receiver: ListValueMust( - StringType, - []attr.Value{ - StringValue("hello"), - StringValue("world"), - }, - ), - input: List{ElemType: StringType, Unknown: true}, - expected: false, - }, - "known-deprecated-null": { - receiver: ListValueMust( - StringType, - []attr.Value{ - StringValue("hello"), - StringValue("world"), - }, - ), - input: List{ElemType: StringType, Null: true}, - expected: false, - }, - "deprecated-known-deprecated-known": { - receiver: List{ - ElemType: StringType, - Elems: []attr.Value{ - String{Value: "hello"}, - String{Value: "world"}, - }, - }, - input: List{ - ElemType: StringType, - Elems: []attr.Value{ - String{Value: "hello"}, - String{Value: "world"}, - }, - }, - expected: true, - }, - "deprecated-known-deprecated-known-diff-value": { - receiver: List{ - ElemType: StringType, - Elems: []attr.Value{ - String{Value: "hello"}, - String{Value: "world"}, - }, - }, - input: List{ - ElemType: StringType, - Elems: []attr.Value{ - String{Value: "goodnight"}, - String{Value: "moon"}, - }, - }, - expected: false, - }, - "deprecated-known-deprecated-known-diff-length": { - receiver: List{ - ElemType: StringType, - Elems: []attr.Value{ - String{Value: "hello"}, - String{Value: "world"}, - }, - }, - input: List{ - ElemType: StringType, - Elems: []attr.Value{ - String{Value: "hello"}, - String{Value: "world"}, - String{Value: "test"}, - }, - }, - expected: false, - }, - "deprecated-known-deprecated-known-diff-type": { - receiver: List{ - ElemType: StringType, - Elems: []attr.Value{ - String{Value: "hello"}, - String{Value: "world"}, - }, - }, - input: List{ - ElemType: BoolType, - Elems: []attr.Value{ - Bool{Value: false}, - Bool{Value: true}, - }, - }, - expected: false, - }, - "deprecated-known-deprecated-known-diff-unknown": { - receiver: List{ - ElemType: StringType, - Elems: []attr.Value{ - String{Value: "hello"}, - String{Unknown: true}, - }, - }, - input: List{ - ElemType: StringType, - Elems: []attr.Value{ - String{Value: "hello"}, - String{Value: "world"}, - }, - }, - expected: false, - }, - "deprecated-known-deprecated-known-diff-null": { - receiver: List{ - ElemType: StringType, - Elems: []attr.Value{ - String{Value: "hello"}, - String{Null: true}, - }, - }, - input: List{ - ElemType: StringType, - Elems: []attr.Value{ - String{Value: "hello"}, - String{Value: "world"}, - }, - }, - expected: false, - }, - "deprecated-known-deprecated-unknown": { - receiver: List{ - ElemType: StringType, - Elems: []attr.Value{ - String{Value: "hello"}, - String{Value: "world"}, - }, - }, - input: List{Unknown: true}, - expected: false, - }, - "deprecated-known-deprecated-null": { - receiver: List{ - ElemType: StringType, - Elems: []attr.Value{ - String{Value: "hello"}, - String{Value: "world"}, - }, - }, - input: List{Null: true}, - expected: false, - }, - "deprecated-known-known": { - receiver: List{ - ElemType: StringType, - Elems: []attr.Value{ - String{Value: "hello"}, - String{Value: "world"}, - }, - }, - input: ListValueMust( - StringType, - []attr.Value{ - StringValue("hello"), - StringValue("world"), - }, - ), - expected: false, // intentional - }, - "deprecated-known-unknown": { - receiver: List{ - ElemType: StringType, - Elems: []attr.Value{ - String{Value: "hello"}, - String{Value: "world"}, - }, - }, - input: ListUnknown(StringType), - expected: false, - }, - "deprecated-known-null": { - receiver: List{ - ElemType: StringType, - Elems: []attr.Value{ - String{Value: "hello"}, - String{Value: "world"}, - }, - }, - input: ListNull(StringType), - expected: false, - }, - "deprecated-known-diff-type": { - receiver: List{ - ElemType: StringType, - Elems: []attr.Value{ - String{Value: "hello"}, - String{Value: "world"}, - }, - }, - input: String{Value: "hello, world"}, - expected: false, - }, - "deprecated-known-nil": { - receiver: List{ - ElemType: StringType, - Elems: []attr.Value{ - String{Value: "hello"}, - String{Value: "world"}, - }, - }, - input: nil, - expected: false, - }, } for name, test := range tests { name, test := name, test @@ -1241,30 +835,14 @@ func TestListIsNull(t *testing.T) { input: ListValueMust(StringType, []attr.Value{StringValue("test")}), expected: false, }, - "deprecated-known": { - input: List{ElemType: StringType, Elems: []attr.Value{StringValue("test")}}, - expected: false, - }, "null": { input: ListNull(StringType), expected: true, }, - "deprecated-null": { - input: List{ElemType: StringType, Null: true}, - expected: true, - }, "unknown": { input: ListUnknown(StringType), expected: false, }, - "deprecated-unknown": { - input: List{ElemType: StringType, Unknown: true}, - expected: false, - }, - "deprecated-invalid": { - input: List{ElemType: StringType, Null: true, Unknown: true}, - expected: true, - }, } for name, testCase := range testCases { @@ -1293,30 +871,14 @@ func TestListIsUnknown(t *testing.T) { input: ListValueMust(StringType, []attr.Value{StringValue("test")}), expected: false, }, - "deprecated-known": { - input: List{ElemType: StringType, Elems: []attr.Value{StringValue("test")}}, - expected: false, - }, "null": { input: ListNull(StringType), expected: false, }, - "deprecated-null": { - input: List{ElemType: StringType, Null: true}, - expected: false, - }, "unknown": { input: ListUnknown(StringType), expected: true, }, - "deprecated-unknown": { - input: List{ElemType: StringType, Unknown: true}, - expected: true, - }, - "deprecated-invalid": { - input: List{ElemType: StringType, Null: true, Unknown: true}, - expected: true, - }, } for name, testCase := range testCases { @@ -1384,51 +946,9 @@ func TestListString(t *testing.T) { input: ListNull(StringType), expectation: "", }, - "deprecated-known": { - input: List{ - ElemType: StringType, - Elems: []attr.Value{ - String{Value: "hello"}, - String{Value: "world"}, - }, - }, - expectation: `["hello","world"]`, - }, - "deprecated-known-list-of-lists": { - input: List{ - ElemType: ListType{ - ElemType: StringType, - }, - Elems: []attr.Value{ - List{ - ElemType: StringType, - Elems: []attr.Value{ - String{Value: "hello"}, - String{Value: "world"}, - }, - }, - List{ - ElemType: StringType, - Elems: []attr.Value{ - String{Value: "foo"}, - String{Value: "bar"}, - }, - }, - }, - }, - expectation: `[["hello","world"],["foo","bar"]]`, - }, - "deprecated-unknown": { - input: List{Unknown: true}, - expectation: "", - }, - "deprecated-null": { - input: List{Null: true}, - expectation: "", - }, - "default-empty": { + "zero-value": { input: List{}, - expectation: "[]", + expectation: "", }, } @@ -1457,8 +977,8 @@ func TestListType(t *testing.T) { input: ListValueMust( StringType, []attr.Value{ - String{Value: "hello"}, - String{Value: "world"}, + StringValue("hello"), + StringValue("world"), }, ), expectation: ListType{ElemType: StringType}, @@ -1472,15 +992,15 @@ func TestListType(t *testing.T) { ListValueMust( StringType, []attr.Value{ - String{Value: "hello"}, - String{Value: "world"}, + StringValue("hello"), + StringValue("world"), }, ), ListValueMust( StringType, []attr.Value{ - String{Value: "foo"}, - String{Value: "bar"}, + StringValue("foo"), + StringValue("bar"), }, ), }, @@ -1499,52 +1019,6 @@ func TestListType(t *testing.T) { input: ListNull(StringType), expectation: ListType{ElemType: StringType}, }, - "deprecated-known": { - input: List{ - ElemType: StringType, - Elems: []attr.Value{ - String{Value: "hello"}, - String{Value: "world"}, - }, - }, - expectation: ListType{ElemType: StringType}, - }, - "deprecated-known-list-of-lists": { - input: List{ - ElemType: ListType{ - ElemType: StringType, - }, - Elems: []attr.Value{ - List{ - ElemType: StringType, - Elems: []attr.Value{ - String{Value: "hello"}, - String{Value: "world"}, - }, - }, - List{ - ElemType: StringType, - Elems: []attr.Value{ - String{Value: "foo"}, - String{Value: "bar"}, - }, - }, - }, - }, - expectation: ListType{ - ElemType: ListType{ - ElemType: StringType, - }, - }, - }, - "deprecated-unknown": { - input: List{ElemType: StringType, Unknown: true}, - expectation: ListType{ElemType: StringType}, - }, - "deprecated-null": { - input: List{ElemType: StringType, Null: true}, - expectation: ListType{ElemType: StringType}, - }, } for name, test := range tests { diff --git a/types/map.go b/types/map.go index 0b2319f03..a9c1443c0 100644 --- a/types/map.go +++ b/types/map.go @@ -53,13 +53,8 @@ func (m MapType) TerraformType(ctx context.Context) tftypes.Type { // meant to convert the tftypes.Value into a more convenient Go type for the // provider to consume the data with. func (m MapType) ValueFromTerraform(ctx context.Context, in tftypes.Value) (attr.Value, error) { - ma := Map{ - ElemType: m.ElemType, - state: valueStateDeprecated, - } if in.Type() == nil { - ma.Null = true - return ma, nil + return MapNull(m.ElemType), nil } if !in.Type().Is(tftypes.Map{}) { return nil, fmt.Errorf("can't use %s as value of Map, can only use tftypes.Map values", in.String()) @@ -68,12 +63,10 @@ func (m MapType) ValueFromTerraform(ctx context.Context, in tftypes.Value) (attr return nil, fmt.Errorf("can't use %s as value of Map with ElementType %T, can only use %s values", in.String(), m.ElemType, m.ElemType.TerraformType(ctx).String()) } if !in.IsKnown() { - ma.Unknown = true - return ma, nil + return MapUnknown(m.ElemType), nil } if in.IsNull() { - ma.Null = true - return ma, nil + return MapNull(m.ElemType), nil } val := map[string]tftypes.Value{} err := in.As(&val) @@ -88,8 +81,9 @@ func (m MapType) ValueFromTerraform(ctx context.Context, in tftypes.Value) (attr } elems[key] = av } - ma.Elems = elems - return ma, nil + // ValueFromTerraform above on each element should make this safe. + // Otherwise, this will need to do some Diagnostics to error conversion. + return MapValueMust(m.ElemType, elems), nil } // Equal returns true if `o` is also a MapType and has the same ElemType. @@ -171,39 +165,30 @@ func (m MapType) Validate(ctx context.Context, in tftypes.Value, path path.Path) // ValueType returns the Value type. func (t MapType) ValueType(_ context.Context) attr.Value { return Map{ - ElemType: t.ElemType, + elementType: t.ElemType, } } // MapNull creates a Map with a null value. Determine whether the value is // null via the Map type IsNull method. -// -// Setting the deprecated Map type ElemType, Elems, Null, or Unknown fields -// after creating a Map with this function has no effect. func MapNull(elementType attr.Type) Map { return Map{ elementType: elementType, - state: valueStateNull, + state: attr.ValueStateNull, } } // MapUnknown creates a Map with an unknown value. Determine whether the // value is unknown via the Map type IsUnknown method. -// -// Setting the deprecated Map type ElemType, Elems, Null, or Unknown fields -// after creating a Map with this function has no effect. func MapUnknown(elementType attr.Type) Map { return Map{ elementType: elementType, - state: valueStateUnknown, + state: attr.ValueStateUnknown, } } // MapValue creates a Map with a known value. Access the value via the Map // type Elements or ElementsAs methods. -// -// Setting the deprecated Map type ElemType, Elems, Null, or Unknown fields -// after creating a Map with this function has no effect. func MapValue(elementType attr.Type, elements map[string]attr.Value) (Map, diag.Diagnostics) { var diags diag.Diagnostics @@ -230,7 +215,7 @@ func MapValue(elementType attr.Type, elements map[string]attr.Value) (Map, diag. return Map{ elementType: elementType, elements: elements, - state: valueStateKnown, + state: attr.ValueStateKnown, }, nil } @@ -271,9 +256,6 @@ func MapValueFrom(ctx context.Context, elementType attr.Type, elements any) (Map // This creation function is only recommended to create Map values which will // not potentially effect practitioners, such as testing, or exhaustively // tested provider logic. -// -// Setting the deprecated Map type ElemType, Elems, Null, or Unknown fields -// after creating a Map with this function has no effect. func MapValueMust(elementType attr.Type, elements map[string]attr.Value) Map { m, diags := MapValue(elementType, elements) @@ -298,72 +280,20 @@ func MapValueMust(elementType attr.Type, elements map[string]attr.Value) Map { // Map represents a mapping of string keys to attr.Value values of a single // type. type Map struct { - // Unknown will be set to true if the entire map is an unknown value. - // If only some of the elements in the map are unknown, their known or - // unknown status will be represented however that attr.Value - // surfaces that information. The Map's Unknown property only tracks if - // the number of elements in a Map is known, not whether the elements - // that are in the map are known. - // - // If the Map was created with the MapValue, MapNull, or MapUnknown - // functions, changing this field has no effect. - // - // Deprecated: Use the MapUnknown function to create an unknown Map - // value or use the IsUnknown method to determine whether the Map value - // is unknown instead. - Unknown bool - - // Null will be set to true if the map is null, either because it was - // omitted from the configuration, state, or plan, or because it was - // explicitly set to null. - // - // If the Map was created with the MapValue, MapNull, or MapUnknown - // functions, changing this field has no effect. - // - // Deprecated: Use the MapNull function to create a null Map value or - // use the IsNull method to determine whether the Map value is null - // instead. - Null bool - - // Elems are the elements in the map. - // - // If the Map was created with the MapValue, MapNull, or MapUnknown - // functions, changing this field has no effect. - // - // Deprecated: Use the MapValue function to create a known Map value or - // use the Elements or ElementsAs methods to retrieve the Map elements - // instead. - Elems map[string]attr.Value - - // ElemType is the AttributeType of the elements in the map. All - // elements in the map must be of this type. - // - // Deprecated: Use the MapValue, MapNull, or MapUnknown functions - // to create a Map or use the ElementType method to retrieve the - // Map element type instead. - ElemType attr.Type - // elements is the mapping of known values in the Map. elements map[string]attr.Value // elementType is the type of the elements in the Map. elementType attr.Type - // state represents whether the Map is null, unknown, or known. During the - // exported field deprecation period, this state can also be "deprecated", - // which remains the zero-value for compatibility to ensure exported field - // updates take effect. The zero-value will be changed to null in a future - // version. - state valueState + // state represents whether the value is null, unknown, or known. The + // zero-value is null. + state attr.ValueState } // Elements returns the mapping of elements for the Map. Returns nil if the // Map is null or unknown. func (m Map) Elements() map[string]attr.Value { - if m.state == valueStateDeprecated { - return m.Elems - } - return m.elements } @@ -383,7 +313,7 @@ func (m Map) ElementsAs(ctx context.Context, target interface{}, allowUnhandled } } - return reflect.Into(ctx, MapType{ElemType: m.ElemType}, val, target, reflect.Options{ + return reflect.Into(ctx, MapType{ElemType: m.elementType}, val, target, reflect.Options{ UnhandledNullAsEmpty: allowUnhandled, UnhandledUnknownAsEmpty: allowUnhandled, }, path.Empty()) @@ -391,10 +321,6 @@ func (m Map) ElementsAs(ctx context.Context, target interface{}, allowUnhandled // ElementType returns the element type for the Map. func (m Map) ElementType(_ context.Context) attr.Type { - if m.state == valueStateDeprecated { - return m.ElemType - } - return m.elementType } @@ -405,32 +331,10 @@ func (m Map) Type(ctx context.Context) attr.Type { // ToTerraformValue returns the data contained in the List as a tftypes.Value. func (m Map) ToTerraformValue(ctx context.Context) (tftypes.Value, error) { - if m.state == valueStateDeprecated && m.ElemType == nil { - return tftypes.Value{}, fmt.Errorf("cannot convert Map to tftypes.Value if ElemType field is not set") - } mapType := tftypes.Map{ElementType: m.ElementType(ctx).TerraformType(ctx)} switch m.state { - case valueStateDeprecated: - if m.Unknown { - return tftypes.NewValue(mapType, tftypes.UnknownValue), nil - } - if m.Null { - return tftypes.NewValue(mapType, nil), nil - } - vals := make(map[string]tftypes.Value, len(m.Elems)) - for key, elem := range m.Elems { - val, err := elem.ToTerraformValue(ctx) - if err != nil { - return tftypes.NewValue(mapType, tftypes.UnknownValue), err - } - vals[key] = val - } - if err := tftypes.ValidateValue(mapType, vals); err != nil { - return tftypes.NewValue(mapType, tftypes.UnknownValue), err - } - return tftypes.NewValue(mapType, vals), nil - case valueStateKnown: + case attr.ValueStateKnown: vals := make(map[string]tftypes.Value, len(m.elements)) for key, elem := range m.elements { @@ -448,9 +352,9 @@ func (m Map) ToTerraformValue(ctx context.Context) (tftypes.Value, error) { } return tftypes.NewValue(mapType, vals), nil - case valueStateNull: + case attr.ValueStateNull: return tftypes.NewValue(mapType, nil), nil - case valueStateUnknown: + case attr.ValueStateUnknown: return tftypes.NewValue(mapType, tftypes.UnknownValue), nil default: panic(fmt.Sprintf("unhandled Map state in ToTerraformValue: %s", m.state)) @@ -461,76 +365,48 @@ func (m Map) ToTerraformValue(ctx context.Context) (tftypes.Value, error) { // (same type and same value) to the attr.Value passed as an argument. func (m Map) Equal(o attr.Value) bool { other, ok := o.(Map) + if !ok { return false } - if m.state != other.state { - return false - } - if m.state == valueStateKnown { - if !m.elementType.Equal(other.elementType) { - return false - } - - if len(m.elements) != len(other.elements) { - return false - } - - for key, mElem := range m.elements { - otherElem := other.elements[key] - - if !mElem.Equal(otherElem) { - return false - } - } - return true - } - if m.Unknown != other.Unknown { - return false - } - if m.Null != other.Null { + if !m.elementType.Equal(other.elementType) { return false } - if m.ElemType == nil && other.ElemType != nil { + + if m.state != other.state { return false } - if m.ElemType != nil && !m.ElemType.Equal(other.ElemType) { - return false + + if m.state != attr.ValueStateKnown { + return true } - if len(m.Elems) != len(other.Elems) { + + if len(m.elements) != len(other.elements) { return false } - for key, mElem := range m.Elems { - oElem, ok := other.Elems[key] - if !ok { - return false - } - if !mElem.Equal(oElem) { + + for key, mElem := range m.elements { + otherElem := other.elements[key] + + if !mElem.Equal(otherElem) { return false } } + return true } // IsNull returns true if the Map represents a null value. func (m Map) IsNull() bool { - if m.state == valueStateNull { - return true - } - - return m.state == valueStateDeprecated && m.Null + return m.state == attr.ValueStateNull } // IsUnknown returns true if the Map represents a currently unknown value. // Returns false if the Map has a known number of elements, even if all are // unknown values. func (m Map) IsUnknown() bool { - if m.state == valueStateUnknown { - return true - } - - return m.state == valueStateDeprecated && m.Unknown + return m.state == attr.ValueStateUnknown } // String returns a human-readable representation of the Map value. diff --git a/types/map_test.go b/types/map_test.go index 7920adff3..4c2df2810 100644 --- a/types/map_test.go +++ b/types/map_test.go @@ -89,14 +89,14 @@ func TestMapTypeValueFromTerraform(t *testing.T) { "two": tftypes.NewValue(tftypes.Number, 2), "three": tftypes.NewValue(tftypes.Number, 3), }), - expected: Map{ - ElemType: NumberType, - Elems: map[string]attr.Value{ - "one": Number{Value: big.NewFloat(1)}, - "two": Number{Value: big.NewFloat(2)}, - "three": Number{Value: big.NewFloat(3)}, + expected: MapValueMust( + NumberType, + map[string]attr.Value{ + "one": NumberValue(big.NewFloat(1)), + "two": NumberValue(big.NewFloat(2)), + "three": NumberValue(big.NewFloat(3)), }, - }, + ), }, "wrong-type": { receiver: MapType{ @@ -109,11 +109,8 @@ func TestMapTypeValueFromTerraform(t *testing.T) { receiver: MapType{ ElemType: NumberType, }, - input: tftypes.NewValue(nil, nil), - expected: Map{ - ElemType: NumberType, - Null: true, - }, + input: tftypes.NewValue(nil, nil), + expected: MapNull(NumberType), }, "unknown": { receiver: MapType{ @@ -122,10 +119,7 @@ func TestMapTypeValueFromTerraform(t *testing.T) { input: tftypes.NewValue(tftypes.Map{ ElementType: tftypes.Number, }, tftypes.UnknownValue), - expected: Map{ - ElemType: NumberType, - Unknown: true, - }, + expected: MapUnknown(NumberType), }, "null": { receiver: MapType{ @@ -134,10 +128,7 @@ func TestMapTypeValueFromTerraform(t *testing.T) { input: tftypes.NewValue(tftypes.Map{ ElementType: tftypes.Number, }, nil), - expected: Map{ - ElemType: NumberType, - Null: true, - }, + expected: MapNull(NumberType), }, } @@ -325,18 +316,18 @@ func TestMapValueFrom(t *testing.T) { "valid-StringType-map[string]attr.Value-empty": { elementType: StringType, elements: map[string]attr.Value{}, - expected: Map{ - ElemType: StringType, - Elems: map[string]attr.Value{}, - }, + expected: MapValueMust( + StringType, + map[string]attr.Value{}, + ), }, "valid-StringType-map[string]types.String-empty": { elementType: StringType, elements: map[string]String{}, - expected: Map{ - ElemType: StringType, - Elems: map[string]attr.Value{}, - }, + expected: MapValueMust( + StringType, + map[string]attr.Value{}, + ), }, "valid-StringType-map[string]types.String": { elementType: StringType, @@ -345,14 +336,14 @@ func TestMapValueFrom(t *testing.T) { "key2": StringUnknown(), "key3": StringValue("test"), }, - expected: Map{ - ElemType: StringType, - Elems: map[string]attr.Value{ - "key1": String{Null: true}, - "key2": String{Unknown: true}, - "key3": String{Value: "test"}, + expected: MapValueMust( + StringType, + map[string]attr.Value{ + "key1": StringNull(), + "key2": StringUnknown(), + "key3": StringValue("test"), }, - }, + ), }, "valid-StringType-map[string]*string": { elementType: StringType, @@ -361,14 +352,14 @@ func TestMapValueFrom(t *testing.T) { "key2": pointer("test1"), "key3": pointer("test2"), }, - expected: Map{ - ElemType: StringType, - Elems: map[string]attr.Value{ - "key1": String{Null: true}, - "key2": String{Value: "test1"}, - "key3": String{Value: "test2"}, + expected: MapValueMust( + StringType, + map[string]attr.Value{ + "key1": StringNull(), + "key2": StringValue("test1"), + "key3": StringValue("test2"), }, - }, + ), }, "valid-StringType-map[string]string": { elementType: StringType, @@ -376,13 +367,13 @@ func TestMapValueFrom(t *testing.T) { "key1": "test1", "key2": "test2", }, - expected: Map{ - ElemType: StringType, - Elems: map[string]attr.Value{ - "key1": String{Value: "test1"}, - "key2": String{Value: "test2"}, + expected: MapValueMust( + StringType, + map[string]attr.Value{ + "key1": StringValue("test1"), + "key2": StringValue("test2"), }, - }, + ), }, "invalid-not-map": { elementType: StringType, @@ -431,84 +422,6 @@ func TestMapValueFrom(t *testing.T) { } } -// This test verifies the assumptions that creating the Value via function then -// setting the fields directly has no effects. -func TestMapValue_DeprecatedFieldSetting(t *testing.T) { - t.Parallel() - - knownMap := MapValueMust(StringType, map[string]attr.Value{"test-key": StringValue("test-value")}) - - knownMap.Null = true - - if knownMap.IsNull() { - t.Error("unexpected null update after Null field setting") - } - - knownMap.Unknown = true - - if knownMap.IsUnknown() { - t.Error("unexpected unknown update after Unknown field setting") - } - - knownMap.Elems = map[string]attr.Value{"test-key": StringValue("not-test-value")} - - if knownMap.Elements()["test-key"].Equal(StringValue("not-test-value")) { - t.Error("unexpected value update after Value field setting") - } -} - -// This test verifies the assumptions that creating the Value via function then -// setting the fields directly has no effects. -func TestMapNull_DeprecatedFieldSetting(t *testing.T) { - t.Parallel() - - nullMap := MapNull(StringType) - - nullMap.Null = false - - if !nullMap.IsNull() { - t.Error("unexpected null update after Null field setting") - } - - nullMap.Unknown = true - - if nullMap.IsUnknown() { - t.Error("unexpected unknown update after Unknown field setting") - } - - nullMap.Elems = map[string]attr.Value{"test-key": StringValue("test")} - - if len(nullMap.Elements()) > 0 { - t.Error("unexpected value update after Value field setting") - } -} - -// This test verifies the assumptions that creating the Value via function then -// setting the fields directly has no effects. -func TestMapUnknown_DeprecatedFieldSetting(t *testing.T) { - t.Parallel() - - unknownMap := MapUnknown(StringType) - - unknownMap.Null = true - - if unknownMap.IsNull() { - t.Error("unexpected null update after Null field setting") - } - - unknownMap.Unknown = false - - if !unknownMap.IsUnknown() { - t.Error("unexpected unknown update after Unknown field setting") - } - - unknownMap.Elems = map[string]attr.Value{"test-key": StringValue("test")} - - if len(unknownMap.Elements()) > 0 { - t.Error("unexpected value update after Value field setting") - } -} - func TestMapElementsAs_mapStringString(t *testing.T) { t.Parallel() @@ -518,12 +431,13 @@ func TestMapElementsAs_mapStringString(t *testing.T) { "w": "world", } - diags := (Map{ - ElemType: StringType, - Elems: map[string]attr.Value{ - "h": String{Value: "hello"}, - "w": String{Value: "world"}, - }}).ElementsAs(context.Background(), &stringSlice, false) + diags := MapValueMust( + StringType, + map[string]attr.Value{ + "h": StringValue("hello"), + "w": StringValue("world"), + }, + ).ElementsAs(context.Background(), &stringSlice, false) if diags.HasError() { t.Errorf("Unexpected error: %v", diags) } @@ -537,16 +451,17 @@ func TestMapElementsAs_mapStringAttributeValue(t *testing.T) { var stringSlice map[string]String expected := map[string]String{ - "h": {Value: "hello"}, - "w": {Value: "world"}, + "h": StringValue("hello"), + "w": StringValue("world"), } - diags := (Map{ - ElemType: StringType, - Elems: map[string]attr.Value{ - "h": String{Value: "hello"}, - "w": String{Value: "world"}, - }}).ElementsAs(context.Background(), &stringSlice, false) + diags := MapValueMust( + StringType, + map[string]attr.Value{ + "h": StringValue("hello"), + "w": StringValue("world"), + }, + ).ElementsAs(context.Background(), &stringSlice, false) if diags.HasError() { t.Errorf("Unexpected error: %v", diags) } @@ -611,78 +526,6 @@ func TestMapToTerraformValue(t *testing.T) { input: MapNull(StringType), expectation: tftypes.NewValue(tftypes.Map{ElementType: tftypes.String}, nil), }, - "deprecated-known": { - input: Map{ - ElemType: StringType, - Elems: map[string]attr.Value{ - "key1": String{Value: "hello"}, - "key2": String{Value: "world"}, - }, - }, - expectation: tftypes.NewValue(tftypes.Map{ElementType: tftypes.String}, map[string]tftypes.Value{ - "key1": tftypes.NewValue(tftypes.String, "hello"), - "key2": tftypes.NewValue(tftypes.String, "world"), - }), - }, - "deprecated-known-duplicates": { - input: Map{ - ElemType: StringType, - Elems: map[string]attr.Value{ - "key1": String{Value: "hello"}, - "key2": String{Value: "hello"}, - }, - }, - // Duplicate validation does not occur during this method. - // This is okay, as tftypes allows duplicates. - expectation: tftypes.NewValue(tftypes.Map{ElementType: tftypes.String}, map[string]tftypes.Value{ - "key1": tftypes.NewValue(tftypes.String, "hello"), - "key2": tftypes.NewValue(tftypes.String, "hello"), - }), - }, - "deprecated-unknown": { - input: Map{ElemType: StringType, Unknown: true}, - expectation: tftypes.NewValue(tftypes.Map{ElementType: tftypes.String}, tftypes.UnknownValue), - }, - "deprecated-null": { - input: Map{ElemType: StringType, Null: true}, - expectation: tftypes.NewValue(tftypes.Map{ElementType: tftypes.String}, nil), - }, - "deprecated-known-partial-unknown": { - input: Map{ - ElemType: StringType, - Elems: map[string]attr.Value{ - "key1": String{Unknown: true}, - "key2": String{Value: "hello, world"}, - }, - }, - expectation: tftypes.NewValue(tftypes.Map{ElementType: tftypes.String}, map[string]tftypes.Value{ - "key1": tftypes.NewValue(tftypes.String, tftypes.UnknownValue), - "key2": tftypes.NewValue(tftypes.String, "hello, world"), - }), - }, - "deprecated-known-partial-null": { - input: Map{ - ElemType: StringType, - Elems: map[string]attr.Value{ - "key1": String{Null: true}, - "key2": String{Value: "hello, world"}, - }, - }, - expectation: tftypes.NewValue(tftypes.Map{ElementType: tftypes.String}, map[string]tftypes.Value{ - "key1": tftypes.NewValue(tftypes.String, nil), - "key2": tftypes.NewValue(tftypes.String, "hello, world"), - }), - }, - "no-elem-type": { - input: Map{ - Elems: map[string]attr.Value{ - "key1": String{Value: "hello"}, - "key2": String{Value: "world"}, - }, - }, - expectation: tftypes.Value{}, - expectedErr: "cannot convert Map to tftypes.Value if ElemType field is not set", - }, } for name, test := range tests { name, test := name, test @@ -726,26 +569,14 @@ func TestMapElements(t *testing.T) { input: MapValueMust(StringType, map[string]attr.Value{"test-key": StringValue("test-value")}), expected: map[string]attr.Value{"test-key": StringValue("test-value")}, }, - "deprecated-known": { - input: Map{ElemType: StringType, Elems: map[string]attr.Value{"test-key": StringValue("test-value")}}, - expected: map[string]attr.Value{"test-key": StringValue("test-value")}, - }, "null": { input: MapNull(StringType), expected: nil, }, - "deprecated-null": { - input: Map{ElemType: StringType, Null: true}, - expected: nil, - }, "unknown": { input: MapUnknown(StringType), expected: nil, }, - "deprecated-unknown": { - input: Map{ElemType: StringType, Unknown: true}, - expected: nil, - }, } for name, testCase := range testCases { @@ -774,26 +605,14 @@ func TestMapElementType(t *testing.T) { input: MapValueMust(StringType, map[string]attr.Value{"test-key": StringValue("test-value")}), expected: StringType, }, - "deprecated-known": { - input: Map{ElemType: StringType, Elems: map[string]attr.Value{"test-key": StringValue("test-value")}}, - expected: StringType, - }, "null": { input: MapNull(StringType), expected: StringType, }, - "deprecated-null": { - input: Map{ElemType: StringType, Null: true}, - expected: StringType, - }, "unknown": { input: MapUnknown(StringType), expected: StringType, }, - "deprecated-unknown": { - input: Map{ElemType: StringType, Unknown: true}, - expected: StringType, - }, } for name, testCase := range testCases { @@ -973,231 +792,6 @@ func TestMapEqual(t *testing.T) { input: nil, expected: false, }, - "known-deprecated-known": { - receiver: MapValueMust( - StringType, - map[string]attr.Value{ - "key1": StringValue("hello"), - "key2": StringValue("world"), - }, - ), - input: Map{ - ElemType: StringType, - Elems: map[string]attr.Value{ - "key1": String{Value: "hello"}, - "key2": String{Value: "world"}, - }, - }, - expected: false, // intentional - }, - "known-deprecated-unknown": { - receiver: MapValueMust( - StringType, - map[string]attr.Value{ - "key1": StringValue("hello"), - "key2": StringValue("world"), - }, - ), - input: Map{ElemType: StringType, Unknown: true}, - expected: false, - }, - "known-deprecated-null": { - receiver: MapValueMust( - StringType, - map[string]attr.Value{ - "key1": StringValue("hello"), - "key2": StringValue("world"), - }, - ), - input: Map{ElemType: StringType, Null: true}, - expected: false, - }, - "deprecated-known-deprecated-known": { - receiver: Map{ - ElemType: StringType, - Elems: map[string]attr.Value{ - "key1": String{Value: "hello"}, - "key2": String{Value: "world"}, - }, - }, - input: Map{ - ElemType: StringType, - Elems: map[string]attr.Value{ - "key1": String{Value: "hello"}, - "key2": String{Value: "world"}, - }, - }, - expected: true, - }, - "deprecated-known-deprecated-known-diff-value": { - receiver: Map{ - ElemType: StringType, - Elems: map[string]attr.Value{ - "key1": String{Value: "hello"}, - "key2": String{Value: "world"}, - }, - }, - input: Map{ - ElemType: StringType, - Elems: map[string]attr.Value{ - "key1": String{Value: "goodnight"}, - "key2": String{Value: "moon"}, - }, - }, - expected: false, - }, - "deprecated-known-deprecated-known-diff-length": { - receiver: Map{ - ElemType: StringType, - Elems: map[string]attr.Value{ - "key1": String{Value: "hello"}, - "key2": String{Value: "world"}, - }, - }, - input: Map{ - ElemType: StringType, - Elems: map[string]attr.Value{ - "key1": String{Value: "hello"}, - "key2": String{Value: "world"}, - "key3": String{Value: "test"}, - }, - }, - expected: false, - }, - "deprecated-known-deprecated-known-diff-type": { - receiver: Map{ - ElemType: StringType, - Elems: map[string]attr.Value{ - "key1": String{Value: "hello"}, - "key2": String{Value: "world"}, - }, - }, - input: Map{ - ElemType: BoolType, - Elems: map[string]attr.Value{ - "key1": Bool{Value: false}, - "key2": Bool{Value: true}, - }, - }, - expected: false, - }, - "deprecated-known-deprecated-known-diff-unknown": { - receiver: Map{ - ElemType: StringType, - Elems: map[string]attr.Value{ - "key1": String{Value: "hello"}, - "key2": String{Unknown: true}, - }, - }, - input: Map{ - ElemType: StringType, - Elems: map[string]attr.Value{ - "key1": String{Value: "hello"}, - "key2": String{Value: "world"}, - }, - }, - expected: false, - }, - "deprecated-known-deprecated-known-diff-null": { - receiver: Map{ - ElemType: StringType, - Elems: map[string]attr.Value{ - "key1": String{Value: "hello"}, - "key2": String{Null: true}, - }, - }, - input: Map{ - ElemType: StringType, - Elems: map[string]attr.Value{ - "key1": String{Value: "hello"}, - "key2": String{Value: "world"}, - }, - }, - expected: false, - }, - "deprecated-known-deprecated-unknown": { - receiver: Map{ - ElemType: StringType, - Elems: map[string]attr.Value{ - "key1": String{Value: "hello"}, - "key2": String{Value: "world"}, - }, - }, - input: Map{Unknown: true}, - expected: false, - }, - "deprecated-known-deprecated-null": { - receiver: Map{ - ElemType: StringType, - Elems: map[string]attr.Value{ - "key1": String{Value: "hello"}, - "key2": String{Value: "world"}, - }, - }, - input: Map{Null: true}, - expected: false, - }, - "deprecated-known-known": { - receiver: Map{ - ElemType: StringType, - Elems: map[string]attr.Value{ - "key1": String{Value: "hello"}, - "key2": String{Value: "world"}, - }, - }, - input: MapValueMust( - StringType, - map[string]attr.Value{ - "key1": StringValue("hello"), - "key2": StringValue("world"), - }, - ), - expected: false, // intentional - }, - "deprecated-known-unknown": { - receiver: Map{ - ElemType: StringType, - Elems: map[string]attr.Value{ - "key1": String{Value: "hello"}, - "key2": String{Value: "world"}, - }, - }, - input: MapUnknown(StringType), - expected: false, - }, - "deprecated-known-null": { - receiver: Map{ - ElemType: StringType, - Elems: map[string]attr.Value{ - "key1": String{Value: "hello"}, - "key2": String{Value: "world"}, - }, - }, - input: MapNull(StringType), - expected: false, - }, - "deprecated-known-diff-type": { - receiver: Map{ - ElemType: StringType, - Elems: map[string]attr.Value{ - "key1": String{Value: "hello"}, - "key2": String{Value: "world"}, - }, - }, - input: String{Value: "hello, world"}, - expected: false, - }, - "deprecated-known-nil": { - receiver: Map{ - ElemType: StringType, - Elems: map[string]attr.Value{ - "key1": String{Value: "hello"}, - "key2": String{Value: "world"}, - }, - }, - input: nil, - expected: false, - }, } for name, test := range tests { name, test := name, test @@ -1223,30 +817,14 @@ func TestMapIsNull(t *testing.T) { input: MapValueMust(StringType, map[string]attr.Value{"test-key": StringValue("test-value")}), expected: false, }, - "deprecated-known": { - input: Map{ElemType: StringType, Elems: map[string]attr.Value{"test-key": StringValue("test-value")}}, - expected: false, - }, "null": { input: MapNull(StringType), expected: true, }, - "deprecated-null": { - input: Map{ElemType: StringType, Null: true}, - expected: true, - }, "unknown": { input: MapUnknown(StringType), expected: false, }, - "deprecated-unknown": { - input: Map{ElemType: StringType, Unknown: true}, - expected: false, - }, - "deprecated-invalid": { - input: Map{ElemType: StringType, Null: true, Unknown: true}, - expected: true, - }, } for name, testCase := range testCases { @@ -1275,30 +853,14 @@ func TestMapIsUnknown(t *testing.T) { input: MapValueMust(StringType, map[string]attr.Value{"test-key": StringValue("test-value")}), expected: false, }, - "deprecated-known": { - input: Map{ElemType: StringType, Elems: map[string]attr.Value{"test-key": StringValue("test-value")}}, - expected: false, - }, "null": { input: MapNull(StringType), expected: false, }, - "deprecated-null": { - input: Map{ElemType: StringType, Null: true}, - expected: false, - }, "unknown": { input: MapUnknown(StringType), expected: true, }, - "deprecated-unknown": { - input: Map{ElemType: StringType, Unknown: true}, - expected: true, - }, - "deprecated-invalid": { - input: Map{ElemType: StringType, Null: true, Unknown: true}, - expected: true, - }, } for name, testCase := range testCases { @@ -1328,10 +890,10 @@ func TestMapString(t *testing.T) { input: MapValueMust( Int64Type, map[string]attr.Value{ - "alpha": Int64{Value: 1234}, - "beta": Int64{Value: 56789}, - "gamma": Int64{Value: 9817}, - "sigma": Int64{Value: 62534}, + "alpha": Int64Value(1234), + "beta": Int64Value(56789), + "gamma": Int64Value(9817), + "sigma": Int64Value(62534), }, ), expectation: `{"alpha":1234,"beta":56789,"gamma":9817,"sigma":62534}`, @@ -1345,16 +907,16 @@ func TestMapString(t *testing.T) { "first": MapValueMust( StringType, map[string]attr.Value{ - "alpha": String{Value: "hello"}, - "beta": String{Value: "world"}, - "gamma": String{Value: "foo"}, - "sigma": String{Value: "bar"}, + "alpha": StringValue("hello"), + "beta": StringValue("world"), + "gamma": StringValue("foo"), + "sigma": StringValue("bar"), }, ), "second": MapValueMust( StringType, map[string]attr.Value{ - "echo": String{Value: "echo"}, + "echo": StringValue("echo"), }, ), }, @@ -1365,7 +927,7 @@ func TestMapString(t *testing.T) { input: MapValueMust( BoolType, map[string]attr.Value{ - `testing is "fun"`: Bool{Value: true}, + `testing is "fun"`: BoolValue(true), }, ), expectation: `{"testing is \"fun\"":true}`, @@ -1378,66 +940,9 @@ func TestMapString(t *testing.T) { input: MapNull(StringType), expectation: "", }, - "deprecated-known": { - input: Map{ - ElemType: Int64Type, - Elems: map[string]attr.Value{ - "alpha": Int64{Value: 1234}, - "beta": Int64{Value: 56789}, - "gamma": Int64{Value: 9817}, - "sigma": Int64{Value: 62534}, - }, - }, - expectation: `{"alpha":1234,"beta":56789,"gamma":9817,"sigma":62534}`, - }, - "deprecated-known-map-of-maps": { - input: Map{ - ElemType: MapType{ - ElemType: StringType, - }, - Elems: map[string]attr.Value{ - "first": Map{ - ElemType: StringType, - Elems: map[string]attr.Value{ - "alpha": String{Value: "hello"}, - "beta": String{Value: "world"}, - "gamma": String{Value: "foo"}, - "sigma": String{Value: "bar"}, - }, - }, - "second": Map{ - ElemType: Int64Type, - Elems: map[string]attr.Value{ - "x": Int64{Value: 0}, - "y": Int64{Value: 0}, - "z": Int64{Value: 0}, - "t": Int64{Value: 0}, - }, - }, - }, - }, - expectation: `{"first":{"alpha":"hello","beta":"world","gamma":"foo","sigma":"bar"},"second":{"t":0,"x":0,"y":0,"z":0}}`, - }, - "deprecated-known-key-quotes": { - input: Map{ - ElemType: BoolType, - Elems: map[string]attr.Value{ - `testing is "fun"`: Bool{Value: true}, - }, - }, - expectation: `{"testing is \"fun\"":true}`, - }, - "deprecated-unknown": { - input: Map{Unknown: true}, - expectation: "", - }, - "deprecated-null": { - input: Map{Null: true}, - expectation: "", - }, - "default-empty": { + "zero-value": { input: Map{}, - expectation: "{}", + expectation: "", }, } @@ -1508,52 +1013,6 @@ func TestMapType(t *testing.T) { input: MapNull(StringType), expectation: MapType{ElemType: StringType}, }, - "deprecated-known": { - input: Map{ - ElemType: StringType, - Elems: map[string]attr.Value{ - "key1": String{Value: "hello"}, - "key2": String{Value: "world"}, - }, - }, - expectation: MapType{ElemType: StringType}, - }, - "deprecated-known-list-of-lists": { - input: Map{ - ElemType: MapType{ - ElemType: StringType, - }, - Elems: map[string]attr.Value{ - "key1": Map{ - ElemType: StringType, - Elems: map[string]attr.Value{ - "key1": String{Value: "hello"}, - "key2": String{Value: "world"}, - }, - }, - "key2": Map{ - ElemType: StringType, - Elems: map[string]attr.Value{ - "key1": String{Value: "foo"}, - "key2": String{Value: "bar"}, - }, - }, - }, - }, - expectation: MapType{ - ElemType: MapType{ - ElemType: StringType, - }, - }, - }, - "deprecated-unknown": { - input: Map{ElemType: StringType, Unknown: true}, - expectation: MapType{ElemType: StringType}, - }, - "deprecated-null": { - input: Map{ElemType: StringType, Null: true}, - expectation: MapType{ElemType: StringType}, - }, } for name, test := range tests { diff --git a/types/number.go b/types/number.go index 4e75fa1f9..bac347d15 100644 --- a/types/number.go +++ b/types/number.go @@ -20,7 +20,7 @@ var ( // creating a Number with this function has no effect. func NumberNull() Number { return Number{ - state: valueStateNull, + state: attr.ValueStateNull, } } @@ -31,7 +31,7 @@ func NumberNull() Number { // creating a Number with this function has no effect. func NumberUnknown() Number { return Number{ - state: valueStateUnknown, + state: attr.ValueStateUnknown, } } @@ -46,75 +46,32 @@ func NumberValue(value *big.Float) Number { } return Number{ - state: valueStateKnown, + state: attr.ValueStateKnown, value: value, } } func numberValueFromTerraform(ctx context.Context, in tftypes.Value) (attr.Value, error) { if !in.IsKnown() { - return Number{ - Unknown: true, - state: valueStateDeprecated, - }, nil + return NumberUnknown(), nil } if in.IsNull() { - return Number{ - Null: true, - state: valueStateDeprecated, - }, nil + return NumberNull(), nil } n := big.NewFloat(0) err := in.As(&n) if err != nil { return nil, err } - return Number{ - Value: n, - state: valueStateDeprecated, - }, nil + return NumberValue(n), nil } // Number represents a number value, exposed as a *big.Float. Numbers can be // floats or integers. type Number struct { - // Unknown will be true if the value is not yet known. - // - // If the Number was created with the NumberValue, NumberNull, or NumberUnknown - // functions, changing this field has no effect. - // - // Deprecated: Use the NumberUnknown function to create an unknown Number - // value or use the IsUnknown method to determine whether the Number value - // is unknown instead. - Unknown bool - - // Null will be true if the value was not set, or was explicitly set to - // null. - // - // If the Number was created with the NumberValue, NumberNull, or NumberUnknown - // functions, changing this field has no effect. - // - // Deprecated: Use the NumberNull function to create a null Number value or - // use the IsNull method to determine whether the Number value is null - // instead. - Null bool - - // Value contains the set value, as long as Unknown and Null are both - // false. - // - // If the Number was created with the NumberValue, NumberNull, or NumberUnknown - // functions, changing this field has no effect. - // - // Deprecated: Use the NumberValue function to create a known Number value or - // use the ValueBigFloat method to retrieve the Number value instead. - Value *big.Float - - // state represents whether the Number is null, unknown, or known. During the - // exported field deprecation period, this state can also be "deprecated", - // which remains the zero-value for compatibility to ensure exported field - // updates take effect. The zero-value will be changed to null in a future - // version. - state valueState + // state represents whether the value is null, unknown, or known. The + // zero-value is null. + state attr.ValueState // value contains the known value, if not null or unknown. value *big.Float @@ -128,21 +85,7 @@ func (n Number) Type(_ context.Context) attr.Type { // ToTerraformValue returns the data contained in the Number as a tftypes.Value. func (n Number) ToTerraformValue(_ context.Context) (tftypes.Value, error) { switch n.state { - case valueStateDeprecated: - if n.Null { - return tftypes.NewValue(tftypes.Number, nil), nil - } - if n.Unknown { - return tftypes.NewValue(tftypes.Number, tftypes.UnknownValue), nil - } - if n.Value == nil { - return tftypes.NewValue(tftypes.Number, nil), nil - } - if err := tftypes.ValidateValue(tftypes.Number, n.Value); err != nil { - return tftypes.NewValue(tftypes.Number, tftypes.UnknownValue), err - } - return tftypes.NewValue(tftypes.Number, n.Value), nil - case valueStateKnown: + case attr.ValueStateKnown: if n.value == nil { return tftypes.NewValue(tftypes.Number, nil), nil } @@ -152,9 +95,9 @@ func (n Number) ToTerraformValue(_ context.Context) (tftypes.Value, error) { } return tftypes.NewValue(tftypes.Number, n.value), nil - case valueStateNull: + case attr.ValueStateNull: return tftypes.NewValue(tftypes.Number, nil), nil - case valueStateUnknown: + case attr.ValueStateUnknown: return tftypes.NewValue(tftypes.Number, tftypes.UnknownValue), nil default: panic(fmt.Sprintf("unhandled Number state in ToTerraformValue: %s", n.state)) @@ -164,50 +107,30 @@ func (n Number) ToTerraformValue(_ context.Context) (tftypes.Value, error) { // Equal returns true if `other` is a Number and has the same value as `n`. func (n Number) Equal(other attr.Value) bool { o, ok := other.(Number) + if !ok { return false } + if n.state != o.state { return false } - if n.state == valueStateKnown { - return n.value.Cmp(o.value) == 0 - } - if n.Unknown != o.Unknown { - return false - } - if n.Null != o.Null { - return false - } - if n.Value == nil && o.Value == nil { + + if n.state != attr.ValueStateKnown { return true } - if n.Value == nil || o.Value == nil { - return false - } - return n.Value.Cmp(o.Value) == 0 + + return n.value.Cmp(o.value) == 0 } // IsNull returns true if the Number represents a null value. func (n Number) IsNull() bool { - if n.state == valueStateNull { - return true - } - - if n.state == valueStateDeprecated && n.Null { - return true - } - - return n.state == valueStateDeprecated && (!n.Unknown && n.Value == nil) + return n.state == attr.ValueStateNull } // IsUnknown returns true if the Number represents a currently unknown value. func (n Number) IsUnknown() bool { - if n.state == valueStateUnknown { - return true - } - - return n.state == valueStateDeprecated && n.Unknown + return n.state == attr.ValueStateUnknown } // String returns a human-readable representation of the Number value. @@ -222,19 +145,11 @@ func (n Number) String() string { return attr.NullValueString } - if n.state == valueStateKnown { - return n.value.String() - } - - return n.Value.String() + return n.value.String() } // ValueBigFloat returns the known *big.Float value. If Number is null or unknown, returns // 0.0. func (n Number) ValueBigFloat() *big.Float { - if n.state == valueStateDeprecated { - return n.Value - } - return n.value } diff --git a/types/number_test.go b/types/number_test.go index eb88ef4aa..6207f9d4c 100644 --- a/types/number_test.go +++ b/types/number_test.go @@ -15,84 +15,6 @@ func numberComparer(i, j *big.Float) bool { return (i == nil && j == nil) || (i != nil && j != nil && i.Cmp(j) == 0) } -// This test verifies the assumptions that creating the Value via function then -// setting the fields directly has no effects. -func TestNumberValueDeprecatedFieldSetting(t *testing.T) { - t.Parallel() - - knownNumber := NumberValue(big.NewFloat(2.4)) - - knownNumber.Null = true - - if knownNumber.IsNull() { - t.Error("unexpected null update after Null field setting") - } - - knownNumber.Unknown = true - - if knownNumber.IsUnknown() { - t.Error("unexpected unknown update after Unknown field setting") - } - - knownNumber.Value = big.NewFloat(4.8) - - if knownNumber.ValueBigFloat().Cmp(big.NewFloat(4.8)) == 0 { - t.Error("unexpected value update after Value field setting") - } -} - -// This test verifies the assumptions that creating the Value via function then -// setting the fields directly has no effects. -func TestNumberNullDeprecatedFieldSetting(t *testing.T) { - t.Parallel() - - nullNumber := NumberNull() - - nullNumber.Null = false - - if !nullNumber.IsNull() { - t.Error("unexpected null update after Null field setting") - } - - nullNumber.Unknown = true - - if nullNumber.IsUnknown() { - t.Error("unexpected unknown update after Unknown field setting") - } - - nullNumber.Value = big.NewFloat(4.8) - - if nullNumber.ValueBigFloat() != nil { - t.Error("unexpected value update after Value field setting") - } -} - -// This test verifies the assumptions that creating the Value via function then -// setting the fields directly has no effects. -func TestNumberUnknownDeprecatedFieldSetting(t *testing.T) { - t.Parallel() - - unknownNumber := NumberUnknown() - - unknownNumber.Null = true - - if unknownNumber.IsNull() { - t.Error("unexpected null update after Null field setting") - } - - unknownNumber.Unknown = false - - if !unknownNumber.IsUnknown() { - t.Error("unexpected unknown update after Unknown field setting") - } - - unknownNumber.Value = big.NewFloat(4.8) - - if unknownNumber.ValueBigFloat() != nil { - t.Error("unexpected value update after Value field setting") - } -} - func TestNumberValueFromTerraform(t *testing.T) { t.Parallel() @@ -108,15 +30,15 @@ func testNumberValueFromTerraform(t *testing.T, direct bool) { tests := map[string]testCase{ "value": { input: tftypes.NewValue(tftypes.Number, 123), - expectation: Number{Value: big.NewFloat(123)}, + expectation: NumberValue(big.NewFloat(123)), }, "unknown": { input: tftypes.NewValue(tftypes.Number, tftypes.UnknownValue), - expectation: Number{Unknown: true}, + expectation: NumberUnknown(), }, "null": { input: tftypes.NewValue(tftypes.Number, nil), - expectation: Number{Null: true}, + expectation: NumberNull(), }, "wrongType": { input: tftypes.NewValue(tftypes.String, "oops"), @@ -188,22 +110,6 @@ func TestNumberToTerraformValue(t *testing.T) { input: NumberNull(), expectation: tftypes.NewValue(tftypes.Number, nil), }, - "deprecated-value": { - input: Number{Value: big.NewFloat(123)}, - expectation: tftypes.NewValue(tftypes.Number, big.NewFloat(123)), - }, - "deprecated-known-nil": { - input: Number{Value: nil}, - expectation: tftypes.NewValue(tftypes.Number, nil), - }, - "deprecated-unknown": { - input: Number{Unknown: true}, - expectation: tftypes.NewValue(tftypes.Number, tftypes.UnknownValue), - }, - "deprecated-null": { - input: Number{Null: true}, - expectation: tftypes.NewValue(tftypes.Number, nil), - }, } for name, test := range tests { name, test := name, test @@ -327,151 +233,6 @@ func TestNumberEqual(t *testing.T) { candidate: nil, expectation: false, }, - "deprecated-known-known-same": { - input: Number{Value: big.NewFloat(123)}, - candidate: NumberValue(big.NewFloat(123)), - expectation: false, // intentional - }, - "deprecated-known-known-diff": { - input: Number{Value: big.NewFloat(123)}, - candidate: NumberValue(big.NewFloat(456)), - expectation: false, - }, - "deprecated-known-unknown": { - input: Number{Value: big.NewFloat(123)}, - candidate: NumberNull(), - expectation: false, - }, - "deprecated-known-null": { - input: Number{Value: big.NewFloat(123)}, - candidate: NumberNull(), - expectation: false, - }, - "deprecated-known-deprecated-known-same": { - input: Number{Value: big.NewFloat(123)}, - candidate: Number{Value: big.NewFloat(123)}, - expectation: true, - }, - "deprecated-known-deprecated-known-diff": { - input: Number{Value: big.NewFloat(123)}, - candidate: Number{Value: big.NewFloat(456)}, - expectation: false, - }, - "deprecated-known-deprecated-unknown": { - input: Number{Value: big.NewFloat(123)}, - candidate: Number{Unknown: true}, - expectation: false, - }, - "deprecated-known-deprecated-null": { - input: Number{Value: big.NewFloat(123)}, - candidate: Number{Null: true}, - expectation: false, - }, - "deprecated-known-wrongType": { - input: Number{Value: big.NewFloat(123)}, - candidate: &String{Value: "oops"}, - expectation: false, - }, - "deprecated-known-nil": { - input: Number{Value: big.NewFloat(123)}, - candidate: nil, - expectation: false, - }, - "deprecated-known-nilValue": { - input: Number{Value: big.NewFloat(123)}, - candidate: Number{Value: nil}, - expectation: false, - }, - "deprecated-unknown-known": { - input: Number{Unknown: true}, - candidate: NumberValue(big.NewFloat(123)), - expectation: false, - }, - "deprecated-unknown-unknown": { - input: Number{Unknown: true}, - candidate: NumberUnknown(), - expectation: false, // intentional - }, - "deprecated-unknown-null": { - input: Number{Unknown: true}, - candidate: NumberNull(), - expectation: false, - }, - "deprecated-unknown-deprecated-known": { - input: Number{Unknown: true}, - candidate: Number{Value: big.NewFloat(123)}, - expectation: false, - }, - "deprecated-unknown-deprecated-unknown": { - input: Number{Unknown: true}, - candidate: Number{Unknown: true}, - expectation: true, - }, - "deprecated-unknown-deprecated-null": { - input: Number{Unknown: true}, - candidate: Number{Null: true}, - expectation: false, - }, - "deprecated-unknown-wrongType": { - input: Number{Unknown: true}, - candidate: &String{Value: "oops"}, - expectation: false, - }, - "deprecated-unknown-nil": { - input: Number{Unknown: true}, - candidate: nil, - expectation: false, - }, - "deprecated-unknown-nilValue": { - input: Number{Unknown: true}, - candidate: Number{Value: nil}, - expectation: false, - }, - "deprecated-null-value": { - input: Number{Null: true}, - candidate: NumberValue(big.NewFloat(123)), - expectation: false, - }, - "deprecated-null-unknown": { - input: Number{Null: true}, - candidate: NumberUnknown(), - expectation: false, - }, - "deprecated-null-null": { - input: Number{Null: true}, - candidate: NumberNull(), - expectation: false, // intentional - }, - "deprecated-null-deprecated-value": { - input: Number{Null: true}, - candidate: Number{Value: big.NewFloat(123)}, - expectation: false, - }, - "deprecated-null-deprecated-unknown": { - input: Number{Null: true}, - candidate: Number{Unknown: true}, - expectation: false, - }, - "deprecated-null-deprecated-null": { - input: Number{Null: true}, - candidate: Number{Null: true}, - expectation: true, - }, - "deprecated-null-wrongType": { - input: Number{Null: true}, - candidate: &String{Value: "oops"}, - expectation: false, - }, - "deprecated-null-nil": { - input: Number{Null: true}, - candidate: nil, - expectation: false, - }, - "deprecated-null-nilValue": { - input: Number{Null: true}, - candidate: Number{Value: nil}, - expectation: false, - }, } for name, test := range tests { name, test := name, test @@ -497,30 +258,14 @@ func TestNumberIsNull(t *testing.T) { input: NumberValue(big.NewFloat(2.4)), expected: false, }, - "deprecated-known": { - input: Number{Value: big.NewFloat(2.4)}, - expected: false, - }, "null": { input: NumberNull(), expected: true, }, - "deprecated-null": { - input: Number{Null: true}, - expected: true, - }, "unknown": { input: NumberUnknown(), expected: false, }, - "deprecated-unknown": { - input: Number{Unknown: true}, - expected: false, - }, - "deprecated-invalid": { - input: Number{Null: true, Unknown: true}, - expected: true, - }, } for name, testCase := range testCases { @@ -549,30 +294,14 @@ func TestNumberIsUnknown(t *testing.T) { input: NumberValue(big.NewFloat(2.4)), expected: false, }, - "deprecated-known": { - input: Number{Value: big.NewFloat(2.4)}, - expected: false, - }, "null": { input: NumberNull(), expected: false, }, - "deprecated-null": { - input: Number{Null: true}, - expected: false, - }, "unknown": { input: NumberUnknown(), expected: true, }, - "deprecated-unknown": { - input: Number{Unknown: true}, - expected: true, - }, - "deprecated-invalid": { - input: Number{Null: true, Unknown: true}, - expected: true, - }, } for name, testCase := range testCases { @@ -630,42 +359,6 @@ func TestNumberString(t *testing.T) { input: NumberNull(), expectation: "", }, - "deprecated-known-less-than-one": { - input: Number{Value: big.NewFloat(0.12340984302980000)}, - expectation: "0.123409843", - }, - "deprecated-known-more-than-one": { - input: Number{Value: big.NewFloat(92387938173219.327663)}, - expectation: "9.238793817e+13", - }, - "deprecated-known-negative-more-than-one": { - input: Number{Value: big.NewFloat(-0.12340984302980000)}, - expectation: "-0.123409843", - }, - "deprecated-known-negative-less-than-one": { - input: Number{Value: big.NewFloat(-92387938173219.327663)}, - expectation: "-9.238793817e+13", - }, - "deprecated-known-min-float64": { - input: Number{Value: big.NewFloat(math.SmallestNonzeroFloat64)}, - expectation: "4.940656458e-324", - }, - "deprecated-known-max-float64": { - input: Number{Value: big.NewFloat(math.MaxFloat64)}, - expectation: "1.797693135e+308", - }, - "deprecated-unknown": { - input: Number{Unknown: true}, - expectation: "", - }, - "deprecated-null": { - input: Number{Null: true}, - expectation: "", - }, - "default-null": { - input: Number{}, - expectation: "", - }, } for name, test := range tests { @@ -696,30 +389,14 @@ func TestNumberValueBigFloat(t *testing.T) { input: NumberValue(nil), expected: nil, }, - "deprecated-known": { - input: Number{Value: big.NewFloat(2.4)}, - expected: big.NewFloat(2.4), - }, "null": { input: NumberNull(), expected: nil, }, - "deprecated-null": { - input: Number{Null: true}, - expected: nil, - }, "unknown": { input: NumberUnknown(), expected: nil, }, - "deprecated-unknown": { - input: Number{Unknown: true}, - expected: nil, - }, - "deprecated-invalid": { - input: Number{Null: true, Unknown: true}, - expected: nil, - }, } for name, testCase := range testCases { diff --git a/types/object.go b/types/object.go index 65f929714..f834be36b 100644 --- a/types/object.go +++ b/types/object.go @@ -56,23 +56,17 @@ func (o ObjectType) TerraformType(ctx context.Context) tftypes.Type { // This is meant to convert the tftypes.Value into a more convenient Go // type for the provider to consume the data with. func (o ObjectType) ValueFromTerraform(ctx context.Context, in tftypes.Value) (attr.Value, error) { - object := Object{ - AttrTypes: o.AttrTypes, - } if in.Type() == nil { - object.Null = true - return object, nil + return ObjectNull(o.AttrTypes), nil } if !in.Type().Equal(o.TerraformType(ctx)) { return nil, fmt.Errorf("expected %s, got %s", o.TerraformType(ctx), in.Type()) } if !in.IsKnown() { - object.Unknown = true - return object, nil + return ObjectUnknown(o.AttrTypes), nil } if in.IsNull() { - object.Null = true - return object, nil + return ObjectNull(o.AttrTypes), nil } attributes := map[string]attr.Value{} @@ -83,14 +77,15 @@ func (o ObjectType) ValueFromTerraform(ctx context.Context, in tftypes.Value) (a } for k, v := range val { - a, err := object.AttrTypes[k].ValueFromTerraform(ctx, v) + a, err := o.AttrTypes[k].ValueFromTerraform(ctx, v) if err != nil { return nil, err } attributes[k] = a } - object.Attrs = attributes - return object, nil + // ValueFromTerraform above on each attribute should make this safe. + // Otherwise, this will need to do some Diagnostics to error conversion. + return ObjectValueMust(o.AttrTypes, attributes), nil } // Equal returns true if `candidate` is also an ObjectType and has the same @@ -148,39 +143,30 @@ func (o ObjectType) String() string { // ValueType returns the Value type. func (t ObjectType) ValueType(_ context.Context) attr.Value { return Object{ - AttrTypes: t.AttrTypes, + attributeTypes: t.AttrTypes, } } // ObjectNull creates a Object with a null value. Determine whether the value is // null via the Object type IsNull method. -// -// Setting the deprecated Object type AttrTypes, Attrs, Null, or Unknown fields -// after creating a Object with this function has no effect. func ObjectNull(attributeTypes map[string]attr.Type) Object { return Object{ attributeTypes: attributeTypes, - state: valueStateNull, + state: attr.ValueStateNull, } } // ObjectUnknown creates a Object with an unknown value. Determine whether the // value is unknown via the Object type IsUnknown method. -// -// Setting the deprecated Object type AttrTypes, Attrs, Null, or Unknown fields -// after creating a Object with this function has no effect. func ObjectUnknown(attributeTypes map[string]attr.Type) Object { return Object{ attributeTypes: attributeTypes, - state: valueStateUnknown, + state: attr.ValueStateUnknown, } } // ObjectValue creates a Object with a known value. Access the value via the Object // type ElementsAs method. -// -// Setting the deprecated Object type AttrTypes, Attrs, Null, or Unknown fields -// after creating a Object with this function has no effect. func ObjectValue(attributeTypes map[string]attr.Type, attributes map[string]attr.Value) (Object, diag.Diagnostics) { var diags diag.Diagnostics @@ -235,7 +221,7 @@ func ObjectValue(attributeTypes map[string]attr.Type, attributes map[string]attr return Object{ attributeTypes: attributeTypes, attributes: attributes, - state: valueStateKnown, + state: attr.ValueStateKnown, }, nil } @@ -276,9 +262,6 @@ func ObjectValueFrom(ctx context.Context, attributeTypes map[string]attr.Type, a // This creation function is only recommended to create Object values which will // not potentially effect practitioners, such as testing, or exhaustively // tested provider logic. -// -// Objectting the deprecated Object type ElemType, Elems, Null, or Unknown fields -// after creating a Object with this function has no effect. func ObjectValueMust(attributeTypes map[string]attr.Type, attributes map[string]attr.Value) Object { object, diags := ObjectValue(attributeTypes, attributes) @@ -302,63 +285,15 @@ func ObjectValueMust(attributeTypes map[string]attr.Type, attributes map[string] // Object represents an object type Object struct { - // Unknown will be set to true if the entire object is an unknown value. - // If only some of the elements in the object are unknown, their known or - // unknown status will be represented however that attr.Value - // surfaces that information. The Object's Unknown property only tracks - // if the number of elements in a Object is known, not whether the - // elements that are in the object are known. - // - // If the Object was created with the ObjectValue, ObjectNull, or ObjectUnknown - // functions, changing this field has no effect. - // - // Deprecated: Use the ObjectNull function to create a null Object value or - // use the IsNull method to determine whether the Object value is null - // instead. - Unknown bool - - // Null will be set to true if the object is null, either because it was - // omitted from the configuration, state, or plan, or because it was - // explicitly set to null. - // - // If the Object was created with the ObjectValue, ObjectNull, or ObjectUnknown - // functions, changing this field has no effect. - // - // Deprecated: Use the ObjectNull function to create a null Object value or - // use the IsNull method to determine whether the Object value is null - // instead. - Null bool - - // Attrs is the mapping of known attribute values in the Object. - // - // If the Object was created with the ObjectValue, ObjectNull, or ObjectUnknown - // functions, changing this field has no effect. - // - // Deprecated: Use the ObjectValue function to create a known Object value or - // use the As or Attributes methods to retrieve the Object attributes - // instead. - Attrs map[string]attr.Value - - // AttrTypes is the mapping of attribute types in the Object. Required - // for a valid Object. - // - // Deprecated: Use the ObjectValue, ObjectNull, or ObjectUnknown functions - // to create a Object or use the AttributeTypes method to retrieve the - // Object attribute types instead. - AttrTypes map[string]attr.Type - // attributes is the mapping of known attribute values in the Object. attributes map[string]attr.Value // attributeTypes is the type of the attributes in the Object. attributeTypes map[string]attr.Type - // state represents whether the Object is null, unknown, or known. During the - // exported field deprecation period, this state can also be "deprecated", - // which remains the zero-value for compatibility to ensure exported field - // updates take effect. The zero-value will be changed to null in a future - // version. - state valueState + // state represents whether the value is null, unknown, or known. The + // zero-value is null. + state attr.ValueState } // ObjectAsOptions is a collection of toggles to control the behavior of @@ -382,7 +317,7 @@ type ObjectAsOptions struct { func (o Object) As(ctx context.Context, target interface{}, opts ObjectAsOptions) diag.Diagnostics { // we need a tftypes.Value for this Object to be able to use it with // our reflection code - obj := ObjectType{AttrTypes: o.AttrTypes} + obj := ObjectType{AttrTypes: o.attributeTypes} val, err := o.ToTerraformValue(ctx) if err != nil { return diag.Diagnostics{ @@ -401,19 +336,11 @@ func (o Object) As(ctx context.Context, target interface{}, opts ObjectAsOptions // Attributes returns the mapping of known attribute values for the Object. // Returns nil if the Object is null or unknown. func (o Object) Attributes() map[string]attr.Value { - if o.state == valueStateDeprecated { - return o.Attrs - } - return o.attributes } // AttributeTypes returns the mapping of attribute types for the Object. func (o Object) AttributeTypes(_ context.Context) map[string]attr.Type { - if o.state == valueStateDeprecated { - return o.AttrTypes - } - return o.attributeTypes } @@ -425,9 +352,6 @@ func (o Object) Type(ctx context.Context) attr.Type { // ToTerraformValue returns the data contained in the attr.Value as // a tftypes.Value. func (o Object) ToTerraformValue(ctx context.Context) (tftypes.Value, error) { - if o.state == valueStateDeprecated && o.AttrTypes == nil { - return tftypes.Value{}, fmt.Errorf("cannot convert Object to tftypes.Value if AttrTypes field is not set") - } attrTypes := map[string]tftypes.Type{} for attr, typ := range o.AttributeTypes(ctx) { attrTypes[attr] = typ.TerraformType(ctx) @@ -435,27 +359,7 @@ func (o Object) ToTerraformValue(ctx context.Context) (tftypes.Value, error) { objectType := tftypes.Object{AttributeTypes: attrTypes} switch o.state { - case valueStateDeprecated: - if o.Unknown { - return tftypes.NewValue(objectType, tftypes.UnknownValue), nil - } - if o.Null { - return tftypes.NewValue(objectType, nil), nil - } - vals := map[string]tftypes.Value{} - - for k, v := range o.Attrs { - val, err := v.ToTerraformValue(ctx) - if err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - vals[k] = val - } - if err := tftypes.ValidateValue(objectType, vals); err != nil { - return tftypes.NewValue(objectType, tftypes.UnknownValue), err - } - return tftypes.NewValue(objectType, vals), nil - case valueStateKnown: + case attr.ValueStateKnown: vals := make(map[string]tftypes.Value, len(o.attributes)) for name, v := range o.attributes { @@ -473,9 +377,9 @@ func (o Object) ToTerraformValue(ctx context.Context) (tftypes.Value, error) { } return tftypes.NewValue(objectType, vals), nil - case valueStateNull: + case attr.ValueStateNull: return tftypes.NewValue(objectType, nil), nil - case valueStateUnknown: + case attr.ValueStateUnknown: return tftypes.NewValue(objectType, tftypes.UnknownValue), nil default: panic(fmt.Sprintf("unhandled Object state in ToTerraformValue: %s", o.state)) @@ -486,74 +390,47 @@ func (o Object) ToTerraformValue(ctx context.Context) (tftypes.Value, error) { // (same type and same value) to the attr.Value passed as an argument. func (o Object) Equal(c attr.Value) bool { other, ok := c.(Object) + if !ok { return false } + if o.state != other.state { return false } - if o.state == valueStateKnown { - if len(o.attributeTypes) != len(other.attributeTypes) { - return false - } - - for name, oAttributeType := range o.attributeTypes { - otherAttributeType, ok := other.attributeTypes[name] - - if !ok { - return false - } - - if !oAttributeType.Equal(otherAttributeType) { - return false - } - } - - if len(o.attributes) != len(other.attributes) { - return false - } - - for name, oAttribute := range o.attributes { - otherAttribute, ok := other.attributes[name] - - if !ok { - return false - } - - if !oAttribute.Equal(otherAttribute) { - return false - } - } + if o.state != attr.ValueStateKnown { return true } - if o.Unknown != other.Unknown { - return false - } - if o.Null != other.Null { - return false - } - if len(o.AttrTypes) != len(other.AttrTypes) { + + if len(o.attributeTypes) != len(other.attributeTypes) { return false } - for k, v := range o.AttrTypes { - attr, ok := other.AttrTypes[k] + + for name, oAttributeType := range o.attributeTypes { + otherAttributeType, ok := other.attributeTypes[name] + if !ok { return false } - if !v.Equal(attr) { + + if !oAttributeType.Equal(otherAttributeType) { return false } } - if len(o.Attrs) != len(other.Attrs) { + + if len(o.attributes) != len(other.attributes) { return false } - for k, v := range o.Attrs { - attr, ok := other.Attrs[k] + + for name, oAttribute := range o.attributes { + otherAttribute, ok := other.attributes[name] + if !ok { return false } - if !v.Equal(attr) { + + if !oAttribute.Equal(otherAttribute) { return false } } @@ -563,20 +440,12 @@ func (o Object) Equal(c attr.Value) bool { // IsNull returns true if the Object represents a null value. func (o Object) IsNull() bool { - if o.state == valueStateNull { - return true - } - - return o.state == valueStateDeprecated && o.Null + return o.state == attr.ValueStateNull } // IsUnknown returns true if the Object represents a currently unknown value. func (o Object) IsUnknown() bool { - if o.state == valueStateUnknown { - return true - } - - return o.state == valueStateDeprecated && o.Unknown + return o.state == attr.ValueStateUnknown } // String returns a human-readable representation of the Object value. diff --git a/types/object_test.go b/types/object_test.go index 466bca9ff..7cbc69996 100644 --- a/types/object_test.go +++ b/types/object_test.go @@ -71,18 +71,18 @@ func TestObjectTypeValueFromTerraform(t *testing.T) { "b": tftypes.NewValue(tftypes.Bool, true), "c": tftypes.NewValue(tftypes.Number, 123), }), - expected: Object{ - Attrs: map[string]attr.Value{ - "a": String{Value: "red"}, - "b": Bool{Value: true}, - "c": Number{Value: big.NewFloat(123)}, - }, - AttrTypes: map[string]attr.Type{ + expected: ObjectValueMust( + map[string]attr.Type{ "a": StringType, "b": BoolType, "c": NumberType, }, - }, + map[string]attr.Value{ + "a": StringValue("red"), + "b": BoolValue(true), + "c": NumberValue(big.NewFloat(123)), + }, + ), }, "extra-attribute": { receiver: ObjectType{ @@ -133,12 +133,11 @@ func TestObjectTypeValueFromTerraform(t *testing.T) { }, }, input: tftypes.NewValue(nil, nil), - expected: Object{ - AttrTypes: map[string]attr.Type{ + expected: ObjectNull( + map[string]attr.Type{ "a": StringType, }, - Null: true, - }, + ), }, "unknown": { receiver: ObjectType{ @@ -151,12 +150,11 @@ func TestObjectTypeValueFromTerraform(t *testing.T) { "a": tftypes.String, }, }, tftypes.UnknownValue), - expected: Object{ - AttrTypes: map[string]attr.Type{ + expected: ObjectUnknown( + map[string]attr.Type{ "a": StringType, }, - Unknown: true, - }, + ), }, "null": { receiver: ObjectType{ @@ -169,12 +167,11 @@ func TestObjectTypeValueFromTerraform(t *testing.T) { "a": tftypes.String, }, }, nil), - expected: Object{ - AttrTypes: map[string]attr.Type{ + expected: ObjectNull( + map[string]attr.Type{ "a": StringType, }, - Null: true, - }, + ), }, } @@ -516,16 +513,16 @@ func TestObjectValueFrom(t *testing.T) { Bool: BoolValue(true), String: StringValue("test"), }), - expected: Object{ - AttrTypes: map[string]attr.Type{ + expected: ObjectValueMust( + map[string]attr.Type{ "bool": BoolType, "string": StringType, }, - Attrs: map[string]attr.Value{ - "bool": Bool{Value: true}, - "string": String{Value: "test"}, + map[string]attr.Value{ + "bool": BoolValue(true), + "string": StringValue("test"), }, - }, + ), }, "valid-struct": { attributeTypes: map[string]attr.Type{ @@ -539,16 +536,16 @@ func TestObjectValueFrom(t *testing.T) { Bool: BoolValue(true), String: StringValue("test"), }, - expected: Object{ - AttrTypes: map[string]attr.Type{ + expected: ObjectValueMust( + map[string]attr.Type{ "bool": BoolType, "string": StringType, }, - Attrs: map[string]attr.Value{ - "bool": Bool{Value: true}, - "string": String{Value: "test"}, + map[string]attr.Value{ + "bool": BoolValue(true), + "string": StringValue("test"), }, - }, + ), }, "invalid-nil": { attributeTypes: map[string]attr.Type{ @@ -658,87 +655,6 @@ func TestObjectValueFrom(t *testing.T) { } } -// This test verifies the assumptions that creating the Value via function then -// setting the fields directly has no effects. -func TestObjectValue_DeprecatedFieldSetting(t *testing.T) { - t.Parallel() - - knownObject := ObjectValueMust( - map[string]attr.Type{"test_attr": StringType}, - map[string]attr.Value{"test_attr": StringValue("test-value")}, - ) - - knownObject.Null = true - - if knownObject.IsNull() { - t.Error("unexpected null update after Null field setting") - } - - knownObject.Unknown = true - - if knownObject.IsUnknown() { - t.Error("unexpected unknown update after Unknown field setting") - } - - knownObject.Attrs = map[string]attr.Value{"test_attr": StringValue("not-test-value")} - - if knownObject.Attributes()["test_attr"].Equal(StringValue("not-test-value")) { - t.Error("unexpected value update after Value field setting") - } -} - -// This test verifies the assumptions that creating the Value via function then -// setting the fields directly has no effects. -func TestObjectNull_DeprecatedFieldSetting(t *testing.T) { - t.Parallel() - - nullObject := ObjectNull(map[string]attr.Type{"test_attr": StringType}) - - nullObject.Null = false - - if !nullObject.IsNull() { - t.Error("unexpected null update after Null field setting") - } - - nullObject.Unknown = true - - if nullObject.IsUnknown() { - t.Error("unexpected unknown update after Unknown field setting") - } - - nullObject.Attrs = map[string]attr.Value{"test_attr": StringValue("test")} - - if len(nullObject.Attributes()) > 0 { - t.Error("unexpected value update after Value field setting") - } -} - -// This test verifies the assumptions that creating the Value via function then -// setting the fields directly has no effects. -func TestObjectUnknown_DeprecatedFieldSetting(t *testing.T) { - t.Parallel() - - unknownObject := ObjectUnknown(map[string]attr.Type{"test_attr": StringType}) - - unknownObject.Null = true - - if unknownObject.IsNull() { - t.Error("unexpected null update after Null field setting") - } - - unknownObject.Unknown = false - - if !unknownObject.IsUnknown() { - t.Error("unexpected unknown update after Unknown field setting") - } - - unknownObject.Attrs = map[string]attr.Value{"test_attr": StringValue("test")} - - if len(unknownObject.Attributes()) > 0 { - t.Error("unexpected value update after Value field setting") - } -} - func TestObjectAs_struct(t *testing.T) { t.Parallel() @@ -759,8 +675,8 @@ func TestObjectAs_struct(t *testing.T) { H myEmbeddedStruct `tfsdk:"h"` I Object `tfsdk:"i"` } - object := Object{ - AttrTypes: map[string]attr.Type{ + object := ObjectValueMust( + map[string]attr.Type{ "a": StringType, "b": BoolType, "c": ListType{ElemType: StringType}, @@ -790,121 +706,121 @@ func TestObjectAs_struct(t *testing.T) { }, }, }, - Attrs: map[string]attr.Value{ - "a": String{Value: "hello"}, - "b": Bool{Value: true}, - "c": List{ - ElemType: StringType, - Elems: []attr.Value{ - String{Value: "into"}, - String{Value: "the"}, - String{Unknown: true}, - String{Null: true}, + map[string]attr.Value{ + "a": StringValue("hello"), + "b": BoolValue(true), + "c": ListValueMust( + StringType, + []attr.Value{ + StringValue("into"), + StringValue("the"), + StringUnknown(), + StringNull(), }, - }, - "d": List{ - ElemType: StringType, - Elems: []attr.Value{ - String{Value: "it's"}, - String{Value: "getting"}, - String{Value: "hard"}, - String{Value: "to"}, - String{Value: "come"}, - String{Value: "up"}, - String{Value: "with"}, - String{Value: "test"}, - String{Value: "values"}, + ), + "d": ListValueMust( + StringType, + []attr.Value{ + StringValue("it's"), + StringValue("getting"), + StringValue("hard"), + StringValue("to"), + StringValue("come"), + StringValue("up"), + StringValue("with"), + StringValue("test"), + StringValue("values"), }, - }, - "e": List{ - ElemType: BoolType, - Elems: []attr.Value{ - Bool{Value: true}, - Bool{Value: false}, - Bool{Value: false}, - Bool{Value: true}, + ), + "e": ListValueMust( + BoolType, + []attr.Value{ + BoolValue(true), + BoolValue(false), + BoolValue(false), + BoolValue(true), }, - }, - "f": List{ - ElemType: ListType{ + ), + "f": ListValueMust( + ListType{ ElemType: StringType, }, - Elems: []attr.Value{ - List{ - ElemType: StringType, - Elems: []attr.Value{ - String{Value: "head"}, - String{Value: "empty"}, + []attr.Value{ + ListValueMust( + StringType, + []attr.Value{ + StringValue("head"), + StringValue("empty"), }, - }, - List{ - ElemType: StringType, - Elems: []attr.Value{ - String{Value: "no"}, - String{Value: "thoughts"}, + ), + ListValueMust( + StringType, + []attr.Value{ + StringValue("no"), + StringValue("thoughts"), }, - }, + ), }, - }, - "g": Object{ - AttrTypes: map[string]attr.Type{ + ), + "g": ObjectValueMust( + map[string]attr.Type{ "dogs": NumberType, "cats": NumberType, "names": ListType{ElemType: StringType}, }, - Attrs: map[string]attr.Value{ - "dogs": Number{Value: big.NewFloat(3)}, - "cats": Number{Value: big.NewFloat(5)}, - "names": List{ - ElemType: StringType, - Elems: []attr.Value{ - String{Value: "Roxy"}, - String{Value: "Jpeg"}, - String{Value: "Kupo"}, - String{Value: "Clawde"}, - String{Value: "Yeti"}, - String{Value: "Abby"}, - String{Value: "Ellie"}, - String{Value: "Lexi"}, + map[string]attr.Value{ + "dogs": NumberValue(big.NewFloat(3)), + "cats": NumberValue(big.NewFloat(5)), + "names": ListValueMust( + StringType, + []attr.Value{ + StringValue("Roxy"), + StringValue("Jpeg"), + StringValue("Kupo"), + StringValue("Clawde"), + StringValue("Yeti"), + StringValue("Abby"), + StringValue("Ellie"), + StringValue("Lexi"), }, - }, + ), }, - }, - "h": Object{ - AttrTypes: map[string]attr.Type{ + ), + "h": ObjectValueMust( + map[string]attr.Type{ "red": StringType, "blue": ListType{ElemType: NumberType}, "green": NumberType, "yellow": NumberType, }, - Attrs: map[string]attr.Value{ - "red": String{Value: "judge me not too harshly, future maintainers, this much random data is hard to come up with without getting weird."}, - "blue": List{ - ElemType: NumberType, - Elems: []attr.Value{ - Number{Value: big.NewFloat(1)}, - Number{Value: big.NewFloat(2)}, - Number{Value: big.NewFloat(3)}, + map[string]attr.Value{ + "red": StringValue("judge me not too harshly, future maintainers, this much random data is hard to come up with without getting weird."), + "blue": ListValueMust( + NumberType, + []attr.Value{ + NumberValue(big.NewFloat(1)), + NumberValue(big.NewFloat(2)), + NumberValue(big.NewFloat(3)), }, - }, - "green": Number{Value: big.NewFloat(123.456)}, - "yellow": Number{Value: big.NewFloat(123)}, + ), + "green": NumberValue(big.NewFloat(123.456)), + "yellow": NumberValue(big.NewFloat(123)), }, - }, - "i": Object{ - AttrTypes: map[string]attr.Type{ + ), + "i": ObjectValueMust( + map[string]attr.Type{ "name": StringType, "age": NumberType, "opted_in": BoolType, }, - Attrs: map[string]attr.Value{ - "name": String{Value: "J Doe"}, - "age": Number{Value: big.NewFloat(28)}, - "opted_in": Bool{Value: true}, + map[string]attr.Value{ + "name": StringValue("J Doe"), + "age": NumberValue(big.NewFloat(28)), + "opted_in": BoolValue(true), }, - }, + ), }, - } + ) var target myStruct diags := object.As(context.Background(), &target, ObjectAsOptions{}) if diags.HasError() { @@ -912,88 +828,88 @@ func TestObjectAs_struct(t *testing.T) { } expected := myStruct{ A: "hello", - B: Bool{Value: true}, - C: List{ - ElemType: StringType, - Elems: []attr.Value{ - String{Value: "into"}, - String{Value: "the"}, - String{Unknown: true}, - String{Null: true}, - }, - }, + B: BoolValue(true), + C: ListValueMust( + StringType, + []attr.Value{ + StringValue("into"), + StringValue("the"), + StringUnknown(), + StringNull(), + }, + ), D: []string{"it's", "getting", "hard", "to", "come", "up", "with", "test", "values"}, E: []Bool{ - {Value: true}, - {Value: false}, - {Value: false}, - {Value: true}, + BoolValue(true), + BoolValue(false), + BoolValue(false), + BoolValue(true), }, F: []List{ - { - ElemType: StringType, - Elems: []attr.Value{ - String{Value: "head"}, - String{Value: "empty"}, + ListValueMust( + StringType, + []attr.Value{ + StringValue("head"), + StringValue("empty"), }, - }, - { - ElemType: StringType, - Elems: []attr.Value{ - String{Value: "no"}, - String{Value: "thoughts"}, + ), + ListValueMust( + StringType, + []attr.Value{ + StringValue("no"), + StringValue("thoughts"), }, - }, + ), }, - G: Object{ - AttrTypes: map[string]attr.Type{ + G: ObjectValueMust( + map[string]attr.Type{ "dogs": NumberType, "cats": NumberType, "names": ListType{ElemType: StringType}, }, - Attrs: map[string]attr.Value{ - "dogs": Number{Value: big.NewFloat(3)}, - "cats": Number{Value: big.NewFloat(5)}, - "names": List{ - ElemType: StringType, - Elems: []attr.Value{ - String{Value: "Roxy"}, - String{Value: "Jpeg"}, - String{Value: "Kupo"}, - String{Value: "Clawde"}, - String{Value: "Yeti"}, - String{Value: "Abby"}, - String{Value: "Ellie"}, - String{Value: "Lexi"}, + map[string]attr.Value{ + "dogs": NumberValue(big.NewFloat(3)), + "cats": NumberValue(big.NewFloat(5)), + "names": ListValueMust( + StringType, + []attr.Value{ + StringValue("Roxy"), + StringValue("Jpeg"), + StringValue("Kupo"), + StringValue("Clawde"), + StringValue("Yeti"), + StringValue("Abby"), + StringValue("Ellie"), + StringValue("Lexi"), }, - }, + ), }, - }, + ), H: myEmbeddedStruct{ Red: "judge me not too harshly, future maintainers, this much random data is hard to come up with without getting weird.", - Blue: List{ - ElemType: NumberType, - Elems: []attr.Value{ - Number{Value: big.NewFloat(1)}, - Number{Value: big.NewFloat(2)}, - Number{Value: big.NewFloat(3)}, + Blue: ListValueMust( + NumberType, + []attr.Value{ + NumberValue(big.NewFloat(1)), + NumberValue(big.NewFloat(2)), + NumberValue(big.NewFloat(3)), }, - }, - Green: Number{Value: big.NewFloat(123.456)}, + ), + Green: NumberValue(big.NewFloat(123.456)), Yellow: 123, }, - I: Object{ - AttrTypes: map[string]attr.Type{ + I: ObjectValueMust( + map[string]attr.Type{ "name": StringType, "age": NumberType, "opted_in": BoolType, }, - Attrs: map[string]attr.Value{ - "name": String{Value: "J Doe"}, - "age": Number{Value: big.NewFloat(28)}, - "opted_in": Bool{Value: true}, + map[string]attr.Value{ + "name": StringValue("J Doe"), + "age": NumberValue(big.NewFloat(28)), + "opted_in": BoolValue(true), }, - }, + ), } if diff := cmp.Diff(expected, target); diff != "" { t.Errorf("Unexpected diff (+wanted, -got): %s", diff) @@ -1014,35 +930,14 @@ func TestObjectAttributes(t *testing.T) { ), expected: map[string]attr.Value{"test_attr": StringValue("test-value")}, }, - "deprecated-known": { - input: Object{ - AttrTypes: map[string]attr.Type{"test_attr": StringType}, - Attrs: map[string]attr.Value{"test_attr": StringValue("test-value")}, - }, - expected: map[string]attr.Value{"test_attr": StringValue("test-value")}, - }, "null": { input: ObjectNull(map[string]attr.Type{"test_attr": StringType}), expected: nil, }, - "deprecated-null": { - input: Object{ - AttrTypes: map[string]attr.Type{"test_attr": StringType}, - Null: true, - }, - expected: nil, - }, "unknown": { input: ObjectUnknown(map[string]attr.Type{"test_attr": StringType}), expected: nil, }, - "deprecated-unknown": { - input: Object{ - AttrTypes: map[string]attr.Type{"test_attr": StringType}, - Unknown: true, - }, - expected: nil, - }, } for name, testCase := range testCases { @@ -1074,35 +969,14 @@ func TestObjectAttributeTypes(t *testing.T) { ), expected: map[string]attr.Type{"test_attr": StringType}, }, - "deprecated-known": { - input: Object{ - AttrTypes: map[string]attr.Type{"test_attr": StringType}, - Attrs: map[string]attr.Value{"test_attr": StringValue("test-value")}, - }, - expected: map[string]attr.Type{"test_attr": StringType}, - }, "null": { input: ObjectNull(map[string]attr.Type{"test_attr": StringType}), expected: map[string]attr.Type{"test_attr": StringType}, }, - "deprecated-null": { - input: Object{ - AttrTypes: map[string]attr.Type{"test_attr": StringType}, - Null: true, - }, - expected: map[string]attr.Type{"test_attr": StringType}, - }, "unknown": { input: ObjectUnknown(map[string]attr.Type{"test_attr": StringType}), expected: map[string]attr.Type{"test_attr": StringType}, }, - "deprecated-unknown": { - input: Object{ - AttrTypes: map[string]attr.Type{"test_attr": StringType}, - Unknown: true, - }, - expected: map[string]attr.Type{"test_attr": StringType}, - }, } for name, testCase := range testCases { @@ -1129,8 +1003,8 @@ func TestObjectToTerraformValue(t *testing.T) { } tests := map[string]testCase{ "value": { - receiver: Object{ - AttrTypes: map[string]attr.Type{ + receiver: ObjectValueMust( + map[string]attr.Type{ "a": ListType{ElemType: StringType}, "b": StringType, "c": BoolType, @@ -1142,34 +1016,34 @@ func TestObjectToTerraformValue(t *testing.T) { }, "f": SetType{ElemType: StringType}, }, - Attrs: map[string]attr.Value{ - "a": List{ - ElemType: StringType, - Elems: []attr.Value{ - String{Value: "hello"}, - String{Value: "world"}, + map[string]attr.Value{ + "a": ListValueMust( + StringType, + []attr.Value{ + StringValue("hello"), + StringValue("world"), }, - }, - "b": String{Value: "woohoo"}, - "c": Bool{Value: true}, - "d": Number{Value: big.NewFloat(1234)}, - "e": Object{ - AttrTypes: map[string]attr.Type{ + ), + "b": StringValue("woohoo"), + "c": BoolValue(true), + "d": NumberValue(big.NewFloat(1234)), + "e": ObjectValueMust( + map[string]attr.Type{ "name": StringType, }, - Attrs: map[string]attr.Value{ - "name": String{Value: "testing123"}, + map[string]attr.Value{ + "name": StringValue("testing123"), }, - }, - "f": Set{ - ElemType: StringType, - Elems: []attr.Value{ - String{Value: "hello"}, - String{Value: "world"}, + ), + "f": SetValueMust( + StringType, + []attr.Value{ + StringValue("hello"), + StringValue("world"), }, - }, + ), }, - }, + ), expected: tftypes.NewValue(tftypes.Object{ AttributeTypes: map[string]tftypes.Type{ "a": tftypes.List{ElementType: tftypes.String}, @@ -1201,8 +1075,8 @@ func TestObjectToTerraformValue(t *testing.T) { }), }, "unknown": { - receiver: Object{ - AttrTypes: map[string]attr.Type{ + receiver: ObjectUnknown( + map[string]attr.Type{ "a": ListType{ElemType: StringType}, "b": StringType, "c": BoolType, @@ -1214,8 +1088,7 @@ func TestObjectToTerraformValue(t *testing.T) { }, "f": SetType{ElemType: StringType}, }, - Unknown: true, - }, + ), expected: tftypes.NewValue(tftypes.Object{ AttributeTypes: map[string]tftypes.Type{ "a": tftypes.List{ElementType: tftypes.String}, @@ -1232,8 +1105,8 @@ func TestObjectToTerraformValue(t *testing.T) { }, tftypes.UnknownValue), }, "null": { - receiver: Object{ - AttrTypes: map[string]attr.Type{ + receiver: ObjectNull( + map[string]attr.Type{ "a": ListType{ElemType: StringType}, "b": StringType, "c": BoolType, @@ -1245,8 +1118,7 @@ func TestObjectToTerraformValue(t *testing.T) { }, "f": SetType{ElemType: StringType}, }, - Null: true, - }, + ), expected: tftypes.NewValue(tftypes.Object{ AttributeTypes: map[string]tftypes.Type{ "a": tftypes.List{ElementType: tftypes.String}, @@ -1263,8 +1135,8 @@ func TestObjectToTerraformValue(t *testing.T) { }, nil), }, "partial-unknown": { - receiver: Object{ - AttrTypes: map[string]attr.Type{ + receiver: ObjectValueMust( + map[string]attr.Type{ "a": ListType{ElemType: StringType}, "b": StringType, "c": BoolType, @@ -1276,34 +1148,34 @@ func TestObjectToTerraformValue(t *testing.T) { }, "f": SetType{ElemType: StringType}, }, - Attrs: map[string]attr.Value{ - "a": List{ - ElemType: StringType, - Elems: []attr.Value{ - String{Value: "hello"}, - String{Value: "world"}, + map[string]attr.Value{ + "a": ListValueMust( + StringType, + []attr.Value{ + StringValue("hello"), + StringValue("world"), }, - }, - "b": String{Unknown: true}, - "c": Bool{Value: true}, - "d": Number{Value: big.NewFloat(1234)}, - "e": Object{ - AttrTypes: map[string]attr.Type{ + ), + "b": StringUnknown(), + "c": BoolValue(true), + "d": NumberValue(big.NewFloat(1234)), + "e": ObjectValueMust( + map[string]attr.Type{ "name": StringType, }, - Attrs: map[string]attr.Value{ - "name": String{Value: "testing123"}, + map[string]attr.Value{ + "name": StringValue("testing123"), }, - }, - "f": Set{ - ElemType: StringType, - Elems: []attr.Value{ - String{Value: "hello"}, - String{Value: "world"}, + ), + "f": SetValueMust( + StringType, + []attr.Value{ + StringValue("hello"), + StringValue("world"), }, - }, + ), }, - }, + ), expected: tftypes.NewValue(tftypes.Object{ AttributeTypes: map[string]tftypes.Type{ "a": tftypes.List{ElementType: tftypes.String}, @@ -1339,8 +1211,8 @@ func TestObjectToTerraformValue(t *testing.T) { }), }, "partial-null": { - receiver: Object{ - AttrTypes: map[string]attr.Type{ + receiver: ObjectValueMust( + map[string]attr.Type{ "a": ListType{ElemType: StringType}, "b": StringType, "c": BoolType, @@ -1352,34 +1224,34 @@ func TestObjectToTerraformValue(t *testing.T) { }, "f": SetType{ElemType: StringType}, }, - Attrs: map[string]attr.Value{ - "a": List{ - ElemType: StringType, - Elems: []attr.Value{ - String{Value: "hello"}, - String{Value: "world"}, + map[string]attr.Value{ + "a": ListValueMust( + StringType, + []attr.Value{ + StringValue("hello"), + StringValue("world"), }, - }, - "b": String{Null: true}, - "c": Bool{Value: true}, - "d": Number{Value: big.NewFloat(1234)}, - "e": Object{ - AttrTypes: map[string]attr.Type{ + ), + "b": StringNull(), + "c": BoolValue(true), + "d": NumberValue(big.NewFloat(1234)), + "e": ObjectValueMust( + map[string]attr.Type{ "name": StringType, }, - Attrs: map[string]attr.Value{ - "name": String{Value: "testing123"}, + map[string]attr.Value{ + "name": StringValue("testing123"), }, - }, - "f": Set{ - ElemType: StringType, - Elems: []attr.Value{ - String{Value: "hello"}, - String{Value: "world"}, + ), + "f": SetValueMust( + StringType, + []attr.Value{ + StringValue("hello"), + StringValue("world"), }, - }, + ), }, - }, + ), expected: tftypes.NewValue(tftypes.Object{ AttributeTypes: map[string]tftypes.Type{ "a": tftypes.List{ElementType: tftypes.String}, @@ -1415,8 +1287,8 @@ func TestObjectToTerraformValue(t *testing.T) { }), }, "deep-partial-unknown": { - receiver: Object{ - AttrTypes: map[string]attr.Type{ + receiver: ObjectValueMust( + map[string]attr.Type{ "a": ListType{ElemType: StringType}, "b": StringType, "c": BoolType, @@ -1428,34 +1300,34 @@ func TestObjectToTerraformValue(t *testing.T) { }, "f": SetType{ElemType: StringType}, }, - Attrs: map[string]attr.Value{ - "a": List{ - ElemType: StringType, - Elems: []attr.Value{ - String{Value: "hello"}, - String{Value: "world"}, + map[string]attr.Value{ + "a": ListValueMust( + StringType, + []attr.Value{ + StringValue("hello"), + StringValue("world"), }, - }, - "b": String{Value: "woohoo"}, - "c": Bool{Value: true}, - "d": Number{Value: big.NewFloat(1234)}, - "e": Object{ - AttrTypes: map[string]attr.Type{ + ), + "b": StringValue("woohoo"), + "c": BoolValue(true), + "d": NumberValue(big.NewFloat(1234)), + "e": ObjectValueMust( + map[string]attr.Type{ "name": StringType, }, - Attrs: map[string]attr.Value{ - "name": String{Unknown: true}, + map[string]attr.Value{ + "name": StringUnknown(), }, - }, - "f": Set{ - ElemType: StringType, - Elems: []attr.Value{ - String{Value: "hello"}, - String{Value: "world"}, + ), + "f": SetValueMust( + StringType, + []attr.Value{ + StringValue("hello"), + StringValue("world"), }, - }, + ), }, - }, + ), expected: tftypes.NewValue(tftypes.Object{ AttributeTypes: map[string]tftypes.Type{ "a": tftypes.List{ElementType: tftypes.String}, @@ -1491,8 +1363,8 @@ func TestObjectToTerraformValue(t *testing.T) { }), }, "deep-partial-null": { - receiver: Object{ - AttrTypes: map[string]attr.Type{ + receiver: ObjectValueMust( + map[string]attr.Type{ "a": ListType{ElemType: StringType}, "b": StringType, "c": BoolType, @@ -1504,34 +1376,34 @@ func TestObjectToTerraformValue(t *testing.T) { }, "f": SetType{ElemType: StringType}, }, - Attrs: map[string]attr.Value{ - "a": List{ - ElemType: StringType, - Elems: []attr.Value{ - String{Value: "hello"}, - String{Value: "world"}, + map[string]attr.Value{ + "a": ListValueMust( + StringType, + []attr.Value{ + StringValue("hello"), + StringValue("world"), }, - }, - "b": String{Value: "woohoo"}, - "c": Bool{Value: true}, - "d": Number{Value: big.NewFloat(1234)}, - "e": Object{ - AttrTypes: map[string]attr.Type{ + ), + "b": StringValue("woohoo"), + "c": BoolValue(true), + "d": NumberValue(big.NewFloat(1234)), + "e": ObjectValueMust( + map[string]attr.Type{ "name": StringType, }, - Attrs: map[string]attr.Value{ - "name": String{Null: true}, + map[string]attr.Value{ + "name": StringNull(), }, - }, - "f": Set{ - ElemType: StringType, - Elems: []attr.Value{ - String{Value: "hello"}, - String{Value: "world"}, + ), + "f": SetValueMust( + StringType, + []attr.Value{ + StringValue("hello"), + StringValue("world"), }, - }, + ), }, - }, + ), expected: tftypes.NewValue(tftypes.Object{ AttributeTypes: map[string]tftypes.Type{ "a": tftypes.List{ElementType: tftypes.String}, @@ -1566,39 +1438,6 @@ func TestObjectToTerraformValue(t *testing.T) { }), }), }, - "no-attr-types": { - receiver: Object{ - Attrs: map[string]attr.Value{ - "a": List{ - ElemType: StringType, - Elems: []attr.Value{ - String{Value: "hello"}, - String{Value: "world"}, - }, - }, - "b": String{Value: "woohoo"}, - "c": Bool{Value: true}, - "d": Number{Value: big.NewFloat(1234)}, - "e": Object{ - AttrTypes: map[string]attr.Type{ - "name": StringType, - }, - Attrs: map[string]attr.Value{ - "name": String{Value: "testing123"}, - }, - }, - "f": Set{ - ElemType: StringType, - Elems: []attr.Value{ - String{Value: "hello"}, - String{Value: "world"}, - }, - }, - }, - }, - expected: tftypes.Value{}, - expectedErr: "cannot convert Object to tftypes.Value if AttrTypes field is not set", - }, } for name, test := range tests { @@ -1695,22 +1534,22 @@ func TestObjectEqual(t *testing.T) { expected: false, }, "known-known-diff-attribute-types": { - receiver: Object{ - AttrTypes: map[string]attr.Type{ + receiver: ObjectValueMust( + map[string]attr.Type{ "string": StringType, }, - Attrs: map[string]attr.Value{ + map[string]attr.Value{ "string": StringValue("hello"), }, - }, - arg: Object{ - AttrTypes: map[string]attr.Type{ + ), + arg: ObjectValueMust( + map[string]attr.Type{ "number": NumberType, }, - Attrs: map[string]attr.Value{ + map[string]attr.Value{ "number": NumberValue(big.NewFloat(123)), }, - }, + ), expected: false, }, "known-known-diff-unknown": { @@ -1752,595 +1591,73 @@ func TestObjectEqual(t *testing.T) { expected: false, }, "known-unknown": { - receiver: Object{ - AttrTypes: map[string]attr.Type{ + receiver: ObjectValueMust( + map[string]attr.Type{ "string": StringType, "bool": BoolType, "number": NumberType, }, - Attrs: map[string]attr.Value{ + map[string]attr.Value{ "string": StringValue("hello"), "bool": BoolValue(true), "number": NumberValue(big.NewFloat(123)), }, - }, - arg: ObjectUnknown( - map[string]attr.Type{ - "string": StringType, - "bool": BoolType, - "number": NumberType, - }, - ), - expected: false, - }, - "known-null": { - receiver: ObjectValueMust( - map[string]attr.Type{ - "string": StringType, - "bool": BoolType, - "number": NumberType, - }, - map[string]attr.Value{ - "string": StringValue("hello"), - "bool": BoolValue(true), - "number": NumberValue(big.NewFloat(123)), - }, - ), - arg: ObjectNull( - map[string]attr.Type{ - "string": StringType, - "bool": BoolType, - "number": NumberType, - }, - ), - expected: false, - }, - "known-diff-wrong-type": { - receiver: ObjectValueMust( - map[string]attr.Type{ - "string": StringType, - "bool": BoolType, - "number": NumberType, - }, - map[string]attr.Value{ - "string": StringValue("hello"), - "bool": BoolValue(true), - "number": NumberValue(big.NewFloat(123)), - }, - ), - arg: StringValue("whoops"), - expected: false, - }, - "known-deprecated-known": { - receiver: ObjectValueMust( - map[string]attr.Type{ - "string": StringType, - "bool": BoolType, - "number": NumberType, - }, - map[string]attr.Value{ - "string": StringValue("hello"), - "bool": BoolValue(true), - "number": NumberValue(big.NewFloat(123)), - }, - ), - arg: Object{ - AttrTypes: map[string]attr.Type{ - "string": StringType, - "bool": BoolType, - "number": NumberType, - }, - Attrs: map[string]attr.Value{ - "string": String{Value: "hello"}, - "bool": Bool{Value: true}, - "number": Number{Value: big.NewFloat(123)}, - }, - }, - expected: false, // intentional - }, - "known-deprecated-unknown": { - receiver: ObjectValueMust( - map[string]attr.Type{ - "string": StringType, - "bool": BoolType, - "number": NumberType, - }, - map[string]attr.Value{ - "string": StringValue("hello"), - "bool": BoolValue(true), - "number": NumberValue(big.NewFloat(123)), - }, - ), - arg: Object{ - AttrTypes: map[string]attr.Type{ - "string": StringType, - "bool": BoolType, - "number": NumberType, - }, - Unknown: true, - }, - expected: false, - }, - "known-deprecated-null": { - receiver: ObjectValueMust( - map[string]attr.Type{ - "string": StringType, - "bool": BoolType, - "number": NumberType, - }, - map[string]attr.Value{ - "string": StringValue("hello"), - "bool": BoolValue(true), - "number": NumberValue(big.NewFloat(123)), - }, - ), - arg: Object{ - AttrTypes: map[string]attr.Type{ - "string": StringType, - "bool": BoolType, - "number": NumberType, - }, - Null: true, - }, - expected: false, - }, - "unknown-known": { - receiver: ObjectUnknown( - map[string]attr.Type{ - "string": StringType, - "bool": BoolType, - "number": NumberType, - }, - ), - arg: ObjectValueMust( - map[string]attr.Type{ - "string": StringType, - "bool": BoolType, - "number": NumberType, - }, - map[string]attr.Value{ - "string": String{Value: "hello"}, - "bool": Bool{Value: true}, - "number": Number{Value: big.NewFloat(123)}, - }, - ), - expected: false, - }, - "unknown-deprecated-known": { - receiver: ObjectUnknown( - map[string]attr.Type{ - "string": StringType, - "bool": BoolType, - "number": NumberType, - }, - ), - arg: Object{ - AttrTypes: map[string]attr.Type{ - "string": StringType, - "bool": BoolType, - "number": NumberType, - }, - Attrs: map[string]attr.Value{ - "string": String{Value: "hello"}, - "bool": Bool{Value: true}, - "number": Number{Value: big.NewFloat(123)}, - }, - }, - expected: false, - }, - "unknown-unknown": { - receiver: ObjectUnknown( - map[string]attr.Type{ - "string": StringType, - "bool": BoolType, - "number": NumberType, - }, - ), - arg: ObjectUnknown( - map[string]attr.Type{ - "string": StringType, - "bool": BoolType, - "number": NumberType, - }, - ), - expected: true, - }, - "unknown-deprecated-unknown": { - receiver: ObjectUnknown( - map[string]attr.Type{ - "string": StringType, - "bool": BoolType, - "number": NumberType, - }, - ), - arg: Object{ - AttrTypes: map[string]attr.Type{ - "string": StringType, - "bool": BoolType, - "number": NumberType, - }, - Unknown: true, - }, - expected: false, // intentional - }, - "unknown-null": { - receiver: ObjectUnknown( - map[string]attr.Type{ - "string": StringType, - "bool": BoolType, - "number": NumberType, - }, - ), - arg: ObjectNull( - map[string]attr.Type{ - "string": StringType, - "bool": BoolType, - "number": NumberType, - }, - ), - expected: false, - }, - "unknown-deprecated-null": { - receiver: ObjectUnknown( - map[string]attr.Type{ - "string": StringType, - "bool": BoolType, - "number": NumberType, - }, - ), - arg: Object{ - AttrTypes: map[string]attr.Type{ - "string": StringType, - "bool": BoolType, - "number": NumberType, - }, - Null: true, - }, - expected: false, - }, - "null-known": { - receiver: ObjectNull( - map[string]attr.Type{ - "string": StringType, - "bool": BoolType, - "number": NumberType, - }, - ), - arg: ObjectValueMust( - map[string]attr.Type{ - "string": StringType, - "bool": BoolType, - "number": NumberType, - }, - map[string]attr.Value{ - "string": String{Value: "hello"}, - "bool": Bool{Value: true}, - "number": Number{Value: big.NewFloat(123)}, - }, - ), - expected: false, - }, - "null-deprecated-known": { - receiver: ObjectNull( - map[string]attr.Type{ - "string": StringType, - "bool": BoolType, - "number": NumberType, - }, - ), - arg: Object{ - AttrTypes: map[string]attr.Type{ - "string": StringType, - "bool": BoolType, - "number": NumberType, - }, - Attrs: map[string]attr.Value{ - "string": String{Value: "hello"}, - "bool": Bool{Value: true}, - "number": Number{Value: big.NewFloat(123)}, - }, - }, - expected: false, - }, - "null-unknown": { - receiver: ObjectNull( - map[string]attr.Type{ - "string": StringType, - "bool": BoolType, - "number": NumberType, - }, ), - arg: ObjectUnknown( - map[string]attr.Type{ - "string": StringType, - "bool": BoolType, - "number": NumberType, - }, - ), - expected: false, - }, - "null-deprecated-unknown": { - receiver: ObjectNull( - map[string]attr.Type{ - "string": StringType, - "bool": BoolType, - "number": NumberType, - }, - ), - arg: Object{ - AttrTypes: map[string]attr.Type{ - "string": StringType, - "bool": BoolType, - "number": NumberType, - }, - Unknown: true, - }, - expected: false, - }, - "null-null": { - receiver: ObjectNull( - map[string]attr.Type{ - "string": StringType, - "bool": BoolType, - "number": NumberType, - }, - ), - arg: ObjectNull( - map[string]attr.Type{ - "string": StringType, - "bool": BoolType, - "number": NumberType, - }, - ), - expected: true, - }, - "null-deprecated-null": { - receiver: ObjectNull( - map[string]attr.Type{ - "string": StringType, - "bool": BoolType, - "number": NumberType, - }, - ), - arg: Object{ - AttrTypes: map[string]attr.Type{ - "string": StringType, - "bool": BoolType, - "number": NumberType, - }, - Null: true, - }, - expected: false, // intentional - }, - "deprecated-known-deprecated-known": { - receiver: Object{ - AttrTypes: map[string]attr.Type{ - "string": StringType, - "bool": BoolType, - "number": NumberType, - }, - Attrs: map[string]attr.Value{ - "string": String{Value: "hello"}, - "bool": Bool{Value: true}, - "number": Number{Value: big.NewFloat(123)}, - }, - }, - arg: Object{ - AttrTypes: map[string]attr.Type{ - "string": StringType, - "bool": BoolType, - "number": NumberType, - }, - Attrs: map[string]attr.Value{ - "string": String{Value: "hello"}, - "bool": Bool{Value: true}, - "number": Number{Value: big.NewFloat(123)}, - }, - }, - expected: true, - }, - "deprecated-known-deprecated-known-diff-value": { - receiver: Object{ - AttrTypes: map[string]attr.Type{ - "string": StringType, - "bool": BoolType, - "number": NumberType, - }, - Attrs: map[string]attr.Value{ - "string": String{Value: "hello"}, - "bool": Bool{Value: true}, - "number": Number{Value: big.NewFloat(123)}, - }, - }, - arg: Object{ - AttrTypes: map[string]attr.Type{ - "string": StringType, - "bool": BoolType, - "number": NumberType, - }, - Attrs: map[string]attr.Value{ - "string": String{Value: "world"}, - "bool": Bool{Value: true}, - "number": Number{Value: big.NewFloat(123)}, - }, - }, - expected: false, - }, - "deprecated-known-deprecated-known-diff-attribute-types": { - receiver: Object{ - AttrTypes: map[string]attr.Type{ - "string": StringType, - }, - Attrs: map[string]attr.Value{ - "string": String{Value: "hello"}, - }, - }, - arg: Object{ - AttrTypes: map[string]attr.Type{ - "number": NumberType, - }, - Attrs: map[string]attr.Value{ - "number": Number{Value: big.NewFloat(123)}, - }, - }, - expected: false, - }, - "deprecated-known-deprecated-known-diff-attribute-count": { - receiver: Object{ - AttrTypes: map[string]attr.Type{ - "string": StringType, - }, - Attrs: map[string]attr.Value{ - "string": String{Value: "hello"}, - }, - }, - arg: Object{ - AttrTypes: map[string]attr.Type{ - "string": StringType, - "list": ListType{ElemType: StringType}, - }, - Attrs: map[string]attr.Value{ - "string": String{Value: "hello"}, - "list": List{ElemType: BoolType, Elems: []attr.Value{ - Bool{Value: true}, - Bool{Value: false}, - }}, - }, - }, - expected: false, - }, - "deprecated-known-deprecated-known-diff-unknown": { - receiver: Object{ - AttrTypes: map[string]attr.Type{ - "string": StringType, - }, - Attrs: map[string]attr.Value{ - "string": String{Value: "hello"}, - }, - }, - arg: Object{ - AttrTypes: map[string]attr.Type{ - "string": StringType, - }, - Attrs: map[string]attr.Value{ - "string": String{Unknown: true}, - }, - }, - expected: false, - }, - "deprecated-known-deprecated-known-diff-null": { - receiver: Object{ - AttrTypes: map[string]attr.Type{ - "string": StringType, - }, - Attrs: map[string]attr.Value{ - "string": String{Value: "hello"}, - }, - }, - arg: Object{ - AttrTypes: map[string]attr.Type{ - "string": StringType, - }, - Attrs: map[string]attr.Value{ - "string": String{Null: true}, - }, - }, - expected: false, - }, - "deprecated-known-deprecated-unknown": { - receiver: Object{ - AttrTypes: map[string]attr.Type{ - "string": StringType, - "bool": BoolType, - "number": NumberType, - }, - Attrs: map[string]attr.Value{ - "string": String{Value: "hello"}, - "bool": Bool{Value: true}, - "number": Number{Value: big.NewFloat(123)}, - }, - }, - arg: Object{ - AttrTypes: map[string]attr.Type{ + arg: ObjectUnknown( + map[string]attr.Type{ "string": StringType, "bool": BoolType, "number": NumberType, }, - Unknown: true, - }, + ), expected: false, }, - "deprecated-known-deprecated-null": { - receiver: Object{ - AttrTypes: map[string]attr.Type{ + "known-null": { + receiver: ObjectValueMust( + map[string]attr.Type{ "string": StringType, "bool": BoolType, "number": NumberType, }, - Attrs: map[string]attr.Value{ - "string": String{Value: "hello"}, - "bool": Bool{Value: true}, - "number": Number{Value: big.NewFloat(123)}, + map[string]attr.Value{ + "string": StringValue("hello"), + "bool": BoolValue(true), + "number": NumberValue(big.NewFloat(123)), }, - }, - arg: Object{ - AttrTypes: map[string]attr.Type{ + ), + arg: ObjectNull( + map[string]attr.Type{ "string": StringType, "bool": BoolType, "number": NumberType, }, - Null: true, - }, + ), expected: false, }, - "deprecated-known-diff-wrong-type": { - receiver: Object{ - AttrTypes: map[string]attr.Type{ + "known-diff-wrong-type": { + receiver: ObjectValueMust( + map[string]attr.Type{ "string": StringType, "bool": BoolType, "number": NumberType, }, - Attrs: map[string]attr.Value{ - "string": String{Value: "hello"}, - "bool": Bool{Value: true}, - "number": Number{Value: big.NewFloat(123)}, - }, - }, - arg: String{Value: "whoops"}, - expected: false, - }, - "deprecated-known-invalid-attribute-name": { - receiver: Object{ - AttrTypes: map[string]attr.Type{ - "string": StringType, - }, - Attrs: map[string]attr.Value{ - "string": String{Value: "hello"}, - }, - }, - arg: Object{ - AttrTypes: map[string]attr.Type{ - "string": StringType, - }, - Attrs: map[string]attr.Value{ - "strng": String{Value: "hello"}, + map[string]attr.Value{ + "string": StringValue("hello"), + "bool": BoolValue(true), + "number": NumberValue(big.NewFloat(123)), }, - }, + ), + arg: StringValue("whoops"), expected: false, }, - "deprecated-known-known": { - receiver: Object{ - AttrTypes: map[string]attr.Type{ + "unknown-known": { + receiver: ObjectUnknown( + map[string]attr.Type{ "string": StringType, "bool": BoolType, "number": NumberType, }, - Attrs: map[string]attr.Value{ - "string": String{Value: "hello"}, - "bool": Bool{Value: true}, - "number": Number{Value: big.NewFloat(123)}, - }, - }, + ), arg: ObjectValueMust( map[string]attr.Type{ "string": StringType, @@ -2348,26 +1665,21 @@ func TestObjectEqual(t *testing.T) { "number": NumberType, }, map[string]attr.Value{ - "string": String{Value: "hello"}, - "bool": Bool{Value: true}, - "number": Number{Value: big.NewFloat(123)}, + "string": StringValue("hello"), + "bool": BoolValue(true), + "number": NumberValue(big.NewFloat(123)), }, ), - expected: false, // intentional + expected: false, }, - "deprecated-known-unknown": { - receiver: Object{ - AttrTypes: map[string]attr.Type{ + "unknown-unknown": { + receiver: ObjectUnknown( + map[string]attr.Type{ "string": StringType, "bool": BoolType, "number": NumberType, }, - Attrs: map[string]attr.Value{ - "string": String{Value: "hello"}, - "bool": Bool{Value: true}, - "number": Number{Value: big.NewFloat(123)}, - }, - }, + ), arg: ObjectUnknown( map[string]attr.Type{ "string": StringType, @@ -2375,21 +1687,16 @@ func TestObjectEqual(t *testing.T) { "number": NumberType, }, ), - expected: false, + expected: true, }, - "deprecated-known-null": { - receiver: Object{ - AttrTypes: map[string]attr.Type{ + "unknown-null": { + receiver: ObjectUnknown( + map[string]attr.Type{ "string": StringType, "bool": BoolType, "number": NumberType, }, - Attrs: map[string]attr.Value{ - "string": String{Value: "hello"}, - "bool": Bool{Value: true}, - "number": Number{Value: big.NewFloat(123)}, - }, - }, + ), arg: ObjectNull( map[string]attr.Type{ "string": StringType, @@ -2399,34 +1706,36 @@ func TestObjectEqual(t *testing.T) { ), expected: false, }, - "deprecated-unknown-deprecated-unknown": { - receiver: Object{ - AttrTypes: map[string]attr.Type{ + "null-known": { + receiver: ObjectNull( + map[string]attr.Type{ "string": StringType, "bool": BoolType, "number": NumberType, }, - Unknown: true, - }, - arg: Object{ - AttrTypes: map[string]attr.Type{ + ), + arg: ObjectValueMust( + map[string]attr.Type{ "string": StringType, "bool": BoolType, "number": NumberType, }, - Unknown: true, - }, - expected: true, + map[string]attr.Value{ + "string": StringValue("hello"), + "bool": BoolValue(true), + "number": NumberValue(big.NewFloat(123)), + }, + ), + expected: false, }, - "deprecated-unknown-unknown": { - receiver: Object{ - AttrTypes: map[string]attr.Type{ + "null-unknown": { + receiver: ObjectNull( + map[string]attr.Type{ "string": StringType, "bool": BoolType, "number": NumberType, }, - Unknown: true, - }, + ), arg: ObjectUnknown( map[string]attr.Type{ "string": StringType, @@ -2434,36 +1743,16 @@ func TestObjectEqual(t *testing.T) { "number": NumberType, }, ), - expected: false, // intentional - }, - "deprecated-null-deprecated-null": { - receiver: Object{ - AttrTypes: map[string]attr.Type{ - "string": StringType, - "bool": BoolType, - "number": NumberType, - }, - Null: true, - }, - arg: Object{ - AttrTypes: map[string]attr.Type{ - "string": StringType, - "bool": BoolType, - "number": NumberType, - }, - Null: true, - }, - expected: true, + expected: false, }, - "deprecated-null-null": { - receiver: Object{ - AttrTypes: map[string]attr.Type{ + "null-null": { + receiver: ObjectNull( + map[string]attr.Type{ "string": StringType, "bool": BoolType, "number": NumberType, }, - Null: true, - }, + ), arg: ObjectNull( map[string]attr.Type{ "string": StringType, @@ -2471,7 +1760,7 @@ func TestObjectEqual(t *testing.T) { "number": NumberType, }, ), - expected: false, // intentional + expected: true, }, } @@ -2502,43 +1791,14 @@ func TestObjectIsNull(t *testing.T) { ), expected: false, }, - "deprecated-known": { - input: Object{ - AttrTypes: map[string]attr.Type{"test_attr": StringType}, - Attrs: map[string]attr.Value{"test_attr": StringValue("test-value")}, - }, - expected: false, - }, "null": { input: ObjectNull(map[string]attr.Type{"test_attr": StringType}), expected: true, }, - "deprecated-null": { - input: Object{ - AttrTypes: map[string]attr.Type{"test_attr": StringType}, - Null: true, - }, - expected: true, - }, "unknown": { input: ObjectUnknown(map[string]attr.Type{"test_attr": StringType}), expected: false, }, - "deprecated-unknown": { - input: Object{ - AttrTypes: map[string]attr.Type{"test_attr": StringType}, - Unknown: true, - }, - expected: false, - }, - "deprecated-invalid": { - input: Object{ - AttrTypes: map[string]attr.Type{"test_attr": StringType}, - Null: true, - Unknown: true, - }, - expected: true, - }, } for name, testCase := range testCases { @@ -2570,43 +1830,14 @@ func TestObjectIsUnknown(t *testing.T) { ), expected: false, }, - "deprecated-known": { - input: Object{ - AttrTypes: map[string]attr.Type{"test_attr": StringType}, - Attrs: map[string]attr.Value{"test_attr": StringValue("test-value")}, - }, - expected: false, - }, "null": { input: ObjectNull(map[string]attr.Type{"test_attr": StringType}), expected: false, }, - "deprecated-null": { - input: Object{ - AttrTypes: map[string]attr.Type{"test_attr": StringType}, - Null: true, - }, - expected: false, - }, "unknown": { input: ObjectUnknown(map[string]attr.Type{"test_attr": StringType}), expected: true, }, - "deprecated-unknown": { - input: Object{ - AttrTypes: map[string]attr.Type{"test_attr": StringType}, - Unknown: true, - }, - expected: true, - }, - "deprecated-invalid": { - input: Object{ - AttrTypes: map[string]attr.Type{"test_attr": StringType}, - Null: true, - Unknown: true, - }, - expected: true, - }, } for name, testCase := range testCases { @@ -2642,11 +1873,11 @@ func TestObjectString(t *testing.T) { "theta": BoolType, }, map[string]attr.Value{ - "alpha": String{Value: "hello"}, - "beta": Int64{Value: 98719827987189}, - "gamma": Float64{Value: -9876.782378}, - "sigma": Number{Unknown: true}, - "theta": Bool{Null: true}, + "alpha": StringValue("hello"), + "beta": Int64Value(98719827987189), + "gamma": Float64Value(-9876.782378), + "sigma": NumberUnknown(), + "theta": BoolNull(), }, ), expectation: `{"alpha":"hello","beta":98719827987189,"gamma":-9876.782378,"sigma":,"theta":}`, @@ -2680,9 +1911,9 @@ func TestObjectString(t *testing.T) { "three": NumberType, }, map[string]attr.Value{ - "one": String{Value: "1"}, - "two": Bool{Value: true}, - "three": Number{Value: big.NewFloat(0.3)}, + "one": StringValue("1"), + "two": BoolValue(true), + "three": NumberValue(big.NewFloat(0.3)), }, ), "beta": ObjectValueMust( @@ -2692,14 +1923,14 @@ func TestObjectString(t *testing.T) { "tre": StringType, }, map[string]attr.Value{ - "uno": Int64{Value: 1}, - "due": Bool{Value: false}, - "tre": String{Value: "3"}, + "uno": Int64Value(1), + "due": BoolValue(false), + "tre": StringValue("3"), }, ), - "gamma": Float64{Value: -9876.782378}, - "sigma": Number{Unknown: true}, - "theta": Bool{Null: true}, + "gamma": Float64Value(-9876.782378), + "sigma": NumberUnknown(), + "theta": BoolNull(), }, ), expectation: `{"alpha":{"one":"1","three":0.3,"two":true},"beta":{"due":false,"tre":"3","uno":1},"gamma":-9876.782378,"sigma":,"theta":}`, @@ -2712,79 +1943,9 @@ func TestObjectString(t *testing.T) { input: ObjectNull(map[string]attr.Type{"test_attr": StringType}), expectation: "", }, - "deprecated-known": { - input: Object{ - AttrTypes: map[string]attr.Type{ - "alpha": StringType, - "beta": Int64Type, - "gamma": Float64Type, - "sigma": NumberType, - "theta": BoolType, - }, - Attrs: map[string]attr.Value{ - "alpha": String{Value: "hello"}, - "beta": Int64{Value: 98719827987189}, - "gamma": Float64{Value: -9876.782378}, - "sigma": Number{Unknown: true}, - "theta": Bool{Null: true}, - }, - }, - expectation: `{"alpha":"hello","beta":98719827987189,"gamma":-9876.782378,"sigma":,"theta":}`, - }, - "deprecated-known-object-of-objects": { - input: Object{ - AttrTypes: map[string]attr.Type{ - "alpha": ObjectType{ - AttrTypes: map[string]attr.Type{ - "one": StringType, - "two": BoolType, - "three": NumberType, - }, - }, - "beta": ObjectType{ - AttrTypes: map[string]attr.Type{ - "uno": Int64Type, - "due": BoolType, - "tre": StringType, - }, - }, - "gamma": Float64Type, - "sigma": NumberType, - "theta": BoolType, - }, - Attrs: map[string]attr.Value{ - "alpha": Object{ - Attrs: map[string]attr.Value{ - "one": String{Value: "1"}, - "two": Bool{Value: true}, - "three": Number{Value: big.NewFloat(0.3)}, - }, - }, - "beta": Object{ - Attrs: map[string]attr.Value{ - "uno": Int64{Value: 1}, - "due": Bool{Value: false}, - "tre": String{Value: "3"}, - }, - }, - "gamma": Float64{Value: -9876.782378}, - "sigma": Number{Unknown: true}, - "theta": Bool{Null: true}, - }, - }, - expectation: `{"alpha":{"one":"1","three":0.3,"two":true},"beta":{"due":false,"tre":"3","uno":1},"gamma":-9876.782378,"sigma":,"theta":}`, - }, - "deprecated-unknown": { - input: Object{Unknown: true}, - expectation: "", - }, - "deprecated-null": { - input: Object{Null: true}, - expectation: "", - }, - "default-empty": { + "zero-value": { input: Object{}, - expectation: "{}", + expectation: "", }, } @@ -2891,98 +2052,6 @@ func TestObjectType(t *testing.T) { input: ObjectNull(map[string]attr.Type{"test_attr": StringType}), expectation: ObjectType{AttrTypes: map[string]attr.Type{"test_attr": StringType}}, }, - "deprecated-known": { - input: Object{ - AttrTypes: map[string]attr.Type{ - "test_attr1": StringType, - "test_attr2": StringType, - }, - Attrs: map[string]attr.Value{ - "test_attr1": String{Value: "hello"}, - "test_attr2": String{Value: "world"}, - }, - }, - expectation: ObjectType{ - AttrTypes: map[string]attr.Type{ - "test_attr1": StringType, - "test_attr2": StringType, - }, - }, - }, - "deprecated-known-object-of-objects": { - input: Object{ - AttrTypes: map[string]attr.Type{ - "test_attr1": ObjectType{ - AttrTypes: map[string]attr.Type{ - "test_attr1": StringType, - "test_attr2": StringType, - }, - }, - "test_attr2": ObjectType{ - AttrTypes: map[string]attr.Type{ - "test_attr1": StringType, - "test_attr2": StringType, - }, - }, - }, - Attrs: map[string]attr.Value{ - "test_attr1": ObjectValueMust( - map[string]attr.Type{ - "test_attr1": StringType, - "test_attr2": StringType, - }, - map[string]attr.Value{ - "test_attr1": StringValue("hello"), - "test_attr2": StringValue("world"), - }, - ), - "test_attr2": ObjectValueMust( - map[string]attr.Type{ - "test_attr1": StringType, - "test_attr2": StringType, - }, - map[string]attr.Value{ - "test_attr1": StringValue("foo"), - "test_attr2": StringValue("bar"), - }, - ), - }, - }, - expectation: ObjectType{ - AttrTypes: map[string]attr.Type{ - "test_attr1": ObjectType{ - AttrTypes: map[string]attr.Type{ - "test_attr1": StringType, - "test_attr2": StringType, - }, - }, - "test_attr2": ObjectType{ - AttrTypes: map[string]attr.Type{ - "test_attr1": StringType, - "test_attr2": StringType, - }, - }, - }, - }, - }, - "deprecated-unknown": { - input: Object{ - AttrTypes: map[string]attr.Type{"test_attr": StringType}, - Unknown: true, - }, - expectation: ObjectType{ - AttrTypes: map[string]attr.Type{"test_attr": StringType}, - }, - }, - "deprecated-null": { - input: Object{ - AttrTypes: map[string]attr.Type{"test_attr": StringType}, - Null: true, - }, - expectation: ObjectType{ - AttrTypes: map[string]attr.Type{"test_attr": StringType}, - }, - }, } for name, test := range tests { diff --git a/types/set.go b/types/set.go index fbfc5e66d..18c386d71 100644 --- a/types/set.go +++ b/types/set.go @@ -53,24 +53,17 @@ func (st SetType) TerraformType(ctx context.Context) tftypes.Type { // This is meant to convert the tftypes.Value into a more convenient Go // type for the provider to consume the data with. func (st SetType) ValueFromTerraform(ctx context.Context, in tftypes.Value) (attr.Value, error) { - set := Set{ - ElemType: st.ElemType, - state: valueStateDeprecated, - } if in.Type() == nil { - set.Null = true - return set, nil + return SetNull(st.ElemType), nil } if !in.Type().Equal(st.TerraformType(ctx)) { return nil, fmt.Errorf("can't use %s as value of Set with ElementType %T, can only use %s values", in.String(), st.ElemType, st.ElemType.TerraformType(ctx).String()) } if !in.IsKnown() { - set.Unknown = true - return set, nil + return SetUnknown(st.ElemType), nil } if in.IsNull() { - set.Null = true - return set, nil + return SetNull(st.ElemType), nil } val := []tftypes.Value{} err := in.As(&val) @@ -85,8 +78,9 @@ func (st SetType) ValueFromTerraform(ctx context.Context, in tftypes.Value) (att } elems = append(elems, av) } - set.Elems = elems - return set, nil + // ValueFromTerraform above on each element should make this safe. + // Otherwise, this will need to do some Diagnostics to error conversion. + return SetValueMust(st.ElemType, elems), nil } // Equal returns true if `o` is also a SetType and has the same ElemType. @@ -199,39 +193,30 @@ func (st SetType) Validate(ctx context.Context, in tftypes.Value, path path.Path // ValueType returns the Value type. func (t SetType) ValueType(_ context.Context) attr.Value { return Set{ - ElemType: t.ElemType, + elementType: t.ElemType, } } // SetNull creates a Set with a null value. Determine whether the value is // null via the Set type IsNull method. -// -// Setting the deprecated Set type ElemType, Elems, Null, or Unknown fields -// after creating a Set with this function has no effect. func SetNull(elementType attr.Type) Set { return Set{ elementType: elementType, - state: valueStateNull, + state: attr.ValueStateNull, } } // SetUnknown creates a Set with an unknown value. Determine whether the // value is unknown via the Set type IsUnknown method. -// -// Setting the deprecated Set type ElemType, Elems, Null, or Unknown fields -// after creating a Set with this function has no effect. func SetUnknown(elementType attr.Type) Set { return Set{ elementType: elementType, - state: valueStateUnknown, + state: attr.ValueStateUnknown, } } // SetValue creates a Set with a known value. Access the value via the Set // type Elements or ElementsAs methods. -// -// Setting the deprecated Set type ElemType, Elems, Null, or Unknown fields -// after creating a Set with this function has no effect. func SetValue(elementType attr.Type, elements []attr.Value) (Set, diag.Diagnostics) { var diags diag.Diagnostics @@ -258,7 +243,7 @@ func SetValue(elementType attr.Type, elements []attr.Value) (Set, diag.Diagnosti return Set{ elementType: elementType, elements: elements, - state: valueStateKnown, + state: attr.ValueStateKnown, }, nil } @@ -298,9 +283,6 @@ func SetValueFrom(ctx context.Context, elementType attr.Type, elements any) (Set // This creation function is only recommended to create Set values which will // not potentially effect practitioners, such as testing, or exhaustively // tested provider logic. -// -// Setting the deprecated Set type ElemType, Elems, Null, or Unknown fields -// after creating a Set with this function has no effect. func SetValueMust(elementType attr.Type, elements []attr.Value) Set { set, diags := SetValue(elementType, elements) @@ -325,72 +307,20 @@ func SetValueMust(elementType attr.Type, elements []attr.Value) Set { // Set represents a set of attr.Value, all of the same type, // indicated by ElemType. type Set struct { - // Unknown will be set to true if the entire set is an unknown value. - // If only some of the elements in the set are unknown, their known or - // unknown status will be represented however that attr.Value - // surfaces that information. The Set's Unknown property only tracks - // if the number of elements in a Set is known, not whether the - // elements that are in the set are known. - // - // If the Set was created with the SetValue, SetNull, or SetUnknown - // functions, changing this field has no effect. - // - // Deprecated: Use the SetUnknown function to create an unknown Set - // value or use the IsUnknown method to determine whether the Set value - // is unknown instead. - Unknown bool - - // Null will be set to true if the set is null, either because it was - // omitted from the configuration, state, or plan, or because it was - // explicitly set to null. - // - // If the Set was created with the SetValue, SetNull, or SetUnknown - // functions, changing this field has no effect. - // - // Deprecated: Use the SetNull function to create a null Set value or - // use the IsNull method to determine whether the Set value is null - // instead. - Null bool - - // Elems are the elements in the set. - // - // If the Set was created with the SetValue, SetNull, or SetUnknown - // functions, changing this field has no effect. - // - // Deprecated: Use the SetValue function to create a known Set value or - // use the Elements or ElementsAs methods to retrieve the Set elements - // instead. - Elems []attr.Value - - // ElemType is the tftypes.Type of the elements in the set. All - // elements in the set must be of this type. - // - // Deprecated: Use the SetValue, SetNull, or SetUnknown functions - // to create a Set or use the ElementType method to retrieve the - // Set element type instead. - ElemType attr.Type - // elements is the collection of known values in the Set. elements []attr.Value // elementType is the type of the elements in the Set. elementType attr.Type - // state represents whether the Set is null, unknown, or known. During the - // exported field deprecation period, this state can also be "deprecated", - // which remains the zero-value for compatibility to ensure exported field - // updates take effect. The zero-value will be changed to null in a future - // version. - state valueState + // state represents whether the value is null, unknown, or known. The + // zero-value is null. + state attr.ValueState } // Elements returns the collection of elements for the Set. Returns nil if the // Set is null or unknown. func (s Set) Elements() []attr.Value { - if s.state == valueStateDeprecated { - return s.Elems - } - return s.elements } @@ -416,10 +346,6 @@ func (s Set) ElementsAs(ctx context.Context, target interface{}, allowUnhandled // ElementType returns the element type for the Set. func (s Set) ElementType(_ context.Context) attr.Type { - if s.state == valueStateDeprecated { - return s.ElemType - } - return s.elementType } @@ -430,32 +356,10 @@ func (s Set) Type(ctx context.Context) attr.Type { // ToTerraformValue returns the data contained in the Set as a tftypes.Value. func (s Set) ToTerraformValue(ctx context.Context) (tftypes.Value, error) { - if s.state == valueStateDeprecated && s.ElemType == nil { - return tftypes.Value{}, fmt.Errorf("cannot convert Set to tftypes.Value if ElemType field is not set") - } setType := tftypes.Set{ElementType: s.ElementType(ctx).TerraformType(ctx)} switch s.state { - case valueStateDeprecated: - if s.Unknown { - return tftypes.NewValue(setType, tftypes.UnknownValue), nil - } - if s.Null { - return tftypes.NewValue(setType, nil), nil - } - vals := make([]tftypes.Value, 0, len(s.Elems)) - for _, elem := range s.Elems { - val, err := elem.ToTerraformValue(ctx) - if err != nil { - return tftypes.NewValue(setType, tftypes.UnknownValue), err - } - vals = append(vals, val) - } - if err := tftypes.ValidateValue(setType, vals); err != nil { - return tftypes.NewValue(setType, tftypes.UnknownValue), err - } - return tftypes.NewValue(setType, vals), nil - case valueStateKnown: + case attr.ValueStateKnown: vals := make([]tftypes.Value, 0, len(s.elements)) for _, elem := range s.elements { @@ -473,9 +377,9 @@ func (s Set) ToTerraformValue(ctx context.Context) (tftypes.Value, error) { } return tftypes.NewValue(setType, vals), nil - case valueStateNull: + case attr.ValueStateNull: return tftypes.NewValue(setType, nil), nil - case valueStateUnknown: + case attr.ValueStateUnknown: return tftypes.NewValue(setType, tftypes.UnknownValue), nil default: panic(fmt.Sprintf("unhandled Set state in ToTerraformValue: %s", s.state)) @@ -486,49 +390,33 @@ func (s Set) ToTerraformValue(ctx context.Context) (tftypes.Value, error) { // (same type and same value) to the attr.Value passed as an argument. func (s Set) Equal(o attr.Value) bool { other, ok := o.(Set) + if !ok { return false } - if s.state != other.state { - return false - } - if s.state == valueStateKnown { - if !s.elementType.Equal(other.elementType) { - return false - } - - if len(s.elements) != len(other.elements) { - return false - } - - for _, elem := range s.elements { - if !other.contains(elem) { - return false - } - } - return true - } - if s.Unknown != other.Unknown { + if !s.elementType.Equal(other.elementType) { return false } - if s.Null != other.Null { - return false - } - if s.ElemType == nil && other.ElemType != nil { + + if s.state != other.state { return false } - if s.ElemType != nil && !s.ElemType.Equal(other.ElemType) { - return false + + if s.state != attr.ValueStateKnown { + return true } - if len(s.Elems) != len(other.Elems) { + + if len(s.elements) != len(other.elements) { return false } - for _, elem := range s.Elems { + + for _, elem := range s.elements { if !other.contains(elem) { return false } } + return true } @@ -544,22 +432,14 @@ func (s Set) contains(v attr.Value) bool { // IsNull returns true if the Set represents a null value. func (s Set) IsNull() bool { - if s.state == valueStateNull { - return true - } - - return s.state == valueStateDeprecated && s.Null + return s.state == attr.ValueStateNull } // IsUnknown returns true if the Set represents a currently unknown value. // Returns false if the Set has a known number of elements, even if all are // unknown values. func (s Set) IsUnknown() bool { - if s.state == valueStateUnknown { - return true - } - - return s.state == valueStateDeprecated && s.Unknown + return s.state == attr.ValueStateUnknown } // String returns a human-readable representation of the Set value. diff --git a/types/set_test.go b/types/set_test.go index 405284ccd..56cd4c633 100644 --- a/types/set_test.go +++ b/types/set_test.go @@ -90,13 +90,13 @@ func TestSetTypeValueFromTerraform(t *testing.T) { tftypes.NewValue(tftypes.String, "hello"), tftypes.NewValue(tftypes.String, "world"), }), - expected: Set{ - ElemType: StringType, - Elems: []attr.Value{ - String{Value: "hello"}, - String{Value: "world"}, + expected: SetValueMust( + StringType, + []attr.Value{ + StringValue("hello"), + StringValue("world"), }, - }, + ), }, "set-of-duplicate-strings": { receiver: SetType{ @@ -110,13 +110,13 @@ func TestSetTypeValueFromTerraform(t *testing.T) { }), // Duplicate validation does not occur during this method. // This is okay, as tftypes allows duplicates. - expected: Set{ - ElemType: StringType, - Elems: []attr.Value{ - String{Value: "hello"}, - String{Value: "hello"}, + expected: SetValueMust( + StringType, + []attr.Value{ + StringValue("hello"), + StringValue("hello"), }, - }, + ), }, "unknown-set": { receiver: SetType{ @@ -125,10 +125,7 @@ func TestSetTypeValueFromTerraform(t *testing.T) { input: tftypes.NewValue(tftypes.Set{ ElementType: tftypes.String, }, tftypes.UnknownValue), - expected: Set{ - ElemType: StringType, - Unknown: true, - }, + expected: SetUnknown(StringType), }, "partially-unknown-set": { receiver: SetType{ @@ -140,13 +137,13 @@ func TestSetTypeValueFromTerraform(t *testing.T) { tftypes.NewValue(tftypes.String, "hello"), tftypes.NewValue(tftypes.String, tftypes.UnknownValue), }), - expected: Set{ - ElemType: StringType, - Elems: []attr.Value{ - String{Value: "hello"}, - String{Unknown: true}, + expected: SetValueMust( + StringType, + []attr.Value{ + StringValue("hello"), + StringUnknown(), }, - }, + ), }, "null-set": { receiver: SetType{ @@ -155,10 +152,7 @@ func TestSetTypeValueFromTerraform(t *testing.T) { input: tftypes.NewValue(tftypes.Set{ ElementType: tftypes.String, }, nil), - expected: Set{ - ElemType: StringType, - Null: true, - }, + expected: SetNull(StringType), }, "partially-null-set": { receiver: SetType{ @@ -170,13 +164,13 @@ func TestSetTypeValueFromTerraform(t *testing.T) { tftypes.NewValue(tftypes.String, "hello"), tftypes.NewValue(tftypes.String, nil), }), - expected: Set{ - ElemType: StringType, - Elems: []attr.Value{ - String{Value: "hello"}, - String{Null: true}, + expected: SetValueMust( + StringType, + []attr.Value{ + StringValue("hello"), + StringNull(), }, - }, + ), }, "wrong-type": { receiver: SetType{ @@ -200,11 +194,8 @@ func TestSetTypeValueFromTerraform(t *testing.T) { receiver: SetType{ ElemType: StringType, }, - input: tftypes.NewValue(nil, nil), - expected: Set{ - ElemType: StringType, - Null: true, - }, + input: tftypes.NewValue(nil, nil), + expected: SetNull(StringType), }, } for name, test := range tests { @@ -296,12 +287,13 @@ func TestSetElementsAs_stringSlice(t *testing.T) { var stringSlice []string expected := []string{"hello", "world"} - diags := (Set{ - ElemType: StringType, - Elems: []attr.Value{ - String{Value: "hello"}, - String{Value: "world"}, - }}).ElementsAs(context.Background(), &stringSlice, false) + diags := SetValueMust( + StringType, + []attr.Value{ + StringValue("hello"), + StringValue("world"), + }, + ).ElementsAs(context.Background(), &stringSlice, false) if diags.HasError() { t.Errorf("Unexpected error: %s", diags) } @@ -315,16 +307,17 @@ func TestSetElementsAs_attributeValueSlice(t *testing.T) { var stringSlice []String expected := []String{ - {Value: "hello"}, - {Value: "world"}, + StringValue("hello"), + StringValue("world"), } - diags := (Set{ - ElemType: StringType, - Elems: []attr.Value{ - String{Value: "hello"}, - String{Value: "world"}, - }}).ElementsAs(context.Background(), &stringSlice, false) + diags := SetValueMust( + StringType, + []attr.Value{ + StringValue("hello"), + StringValue("world"), + }, + ).ElementsAs(context.Background(), &stringSlice, false) if diags.HasError() { t.Errorf("Unexpected error: %s", diags) } @@ -651,18 +644,18 @@ func TestSetValueFrom(t *testing.T) { "valid-StringType-[]attr.Value-empty": { elementType: StringType, elements: []attr.Value{}, - expected: Set{ - ElemType: StringType, - Elems: []attr.Value{}, - }, + expected: SetValueMust( + StringType, + []attr.Value{}, + ), }, "valid-StringType-[]types.String-empty": { elementType: StringType, elements: []String{}, - expected: Set{ - ElemType: StringType, - Elems: []attr.Value{}, - }, + expected: SetValueMust( + StringType, + []attr.Value{}, + ), }, "valid-StringType-[]types.String": { elementType: StringType, @@ -671,14 +664,14 @@ func TestSetValueFrom(t *testing.T) { StringUnknown(), StringValue("test"), }, - expected: Set{ - ElemType: StringType, - Elems: []attr.Value{ - String{Null: true}, - String{Unknown: true}, - String{Value: "test"}, + expected: SetValueMust( + StringType, + []attr.Value{ + StringNull(), + StringUnknown(), + StringValue("test"), }, - }, + ), }, "valid-StringType-[]*string": { elementType: StringType, @@ -687,14 +680,14 @@ func TestSetValueFrom(t *testing.T) { pointer("test1"), pointer("test2"), }, - expected: Set{ - ElemType: StringType, - Elems: []attr.Value{ - String{Null: true}, - String{Value: "test1"}, - String{Value: "test2"}, + expected: SetValueMust( + StringType, + []attr.Value{ + StringNull(), + StringValue("test1"), + StringValue("test2"), }, - }, + ), }, "valid-StringType-[]string": { elementType: StringType, @@ -702,13 +695,13 @@ func TestSetValueFrom(t *testing.T) { "test1", "test2", }, - expected: Set{ - ElemType: StringType, - Elems: []attr.Value{ - String{Value: "test1"}, - String{Value: "test2"}, + expected: SetValueMust( + StringType, + []attr.Value{ + StringValue("test1"), + StringValue("test2"), }, - }, + ), }, "invalid-not-slice": { elementType: StringType, @@ -757,84 +750,6 @@ func TestSetValueFrom(t *testing.T) { } } -// This test verifies the assumptions that creating the Value via function then -// setting the fields directly has no effects. -func TestSetValue_DeprecatedFieldSetting(t *testing.T) { - t.Parallel() - - knownSet := SetValueMust(StringType, []attr.Value{StringValue("test")}) - - knownSet.Null = true - - if knownSet.IsNull() { - t.Error("unexpected null update after Null field setting") - } - - knownSet.Unknown = true - - if knownSet.IsUnknown() { - t.Error("unexpected unknown update after Unknown field setting") - } - - knownSet.Elems = []attr.Value{StringValue("not-test")} - - if knownSet.Elements()[0].Equal(StringValue("not-test")) { - t.Error("unexpected value update after Value field setting") - } -} - -// This test verifies the assumptions that creating the Value via function then -// setting the fields directly has no effects. -func TestSetNull_DeprecatedFieldSetting(t *testing.T) { - t.Parallel() - - nullSet := SetNull(StringType) - - nullSet.Null = false - - if !nullSet.IsNull() { - t.Error("unexpected null update after Null field setting") - } - - nullSet.Unknown = true - - if nullSet.IsUnknown() { - t.Error("unexpected unknown update after Unknown field setting") - } - - nullSet.Elems = []attr.Value{StringValue("test")} - - if len(nullSet.Elements()) > 0 { - t.Error("unexpected value update after Value field setting") - } -} - -// This test verifies the assumptions that creating the Value via function then -// setting the fields directly has no effects. -func TestSetUnknown_DeprecatedFieldSetting(t *testing.T) { - t.Parallel() - - unknownSet := SetUnknown(StringType) - - unknownSet.Null = true - - if unknownSet.IsNull() { - t.Error("unexpected null update after Null field setting") - } - - unknownSet.Unknown = false - - if !unknownSet.IsUnknown() { - t.Error("unexpected unknown update after Unknown field setting") - } - - unknownSet.Elems = []attr.Value{StringValue("test")} - - if len(unknownSet.Elements()) > 0 { - t.Error("unexpected value update after Value field setting") - } -} - func TestSetToTerraformValue(t *testing.T) { t.Parallel() @@ -906,78 +821,6 @@ func TestSetToTerraformValue(t *testing.T) { input: SetNull(StringType), expectation: tftypes.NewValue(tftypes.Set{ElementType: tftypes.String}, nil), }, - "deprecated-known": { - input: Set{ - ElemType: StringType, - Elems: []attr.Value{ - String{Value: "hello"}, - String{Value: "world"}, - }, - }, - expectation: tftypes.NewValue(tftypes.Set{ElementType: tftypes.String}, []tftypes.Value{ - tftypes.NewValue(tftypes.String, "hello"), - tftypes.NewValue(tftypes.String, "world"), - }), - }, - "deprecated-known-duplicates": { - input: Set{ - ElemType: StringType, - Elems: []attr.Value{ - String{Value: "hello"}, - String{Value: "hello"}, - }, - }, - // Duplicate validation does not occur during this method. - // This is okay, as tftypes allows duplicates. - expectation: tftypes.NewValue(tftypes.Set{ElementType: tftypes.String}, []tftypes.Value{ - tftypes.NewValue(tftypes.String, "hello"), - tftypes.NewValue(tftypes.String, "hello"), - }), - }, - "deprecated-unknown": { - input: Set{ElemType: StringType, Unknown: true}, - expectation: tftypes.NewValue(tftypes.Set{ElementType: tftypes.String}, tftypes.UnknownValue), - }, - "deprecated-null": { - input: Set{ElemType: StringType, Null: true}, - expectation: tftypes.NewValue(tftypes.Set{ElementType: tftypes.String}, nil), - }, - "deprecated-known-partial-unknown": { - input: Set{ - ElemType: StringType, - Elems: []attr.Value{ - String{Unknown: true}, - String{Value: "hello, world"}, - }, - }, - expectation: tftypes.NewValue(tftypes.Set{ElementType: tftypes.String}, []tftypes.Value{ - tftypes.NewValue(tftypes.String, tftypes.UnknownValue), - tftypes.NewValue(tftypes.String, "hello, world"), - }), - }, - "deprecated-known-partial-null": { - input: Set{ - ElemType: StringType, - Elems: []attr.Value{ - String{Null: true}, - String{Value: "hello, world"}, - }, - }, - expectation: tftypes.NewValue(tftypes.Set{ElementType: tftypes.String}, []tftypes.Value{ - tftypes.NewValue(tftypes.String, nil), - tftypes.NewValue(tftypes.String, "hello, world"), - }), - }, - "no-elem-type": { - input: Set{ - Elems: []attr.Value{ - String{Value: "hello"}, - String{Value: "world"}, - }, - }, - expectation: tftypes.Value{}, - expectedErr: "cannot convert Set to tftypes.Value if ElemType field is not set", - }, } for name, test := range tests { name, test := name, test @@ -1021,26 +864,14 @@ func TestSetElements(t *testing.T) { input: SetValueMust(StringType, []attr.Value{StringValue("test")}), expected: []attr.Value{StringValue("test")}, }, - "deprecated-known": { - input: Set{ElemType: StringType, Elems: []attr.Value{StringValue("test")}}, - expected: []attr.Value{StringValue("test")}, - }, "null": { input: SetNull(StringType), expected: nil, }, - "deprecated-null": { - input: Set{ElemType: StringType, Null: true}, - expected: nil, - }, "unknown": { input: SetUnknown(StringType), expected: nil, }, - "deprecated-unknown": { - input: Set{ElemType: StringType, Unknown: true}, - expected: nil, - }, } for name, testCase := range testCases { @@ -1069,26 +900,14 @@ func TestSetElementType(t *testing.T) { input: SetValueMust(StringType, []attr.Value{StringValue("test")}), expected: StringType, }, - "deprecated-known": { - input: Set{ElemType: StringType, Elems: []attr.Value{StringValue("test")}}, - expected: StringType, - }, "null": { input: SetNull(StringType), expected: StringType, }, - "deprecated-null": { - input: Set{ElemType: StringType, Null: true}, - expected: StringType, - }, "unknown": { input: SetUnknown(StringType), expected: StringType, }, - "deprecated-unknown": { - input: Set{ElemType: StringType, Unknown: true}, - expected: StringType, - }, } for name, testCase := range testCases { @@ -1268,231 +1087,6 @@ func TestSetEqual(t *testing.T) { input: nil, expected: false, }, - "known-deprecated-known": { - receiver: SetValueMust( - StringType, - []attr.Value{ - StringValue("hello"), - StringValue("world"), - }, - ), - input: Set{ - ElemType: StringType, - Elems: []attr.Value{ - String{Value: "hello"}, - String{Value: "world"}, - }, - }, - expected: false, // intentional - }, - "known-deprecated-unknown": { - receiver: SetValueMust( - StringType, - []attr.Value{ - StringValue("hello"), - StringValue("world"), - }, - ), - input: Set{ElemType: StringType, Unknown: true}, - expected: false, - }, - "known-deprecated-null": { - receiver: SetValueMust( - StringType, - []attr.Value{ - StringValue("hello"), - StringValue("world"), - }, - ), - input: Set{ElemType: StringType, Null: true}, - expected: false, - }, - "deprecated-known-deprecated-known": { - receiver: Set{ - ElemType: StringType, - Elems: []attr.Value{ - String{Value: "hello"}, - String{Value: "world"}, - }, - }, - input: Set{ - ElemType: StringType, - Elems: []attr.Value{ - String{Value: "hello"}, - String{Value: "world"}, - }, - }, - expected: true, - }, - "deprecated-known-deprecated-known-diff-value": { - receiver: Set{ - ElemType: StringType, - Elems: []attr.Value{ - String{Value: "hello"}, - String{Value: "world"}, - }, - }, - input: Set{ - ElemType: StringType, - Elems: []attr.Value{ - String{Value: "goodnight"}, - String{Value: "moon"}, - }, - }, - expected: false, - }, - "deprecated-known-deprecated-known-diff-length": { - receiver: Set{ - ElemType: StringType, - Elems: []attr.Value{ - String{Value: "hello"}, - String{Value: "world"}, - }, - }, - input: Set{ - ElemType: StringType, - Elems: []attr.Value{ - String{Value: "hello"}, - String{Value: "world"}, - String{Value: "test"}, - }, - }, - expected: false, - }, - "deprecated-known-deprecated-known-diff-type": { - receiver: Set{ - ElemType: StringType, - Elems: []attr.Value{ - String{Value: "hello"}, - String{Value: "world"}, - }, - }, - input: Set{ - ElemType: BoolType, - Elems: []attr.Value{ - Bool{Value: false}, - Bool{Value: true}, - }, - }, - expected: false, - }, - "deprecated-known-deprecated-known-diff-unknown": { - receiver: Set{ - ElemType: StringType, - Elems: []attr.Value{ - String{Value: "hello"}, - String{Unknown: true}, - }, - }, - input: Set{ - ElemType: StringType, - Elems: []attr.Value{ - String{Value: "hello"}, - String{Value: "world"}, - }, - }, - expected: false, - }, - "deprecated-known-deprecated-known-diff-null": { - receiver: Set{ - ElemType: StringType, - Elems: []attr.Value{ - String{Value: "hello"}, - String{Null: true}, - }, - }, - input: Set{ - ElemType: StringType, - Elems: []attr.Value{ - String{Value: "hello"}, - String{Value: "world"}, - }, - }, - expected: false, - }, - "deprecated-known-deprecated-unknown": { - receiver: Set{ - ElemType: StringType, - Elems: []attr.Value{ - String{Value: "hello"}, - String{Value: "world"}, - }, - }, - input: Set{Unknown: true}, - expected: false, - }, - "deprecated-known-deprecated-null": { - receiver: Set{ - ElemType: StringType, - Elems: []attr.Value{ - String{Value: "hello"}, - String{Value: "world"}, - }, - }, - input: Set{Null: true}, - expected: false, - }, - "deprecated-known-known": { - receiver: Set{ - ElemType: StringType, - Elems: []attr.Value{ - String{Value: "hello"}, - String{Value: "world"}, - }, - }, - input: SetValueMust( - StringType, - []attr.Value{ - StringValue("hello"), - StringValue("world"), - }, - ), - expected: false, // intentional - }, - "deprecated-known-unknown": { - receiver: Set{ - ElemType: StringType, - Elems: []attr.Value{ - String{Value: "hello"}, - String{Value: "world"}, - }, - }, - input: SetUnknown(StringType), - expected: false, - }, - "deprecated-known-null": { - receiver: Set{ - ElemType: StringType, - Elems: []attr.Value{ - String{Value: "hello"}, - String{Value: "world"}, - }, - }, - input: SetNull(StringType), - expected: false, - }, - "deprecated-known-diff-type": { - receiver: Set{ - ElemType: StringType, - Elems: []attr.Value{ - String{Value: "hello"}, - String{Value: "world"}, - }, - }, - input: String{Value: "hello, world"}, - expected: false, - }, - "deprecated-known-nil": { - receiver: Set{ - ElemType: StringType, - Elems: []attr.Value{ - String{Value: "hello"}, - String{Value: "world"}, - }, - }, - input: nil, - expected: false, - }, } for name, test := range tests { name, test := name, test @@ -1518,30 +1112,14 @@ func TestSetIsNull(t *testing.T) { input: SetValueMust(StringType, []attr.Value{StringValue("test")}), expected: false, }, - "deprecated-known": { - input: Set{ElemType: StringType, Elems: []attr.Value{StringValue("test")}}, - expected: false, - }, "null": { input: SetNull(StringType), expected: true, }, - "deprecated-null": { - input: Set{ElemType: StringType, Null: true}, - expected: true, - }, "unknown": { input: SetUnknown(StringType), expected: false, }, - "deprecated-unknown": { - input: Set{ElemType: StringType, Unknown: true}, - expected: false, - }, - "deprecated-invalid": { - input: Set{ElemType: StringType, Null: true, Unknown: true}, - expected: true, - }, } for name, testCase := range testCases { @@ -1570,30 +1148,14 @@ func TestSetIsUnknown(t *testing.T) { input: SetValueMust(StringType, []attr.Value{StringValue("test")}), expected: false, }, - "deprecated-known": { - input: Set{ElemType: StringType, Elems: []attr.Value{StringValue("test")}}, - expected: false, - }, "null": { input: SetNull(StringType), expected: false, }, - "deprecated-null": { - input: Set{ElemType: StringType, Null: true}, - expected: false, - }, "unknown": { input: SetUnknown(StringType), expected: true, }, - "deprecated-unknown": { - input: Set{ElemType: StringType, Unknown: true}, - expected: true, - }, - "deprecated-invalid": { - input: Set{ElemType: StringType, Null: true, Unknown: true}, - expected: true, - }, } for name, testCase := range testCases { @@ -1661,51 +1223,9 @@ func TestSetString(t *testing.T) { input: SetNull(StringType), expectation: "", }, - "deprecated-known": { - input: Set{ - ElemType: StringType, - Elems: []attr.Value{ - String{Value: "hello"}, - String{Value: "world"}, - }, - }, - expectation: `["hello","world"]`, - }, - "deprecated-known-set-of-sets": { - input: Set{ - ElemType: SetType{ - ElemType: StringType, - }, - Elems: []attr.Value{ - Set{ - ElemType: StringType, - Elems: []attr.Value{ - String{Value: "hello"}, - String{Value: "world"}, - }, - }, - Set{ - ElemType: StringType, - Elems: []attr.Value{ - String{Value: "foo"}, - String{Value: "bar"}, - }, - }, - }, - }, - expectation: `[["hello","world"],["foo","bar"]]`, - }, - "deprecated-unknown": { - input: Set{Unknown: true}, - expectation: "", - }, - "deprecated-null": { - input: Set{Null: true}, - expectation: "", - }, - "default-empty": { + "zero-value": { input: Set{}, - expectation: "[]", + expectation: "", }, } @@ -1776,52 +1296,6 @@ func TestSetType(t *testing.T) { input: SetNull(StringType), expectation: SetType{ElemType: StringType}, }, - "deprecated-known": { - input: Set{ - ElemType: StringType, - Elems: []attr.Value{ - String{Value: "hello"}, - String{Value: "world"}, - }, - }, - expectation: SetType{ElemType: StringType}, - }, - "deprecated-known-set-of-sets": { - input: Set{ - ElemType: SetType{ - ElemType: StringType, - }, - Elems: []attr.Value{ - Set{ - ElemType: StringType, - Elems: []attr.Value{ - String{Value: "hello"}, - String{Value: "world"}, - }, - }, - Set{ - ElemType: StringType, - Elems: []attr.Value{ - String{Value: "foo"}, - String{Value: "bar"}, - }, - }, - }, - }, - expectation: SetType{ - ElemType: SetType{ - ElemType: StringType, - }, - }, - }, - "deprecated-unknown": { - input: Set{ElemType: StringType, Unknown: true}, - expectation: SetType{ElemType: StringType}, - }, - "deprecated-null": { - input: Set{ElemType: StringType, Null: true}, - expectation: SetType{ElemType: StringType}, - }, } for name, test := range tests { diff --git a/types/string.go b/types/string.go index 16c41ec45..9239cb403 100644 --- a/types/string.go +++ b/types/string.go @@ -19,7 +19,7 @@ var ( // creating a String with this function has no effect. func StringNull() String { return String{ - state: valueStateNull, + state: attr.ValueStateNull, } } @@ -30,7 +30,7 @@ func StringNull() String { // creating a String with this function has no effect. func StringUnknown() String { return String{ - state: valueStateUnknown, + state: attr.ValueStateUnknown, } } @@ -41,74 +41,31 @@ func StringUnknown() String { // creating a String with this function has no effect. func StringValue(value string) String { return String{ - state: valueStateKnown, + state: attr.ValueStateKnown, value: value, } } func stringValueFromTerraform(ctx context.Context, in tftypes.Value) (attr.Value, error) { if !in.IsKnown() { - return String{ - Unknown: true, - state: valueStateDeprecated, - }, nil + return StringUnknown(), nil } if in.IsNull() { - return String{ - Null: true, - state: valueStateDeprecated, - }, nil + return StringNull(), nil } var s string err := in.As(&s) if err != nil { return nil, err } - return String{ - Value: s, - state: valueStateDeprecated, - }, nil + return StringValue(s), nil } // String represents a UTF-8 string value. type String struct { - // Unknown will be true if the value is not yet known. - // - // If the String was created with the StringValue, StringNull, or StringUnknown - // functions, changing this field has no effect. - // - // Deprecated: Use the StringUnknown function to create an unknown String - // value or use the IsUnknown method to determine whether the String value - // is unknown instead. - Unknown bool - - // Null will be true if the value was not set, or was explicitly set to - // null. - // - // If the String was created with the StringValue, StringNull, or StringUnknown - // functions, changing this field has no effect. - // - // Deprecated: Use the StringNull function to create a null String value or - // use the IsNull method to determine whether the String value is null - // instead. - Null bool - - // Value contains the set value, as long as Unknown and Null are both - // false. - // - // If the String was created with the StringValue, StringNull, or StringUnknown - // functions, changing this field has no effect. - // - // Deprecated: Use the StringValue function to create a known String value or - // use the ValueString method to retrieve the String value instead. - Value string - - // state represents whether the String is null, unknown, or known. During the - // exported field deprecation period, this state can also be "deprecated", - // which remains the zero-value for compatibility to ensure exported field - // updates take effect. The zero-value will be changed to null in a future - // version. - state valueState + // state represents whether the value is null, unknown, or known. The + // zero-value is null. + state attr.ValueState // value contains the known value, if not null or unknown. value string @@ -122,26 +79,15 @@ func (s String) Type(_ context.Context) attr.Type { // ToTerraformValue returns the data contained in the *String as a tftypes.Value. func (s String) ToTerraformValue(_ context.Context) (tftypes.Value, error) { switch s.state { - case valueStateDeprecated: - if s.Null { - return tftypes.NewValue(tftypes.String, nil), nil - } - if s.Unknown { - return tftypes.NewValue(tftypes.String, tftypes.UnknownValue), nil - } - if err := tftypes.ValidateValue(tftypes.String, s.Value); err != nil { - return tftypes.NewValue(tftypes.String, tftypes.UnknownValue), err - } - return tftypes.NewValue(tftypes.String, s.Value), nil - case valueStateKnown: + case attr.ValueStateKnown: if err := tftypes.ValidateValue(tftypes.String, s.value); err != nil { return tftypes.NewValue(tftypes.String, tftypes.UnknownValue), err } return tftypes.NewValue(tftypes.String, s.value), nil - case valueStateNull: + case attr.ValueStateNull: return tftypes.NewValue(tftypes.String, nil), nil - case valueStateUnknown: + case attr.ValueStateUnknown: return tftypes.NewValue(tftypes.String, tftypes.UnknownValue), nil default: panic(fmt.Sprintf("unhandled String state in ToTerraformValue: %s", s.state)) @@ -151,40 +97,30 @@ func (s String) ToTerraformValue(_ context.Context) (tftypes.Value, error) { // Equal returns true if `other` is a String and has the same value as `s`. func (s String) Equal(other attr.Value) bool { o, ok := other.(String) + if !ok { return false } + if s.state != o.state { return false } - if s.state == valueStateKnown { - return s.value == o.value - } - if s.Unknown != o.Unknown { - return false - } - if s.Null != o.Null { - return false + + if s.state != attr.ValueStateKnown { + return true } - return s.Value == o.Value + + return s.value == o.value } // IsNull returns true if the String represents a null value. func (s String) IsNull() bool { - if s.state == valueStateNull { - return true - } - - return s.state == valueStateDeprecated && s.Null + return s.state == attr.ValueStateNull } // IsUnknown returns true if the String represents a currently unknown value. func (s String) IsUnknown() bool { - if s.state == valueStateUnknown { - return true - } - - return s.state == valueStateDeprecated && s.Unknown + return s.state == attr.ValueStateUnknown } // String returns a human-readable representation of the String value. Use @@ -201,19 +137,11 @@ func (s String) String() string { return attr.NullValueString } - if s.state == valueStateKnown { - return fmt.Sprintf("%q", s.value) - } - - return fmt.Sprintf("%q", s.Value) + return fmt.Sprintf("%q", s.value) } // ValueString returns the known string value. If String is null or unknown, returns // "". func (s String) ValueString() string { - if s.state == valueStateDeprecated { - return s.Value - } - return s.value } diff --git a/types/string_test.go b/types/string_test.go index d0b978443..f87e76416 100644 --- a/types/string_test.go +++ b/types/string_test.go @@ -2,7 +2,6 @@ package types import ( "context" - "math/big" "testing" "github.com/google/go-cmp/cmp" @@ -10,84 +9,6 @@ import ( "github.com/hashicorp/terraform-plugin-go/tftypes" ) -// This test verifies the assumptions that creating the Value via function then -// setting the fields directly has no effects. -func TestStringValueDeprecatedFieldSetting(t *testing.T) { - t.Parallel() - - knownString := StringValue("test") - - knownString.Null = true - - if knownString.IsNull() { - t.Error("unexpected null update after Null field setting") - } - - knownString.Unknown = true - - if knownString.IsUnknown() { - t.Error("unexpected unknown update after Unknown field setting") - } - - knownString.Value = "not-test" - - if knownString.ValueString() == "not-test" { - t.Error("unexpected value update after Value field setting") - } -} - -// This test verifies the assumptions that creating the Value via function then -// setting the fields directly has no effects. -func TestStringNullDeprecatedFieldSetting(t *testing.T) { - t.Parallel() - - nullString := StringNull() - - nullString.Null = false - - if !nullString.IsNull() { - t.Error("unexpected null update after Null field setting") - } - - nullString.Unknown = true - - if nullString.IsUnknown() { - t.Error("unexpected unknown update after Unknown field setting") - } - - nullString.Value = "test" - - if nullString.ValueString() == "test" { - t.Error("unexpected value update after Value field setting") - } -} - -// This test verifies the assumptions that creating the Value via function then -// setting the fields directly has no effects. -func TestStringUnknownDeprecatedFieldSetting(t *testing.T) { - t.Parallel() - - unknownString := StringUnknown() - - unknownString.Null = true - - if unknownString.IsNull() { - t.Error("unexpected null update after Null field setting") - } - - unknownString.Unknown = false - - if !unknownString.IsUnknown() { - t.Error("unexpected unknown update after Unknown field setting") - } - - unknownString.Value = "test" - - if unknownString.ValueString() == "test" { - t.Error("unexpected value update after Value field setting") - } -} - func TestStringValueFromTerraform(t *testing.T) { t.Parallel() @@ -103,15 +24,15 @@ func testStringValueFromTerraform(t *testing.T, direct bool) { tests := map[string]testCase{ "true": { input: tftypes.NewValue(tftypes.String, "hello"), - expectation: String{Value: "hello"}, + expectation: StringValue("hello"), }, "unknown": { input: tftypes.NewValue(tftypes.String, tftypes.UnknownValue), - expectation: String{Unknown: true}, + expectation: StringUnknown(), }, "null": { input: tftypes.NewValue(tftypes.String, nil), - expectation: String{Null: true}, + expectation: StringNull(), }, "wrongType": { input: tftypes.NewValue(tftypes.Number, 123), @@ -179,18 +100,6 @@ func TestStringToTerraformValue(t *testing.T) { input: StringNull(), expectation: tftypes.NewValue(tftypes.String, nil), }, - "deprecated-known": { - input: String{Value: "hello"}, - expectation: tftypes.NewValue(tftypes.String, "hello"), - }, - "deprecated-unknown": { - input: String{Unknown: true}, - expectation: tftypes.NewValue(tftypes.String, tftypes.UnknownValue), - }, - "deprecated-null": { - input: String{Null: true}, - expectation: tftypes.NewValue(tftypes.String, nil), - }, } for name, test := range tests { name, test := name, test @@ -269,136 +178,6 @@ func TestStringEqual(t *testing.T) { candidate: StringNull(), expectation: true, }, - "deprecated-known-known-same": { - input: String{Value: "test"}, - candidate: StringValue("test"), - expectation: false, // intentional - }, - "deprecated-known-known-diff": { - input: String{Value: "test"}, - candidate: StringValue("not-test"), - expectation: false, - }, - "deprecated-known-unknown": { - input: String{Value: "test"}, - candidate: StringUnknown(), - expectation: false, - }, - "deprecated-known-null": { - input: String{Value: "test"}, - candidate: StringNull(), - expectation: false, - }, - "deprecated-known-deprecated-known-same": { - input: String{Value: "hello"}, - candidate: String{Value: "hello"}, - expectation: true, - }, - "deprecated-known-deprecated-known-diff": { - input: String{Value: "hello"}, - candidate: String{Value: "world"}, - expectation: false, - }, - "deprecated-known-deprecated-unknown": { - input: String{Value: "hello"}, - candidate: String{Unknown: true}, - expectation: false, - }, - "deprecated-known-deprecated-null": { - input: String{Value: "hello"}, - candidate: String{Null: true}, - expectation: false, - }, - "deprecated-known-wrongType": { - input: String{Value: "hello"}, - candidate: Number{Value: big.NewFloat(123)}, - expectation: false, - }, - "deprecated-known-nil": { - input: String{Value: "hello"}, - candidate: nil, - expectation: false, - }, - "deprecated-unknown-value": { - input: String{Unknown: true}, - candidate: StringValue("test"), - expectation: false, - }, - "deprecated-unknown-unknown": { - input: String{Unknown: true}, - candidate: StringUnknown(), - expectation: false, // intentional - }, - "deprecated-unknown-null": { - input: String{Unknown: true}, - candidate: StringNull(), - expectation: false, - }, - "deprecated-unknown-deprecated-known": { - input: String{Unknown: true}, - candidate: String{Value: "hello"}, - expectation: false, - }, - "deprecated-unknown-deprecated-unknown": { - input: String{Unknown: true}, - candidate: String{Unknown: true}, - expectation: true, - }, - "deprecated-unknown-deprecated-null": { - input: String{Unknown: true}, - candidate: String{Null: true}, - expectation: false, - }, - "deprecated-unknown-wrongType": { - input: String{Unknown: true}, - candidate: Number{Value: big.NewFloat(123)}, - expectation: false, - }, - "deprecated-unknown-nil": { - input: String{Unknown: true}, - candidate: nil, - expectation: false, - }, - "deprecated-null-known": { - input: String{Null: true}, - candidate: StringValue("test"), - expectation: false, - }, - "deprecated-null-unknown": { - input: String{Null: true}, - candidate: StringUnknown(), - expectation: false, - }, - "deprecated-null-null": { - input: String{Null: true}, - candidate: StringNull(), - expectation: false, // intentional - }, - "deprecated-null-deprecated-known": { - input: String{Null: true}, - candidate: String{Value: "hello"}, - expectation: false, - }, - "deprecated-null-deprecated-unknown": { - input: String{Null: true}, - candidate: String{Unknown: true}, - expectation: false, - }, - "deprecated-null-deprecated-null": { - input: String{Null: true}, - candidate: String{Null: true}, - expectation: true, - }, - "deprecated-null-wrongType": { - input: String{Null: true}, - candidate: Number{Value: big.NewFloat(123)}, - expectation: false, - }, - "deprecated-null-nil": { - input: String{Null: true}, - candidate: nil, - expectation: false, - }, } for name, test := range tests { name, test := name, test @@ -424,30 +203,14 @@ func TestStringIsNull(t *testing.T) { input: StringValue("test"), expected: false, }, - "deprecated-known": { - input: String{Value: "test"}, - expected: false, - }, "null": { input: StringNull(), expected: true, }, - "deprecated-null": { - input: String{Null: true}, - expected: true, - }, "unknown": { input: StringUnknown(), expected: false, }, - "deprecated-unknown": { - input: String{Unknown: true}, - expected: false, - }, - "deprecated-invalid": { - input: String{Null: true, Unknown: true}, - expected: true, - }, } for name, testCase := range testCases { @@ -476,30 +239,14 @@ func TestStringIsUnknown(t *testing.T) { input: StringValue("test"), expected: false, }, - "deprecated-known": { - input: String{Value: "test"}, - expected: false, - }, "null": { input: StringNull(), expected: false, }, - "deprecated-null": { - input: String{Null: true}, - expected: false, - }, "unknown": { input: StringUnknown(), expected: true, }, - "deprecated-unknown": { - input: String{Unknown: true}, - expected: true, - }, - "deprecated-invalid": { - input: String{Null: true, Unknown: true}, - expected: true, - }, } for name, testCase := range testCases { @@ -545,29 +292,9 @@ func TestStringString(t *testing.T) { input: StringNull(), expectation: "", }, - "deprecated-known-non-empty": { - input: String{Value: "simple"}, - expectation: `"simple"`, - }, - "deprecated-known-empty": { - input: String{Value: ""}, - expectation: `""`, - }, - "deprecated-known-quotes": { - input: String{Value: `testing is "fun"`}, - expectation: `"testing is \"fun\""`, - }, - "deprecated-unknown": { - input: String{Unknown: true}, - expectation: "", - }, - "deprecated-null": { - input: String{Null: true}, - expectation: "", - }, - "default-0": { + "zero-value": { input: String{}, - expectation: `""`, + expectation: ``, }, } @@ -595,30 +322,14 @@ func TestStringValueString(t *testing.T) { input: StringValue("test"), expected: "test", }, - "deprecated-known": { - input: String{Value: "test"}, - expected: "test", - }, "null": { input: StringNull(), expected: "", }, - "deprecated-null": { - input: String{Null: true}, - expected: "", - }, "unknown": { input: StringUnknown(), expected: "", }, - "deprecated-unknown": { - input: String{Unknown: true}, - expected: "", - }, - "deprecated-invalid": { - input: String{Null: true, Unknown: true}, - expected: "", - }, } for name, testCase := range testCases { diff --git a/types/value_state.go b/types/value_state.go deleted file mode 100644 index 3ec78adcd..000000000 --- a/types/value_state.go +++ /dev/null @@ -1,42 +0,0 @@ -package types - -import "fmt" - -const ( - // valueStateDeprecated represents a value where it can potentially be - // controlled by exported fields such as Null and Unknown. Since consumers - // can adjust those fields directly and it would not modify the internal - // valueState value, this sentinel value is a placeholder which can be - // checked in logic before assuming the valueState value is accurate. - // - // This value is 0 so it is the zero-value of existing implementations to - // preserve existing behaviors. A future version will switch the zero-value - // to null and export this implementation in the attr package. - valueStateDeprecated valueState = 0 - - // valueStateNull represents a value which is null. - valueStateNull valueState = 1 - - // valueStateUnknown represents a value which is unknown. - valueStateUnknown valueState = 2 - - // valueStateKnown represents a value which is known (not null or unknown). - valueStateKnown valueState = 3 -) - -type valueState uint8 - -func (s valueState) String() string { - switch s { - case valueStateDeprecated: - return "deprecated" - case valueStateKnown: - return "known" - case valueStateNull: - return "null" - case valueStateUnknown: - return "unknown" - default: - panic(fmt.Sprintf("unhandled valueState in String: %d", s)) - } -} diff --git a/website/docs/plugin/framework/migrating/resources/import.mdx b/website/docs/plugin/framework/migrating/resources/import.mdx index 06d1534d7..faf8d8e20 100644 --- a/website/docs/plugin/framework/migrating/resources/import.mdx +++ b/website/docs/plugin/framework/migrating/resources/import.mdx @@ -177,8 +177,6 @@ func (r *passwordResource) ImportState(ctx context.Context, req resource.ImportS MinNumeric: types.Int64Value(0), } - state.Keepers.ElemType = types.StringType - hash, err := generateHash(id) if err != nil { resp.Diagnostics.Append(diagnostics.HashGenerationError(err.Error())...) diff --git a/website/docs/plugin/framework/paths.mdx b/website/docs/plugin/framework/paths.mdx index cd1d13993..b76113f4a 100644 --- a/website/docs/plugin/framework/paths.mdx +++ b/website/docs/plugin/framework/paths.mdx @@ -295,27 +295,27 @@ Examples below will presume a `nested_string_attribute` string value of `types.S The path which matches the object associated with the `root_set_attribute` block is: ```go -path.Root("root_set_attribute").AtSetValue(types.Object{ - AttrTypes: map[string]attr.Type{ +path.Root("root_set_attribute").AtSetValue(types.ObjectValueMust( + map[string]attr.Type{ "nested_string_attribute": types.StringType, }, - Attrs: map[string]attr.Value{ + map[string]attr.Value{ "nested_string_attribute": types.StringValue("example"), } -}) +)) ``` The path which matches the `nested_string_attribute` string value associated with `root_set_attribute` block is: ```go -path.Root("root_set_attribute").AtSetValue(types.Object{ - AttrTypes: map[string]attr.Type{ +path.Root("root_set_attribute").AtSetValue(types.ObjectValueMust( + map[string]attr.Type{ "nested_string_attribute": types.StringType, }, - Attrs: map[string]attr.Value{ + map[string]attr.Value{ "nested_string_attribute": types.StringValue("example"), } -}).AtName("nested_string_attribute") +)).AtName("nested_string_attribute") ``` #### Building Single Nested Attributes Paths @@ -462,27 +462,27 @@ Examples below will presume a `block_string_attribute` string value of `types.St The path which matches the object associated with the `root_set_block` block is: ```go -path.Root("root_set_block").AtSetValue(types.Object{ - AttrTypes: map[string]attr.Type{ +path.Root("root_set_block").AtSetValue(types.ObjectValueMust( + map[string]attr.Type{ "block_string_attribute": types.StringType, }, - Attrs: map[string]attr.Value{ + map[string]attr.Value{ "block_string_attribute": types.StringValue("example"), } -}) +)) ``` The path which matches the `block_string_attribute` string value associated with `root_set_block` block is: ```go -path.Root("root_set_block").AtSetValue(types.Object{ - AttrTypes: map[string]attr.Type{ +path.Root("root_set_block").AtSetValue(types.ObjectValueMust( + map[string]attr.Type{ "block_string_attribute": types.StringType, }, - Attrs: map[string]attr.Value{ + map[string]attr.Value{ "block_string_attribute": types.StringValue("example"), } -}).AtName("block_string_attribute") +)).AtName("block_string_attribute") ``` #### Building Single Block Paths