Skip to content

Commit

Permalink
resource/schema: Revert prevent UseStateForUnknown data misalignment …
Browse files Browse the repository at this point in the history
…by raising implementation error when under a list or set (#750)

Reference: #709
Reference: #711

This unblocks the v1.3.0 release by reverting the `UseStateForUnknown` implementation errors introduced as an interim solution to the originally reported data alignment issue with the plan modifier. Leaving the half state of the `UseStateForUnknown` implementation error would leave provider developers in an unfortunately much worse situation where existing implementations would break without a straightforward path to fixing their schema implementations. The framework needs additional reworking of plan data (potentially reimplementing some of the Terraform core logic in this regard) as a fuller solution for the issue, rather than trying to shoe-horn a solution only for framework-defined plan modifiers.

This changeset reverts a lot of the prior code changes that were part of the interim implementation error logic, however it does notably leave the additional unit testing that highlights the current (sometimes unfortunate) behavior of the `UseStateForUnknown` plan modifier so that future efforts can show the expected behavior changes of updating the framework planning logic.
  • Loading branch information
bflad authored Jun 7, 2023
1 parent 1e82228 commit 0ac33a2
Show file tree
Hide file tree
Showing 28 changed files with 49 additions and 928 deletions.
6 changes: 0 additions & 6 deletions .changes/unreleased/BUG FIXES-20230406-112757.yaml

This file was deleted.

95 changes: 26 additions & 69 deletions internal/fwserver/attribute_plan_modification_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
"github.com/hashicorp/terraform-plugin-framework/diag"
"github.com/hashicorp/terraform-plugin-framework/internal/fwschema"
"github.com/hashicorp/terraform-plugin-framework/internal/fwschema/fwxschema"
"github.com/hashicorp/terraform-plugin-framework/internal/planmodifierdiag"
"github.com/hashicorp/terraform-plugin-framework/internal/privatestate"
"github.com/hashicorp/terraform-plugin-framework/internal/testing/planmodifiers"
"github.com/hashicorp/terraform-plugin-framework/internal/testing/testplanmodifier"
Expand Down Expand Up @@ -358,7 +357,9 @@ func TestAttributeModifyPlan(t *testing.T) {
"nested_required": types.StringType,
},
map[string]attr.Value{
"nested_computed": types.StringUnknown(),
// TODO: Rework list/set element alignment during plan
// Reference: https://github.com/hashicorp/terraform-plugin-framework/issues/709
"nested_computed": types.StringValue("statevalue1"),
"nested_required": types.StringValue("testvalue2"),
},
),
Expand All @@ -368,7 +369,9 @@ func TestAttributeModifyPlan(t *testing.T) {
"nested_required": types.StringType,
},
map[string]attr.Value{
"nested_computed": types.StringUnknown(),
// TODO: Rework list/set element alignment during plan
// Reference: https://github.com/hashicorp/terraform-plugin-framework/issues/709
"nested_computed": types.StringValue("statevalue2"),
"nested_required": types.StringValue("testvalue1"),
},
),
Expand Down Expand Up @@ -420,7 +423,9 @@ func TestAttributeModifyPlan(t *testing.T) {
"nested_required": types.StringType,
},
map[string]attr.Value{
"nested_computed": types.StringUnknown(),
// TODO: Rework list/set element alignment during plan
// Reference: https://github.com/hashicorp/terraform-plugin-framework/issues/709
"nested_computed": types.StringValue("statevalue1"),
"nested_required": types.StringValue("testvalue2"),
},
),
Expand All @@ -430,17 +435,14 @@ func TestAttributeModifyPlan(t *testing.T) {
"nested_required": types.StringType,
},
map[string]attr.Value{
"nested_computed": types.StringUnknown(),
// TODO: Rework list/set element alignment during plan
// Reference: https://github.com/hashicorp/terraform-plugin-framework/issues/709
"nested_computed": types.StringValue("statevalue2"),
"nested_required": types.StringValue("testvalue1"),
},
),
},
),
Diagnostics: diag.Diagnostics{
planmodifierdiag.UseStateForUnknownUnderListOrSet(
path.Root("test").AtListIndex(0).AtName("nested_computed"),
),
},
},
},
"attribute-list-nested-nested-usestateforunknown-elements-removed": {
Expand Down Expand Up @@ -550,17 +552,14 @@ func TestAttributeModifyPlan(t *testing.T) {
"nested_required": types.StringType,
},
map[string]attr.Value{
"nested_computed": types.StringUnknown(),
// TODO: Rework list/set element alignment during plan
// Reference: https://github.com/hashicorp/terraform-plugin-framework/issues/709
"nested_computed": types.StringValue("statevalue1"),
"nested_required": types.StringValue("testvalue2"),
},
),
},
),
Diagnostics: diag.Diagnostics{
planmodifierdiag.UseStateForUnknownUnderListOrSet(
path.Root("test").AtListIndex(0).AtName("nested_computed"),
),
},
},
},
"attribute-set-nested-private": {
Expand Down Expand Up @@ -852,7 +851,7 @@ func TestAttributeModifyPlan(t *testing.T) {
"nested_required": types.StringType,
},
map[string]attr.Value{
"nested_computed": types.StringUnknown(),
"nested_computed": types.StringValue("statevalue1"),
"nested_required": types.StringValue("testvalue1"),
},
),
Expand All @@ -862,28 +861,12 @@ func TestAttributeModifyPlan(t *testing.T) {
"nested_required": types.StringType,
},
map[string]attr.Value{
"nested_computed": types.StringUnknown(),
"nested_computed": types.StringValue("statevalue2"),
"nested_required": types.StringValue("testvalue2"),
},
),
},
),
Diagnostics: diag.Diagnostics{
planmodifierdiag.UseStateForUnknownUnderListOrSet(
path.Root("test").AtSetValue(
types.ObjectValueMust(
map[string]attr.Type{
"nested_computed": types.StringType,
"nested_required": types.StringType,
},
map[string]attr.Value{
"nested_computed": types.StringUnknown(),
"nested_required": types.StringValue("testvalue1"),
},
),
).AtName("nested_computed"),
),
},
},
},
"attribute-set-nested-nested-usestateforunknown-elements-rearranged": {
Expand Down Expand Up @@ -1013,7 +996,9 @@ func TestAttributeModifyPlan(t *testing.T) {
"nested_required": types.StringType,
},
map[string]attr.Value{
"nested_computed": types.StringUnknown(),
// TODO: Rework list/set element alignment during plan
// Reference: https://github.com/hashicorp/terraform-plugin-framework/issues/709
"nested_computed": types.StringValue("statevalue1"),
"nested_required": types.StringValue("testvalue2"),
},
),
Expand All @@ -1023,28 +1008,14 @@ func TestAttributeModifyPlan(t *testing.T) {
"nested_required": types.StringType,
},
map[string]attr.Value{
"nested_computed": types.StringUnknown(),
// TODO: Rework list/set element alignment during plan
// Reference: https://github.com/hashicorp/terraform-plugin-framework/issues/709
"nested_computed": types.StringValue("statevalue2"),
"nested_required": types.StringValue("testvalue1"),
},
),
},
),
Diagnostics: diag.Diagnostics{
planmodifierdiag.UseStateForUnknownUnderListOrSet(
path.Root("test").AtSetValue(
types.ObjectValueMust(
map[string]attr.Type{
"nested_computed": types.StringType,
"nested_required": types.StringType,
},
map[string]attr.Value{
"nested_computed": types.StringUnknown(),
"nested_required": types.StringValue("testvalue2"),
},
),
).AtName("nested_computed"),
),
},
},
},
"attribute-set-nested-nested-usestateforunknown-elements-removed": {
Expand Down Expand Up @@ -1154,28 +1125,14 @@ func TestAttributeModifyPlan(t *testing.T) {
"nested_required": types.StringType,
},
map[string]attr.Value{
"nested_computed": types.StringUnknown(),
// TODO: Rework list/set element alignment during plan
// Reference: https://github.com/hashicorp/terraform-plugin-framework/issues/709
"nested_computed": types.StringValue("statevalue1"),
"nested_required": types.StringValue("testvalue2"),
},
),
},
),
Diagnostics: diag.Diagnostics{
planmodifierdiag.UseStateForUnknownUnderListOrSet(
path.Root("test").AtSetValue(
types.ObjectValueMust(
map[string]attr.Type{
"nested_computed": types.StringType,
"nested_required": types.StringType,
},
map[string]attr.Value{
"nested_computed": types.StringUnknown(),
"nested_required": types.StringValue("testvalue2"),
},
),
).AtName("nested_computed"),
),
},
},
},
"attribute-map-nested-private": {
Expand Down
Loading

0 comments on commit 0ac33a2

Please sign in to comment.