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

In CustomizedDiff the 2nd return value of d.GetChange on a nested block (TypeSet) doesn't contain inner nested block #497

Open
magodo opened this issue Jul 10, 2020 · 3 comments
Labels
bug Something isn't working shims/maybe Issues that may be caused by our backwards-compatibility shims. subsystem/types Issues and feature requests related to the type system of Terraform and our shims around it.

Comments

@magodo
Copy link

magodo commented Jul 10, 2020

SDK version

v1.6.0 & v1.13.0

Relevant provider source code

Schema definition:

"foo": {
    Type:     schema.TypeSet,
    Optional: true,
    Elem: &schema.Resource{
        Schema: map[string]*schema.Schema{
            "a": {
                Type:     schema.TypeString,
                Required: true,
            },

            "b": {
                Type:     schema.TypeList,
                Optional: true,
                MaxItems: 1,
                Elem: &schema.Resource{
                    Schema: map[string]*schema.Schema{
                        "x": {
                            Type:     schema.TypeBool,
                            Required: true,
                        },
                    },
                },
            },
        },
    },
}

Then define a CustomizeDiff, which in turns call d.GetChange("foo").

Expected Behavior

The returned "new" value of foo should contain the new state defined in terraform configuration.

Actual Behavior

The returned "new" value has foo.b with one element: nil.

Addtional Findings

I have debugged a bit on v1.6.0, and find the cause is that in readListField() it will modify the addrPadded to change the hash index of Set into a list index, which in turns will change affect the out address (as slice is passed by pointer in Go). In later step when d.GetChange wants to get the value from diff for an address, it can't find the value, hence setting it to nil.

The fix is simply copy the addrPadded to a temporary list before calling:

countResult, err := r.ReadField(addrPadded)

in file field_reader.go in readListField().

I suspect the same fix should be applied to the v1-maint branch.

@magodo magodo added the bug Something isn't working label Jul 10, 2020
@paddycarver paddycarver added the shims/maybe Issues that may be caused by our backwards-compatibility shims. label Jul 10, 2020
@magodo
Copy link
Author

magodo commented Oct 13, 2020

@paddycarver Any update on this?

@paddycarver paddycarver added the subsystem/types Issues and feature requests related to the type system of Terraform and our shims around it. label Jan 6, 2021
@arodriguezdlc
Copy link

Hello, this issue is blocking the resolution of hashicorp/terraform-provider-azurerm#7463. Is there any update about this? Thank you.

@Chandra2614
Copy link

Any update on this??

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working shims/maybe Issues that may be caused by our backwards-compatibility shims. subsystem/types Issues and feature requests related to the type system of Terraform and our shims around it.
Projects
None yet
Development

No branches or pull requests

4 participants