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

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 committed Jun 6, 2023
1 parent 1e82228 commit e3b5e7e
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 e3b5e7e

Please sign in to comment.