Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

internal/fwserver: Use response plan value instead of request with nested attributes and blocks #669

Merged
merged 4 commits into from
Feb 10, 2023

Conversation

bflad
Copy link
Contributor

@bflad bflad commented Feb 10, 2023

Closes #644
Reference: https://discuss.hashicorp.com/t/framework-v1-1-1-strategies-for-diagnosing-resource-state-churn/49688

The attribute and block plan modification logic must preserve any changes made by the "top level" list/map/set/single nested attribute/block plan modifiers before continuing on to nested attributes/blocks.

New unit testing failures prior to the logic change:

--- FAIL: TestAttributeModifyPlan (0.00s)
    --- FAIL: TestAttributeModifyPlan/attribute-list-nested-usestateforunknown (0.00s)
        attribute_plan_modification_test.go:1107: Unexpected response (-wanted, +got):   fwserver.ModifyAttributePlanResponse{
            - 	AttributePlan:   s`[{"nested_computed":"statevalue1"}]`,
            + 	AttributePlan:   s"[]",
              	Diagnostics:     nil,
              	RequiresReplace: s"[]",
              	Private:         nil,
              }
    --- FAIL: TestAttributeModifyPlan/attribute-map-nested-usestateforunknown (0.00s)
        attribute_plan_modification_test.go:1107: Unexpected response (-wanted, +got):   fwserver.ModifyAttributePlanResponse{
            - 	AttributePlan:   s`{"key1":{"nested_computed":"statevalue1"}}`,
            + 	AttributePlan:   s"{}",
              	Diagnostics:     nil,
              	RequiresReplace: s"[]",
              	Private:         nil,
              }
    --- FAIL: TestAttributeModifyPlan/attribute-single-nested-usestateforunknown (0.00s)
        attribute_plan_modification_test.go:1107: Unexpected response (-wanted, +got):   fwserver.ModifyAttributePlanResponse{
            - 	AttributePlan:   s`{"nested_computed":"statevalue1"}`,
            + 	AttributePlan:   s`{"nested_computed":<unknown>}`,
              	Diagnostics:     nil,
              	RequiresReplace: s"[]",
              	Private:         nil,
              }
    --- FAIL: TestAttributeModifyPlan/attribute-set-nested-usestateforunknown (0.00s)
        attribute_plan_modification_test.go:1107: Unexpected response (-wanted, +got):   fwserver.ModifyAttributePlanResponse{
            - 	AttributePlan:   s`[{"nested_computed":"statevalue1"}]`,
            + 	AttributePlan:   s"[]",
              	Diagnostics:     nil,
              	RequiresReplace: s"[]",
              	Private:         nil,
              }
--- FAIL: TestBlockModifyPlan (0.00s)
    --- FAIL: TestBlockModifyPlan/block-list-usestateforunknown (0.00s)
        /Users/bflad/src/github.com/hashicorp/terraform-plugin-framework/internal/fwserver/block_plan_modification_test.go:2338: Unexpected response (+wanted, -got):   fwserver.ModifyAttributePlanResponse{
            - 	AttributePlan:   s`[{"nested_computed":"statevalue1"}]`,
            + 	AttributePlan:   s"[]",
              	Diagnostics:     nil,
              	RequiresReplace: s"[]",
              	Private:         nil,
              }
    --- FAIL: TestBlockModifyPlan/block-set-usestateforunknown (0.00s)
        /Users/bflad/src/github.com/hashicorp/terraform-plugin-framework/internal/fwserver/block_plan_modification_test.go:2338: Unexpected response (+wanted, -got):   fwserver.ModifyAttributePlanResponse{
            - 	AttributePlan:   s`[{"nested_computed":"statevalue1"}]`,
            + 	AttributePlan:   s"[]",
              	Diagnostics:     nil,
              	RequiresReplace: s"[]",
              	Private:         nil,
              }
FAIL

…sted attributes

Reference: #644
Reference: https://discuss.hashicorp.com/t/framework-v1-1-1-strategies-for-diagnosing-resource-state-churn/49688

The attribute plan modification logic must preserve any changes made by the "top level" list/map/set/single nested attribute plan modifiers before continuing on to nested attributes.

New unit testing failures prior to the logic change:

```
--- FAIL: TestAttributeModifyPlan (0.00s)
    --- FAIL: TestAttributeModifyPlan/attribute-list-nested-usestateforunknown (0.00s)
        attribute_plan_modification_test.go:1107: Unexpected response (-wanted, +got):   fwserver.ModifyAttributePlanResponse{
            - 	AttributePlan:   s`[{"nested_computed":"statevalue1"}]`,
            + 	AttributePlan:   s"[]",
              	Diagnostics:     nil,
              	RequiresReplace: s"[]",
              	Private:         nil,
              }
    --- FAIL: TestAttributeModifyPlan/attribute-map-nested-usestateforunknown (0.00s)
        attribute_plan_modification_test.go:1107: Unexpected response (-wanted, +got):   fwserver.ModifyAttributePlanResponse{
            - 	AttributePlan:   s`{"key1":{"nested_computed":"statevalue1"}}`,
            + 	AttributePlan:   s"{}",
              	Diagnostics:     nil,
              	RequiresReplace: s"[]",
              	Private:         nil,
              }
    --- FAIL: TestAttributeModifyPlan/attribute-single-nested-usestateforunknown (0.00s)
        attribute_plan_modification_test.go:1107: Unexpected response (-wanted, +got):   fwserver.ModifyAttributePlanResponse{
            - 	AttributePlan:   s`{"nested_computed":"statevalue1"}`,
            + 	AttributePlan:   s`{"nested_computed":<unknown>}`,
              	Diagnostics:     nil,
              	RequiresReplace: s"[]",
              	Private:         nil,
              }
    --- FAIL: TestAttributeModifyPlan/attribute-set-nested-usestateforunknown (0.00s)
        attribute_plan_modification_test.go:1107: Unexpected response (-wanted, +got):   fwserver.ModifyAttributePlanResponse{
            - 	AttributePlan:   s`[{"nested_computed":"statevalue1"}]`,
            + 	AttributePlan:   s"[]",
              	Diagnostics:     nil,
              	RequiresReplace: s"[]",
              	Private:         nil,
              }
FAIL
```
@bflad bflad added the bug Something isn't working label Feb 10, 2023
@bflad bflad added this to the v1.2.0 milestone Feb 10, 2023
@bflad bflad requested a review from a team as a code owner February 10, 2023 14:20
Copy link
Contributor

@bendbennett bendbennett left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

Are equivalent changes required for:

@bflad
Copy link
Contributor Author

bflad commented Feb 10, 2023

Are equivalent changes required for:

Looking at their code, that does seem to be case. Will make the equivalent changes there.

@chrismarget-j
Copy link

I've just rebuilt my provider with this version of the framework, can confirm that this fix addressed the issue I was having.

Thanks very much, @bflad!

@bflad bflad changed the title internal/fwserver: Use response plan value instead of request with nested attributes internal/fwserver: Use response plan value instead of request with nested attributes and blocks Feb 10, 2023
@bflad bflad merged commit 757f965 into main Feb 10, 2023
@bflad bflad deleted the bflad/nested-attribute-resp-not-req branch February 10, 2023 21:27
@github-actions
Copy link

I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active contributions.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 14, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

UseStateForUnknown does not work with types.List in model and ListNestedAttribute in schema
3 participants