pulumi / pulumi-terraform-bridge

A library allowing Terraform providers to be bridged into Pulumi.
Apache License 2.0
198 stars 43 forks source link

PF Configure cross-tests fail when renaming fields within `SingleNestedAttribute` #2560

Open iwahbe opened 1 week ago

iwahbe commented 1 week ago

The following cross test fails with a type error:

func TestSingleNestedAttrFieldOverride(t *testing.T) {
    t.Parallel()

    crosstests.Configure(t,
        schema.Schema{
            Attributes: map[string]schema.Attribute{
                "a": schema.SingleNestedAttribute{
                    Optional: true,
                    Attributes: map[string]schema.Attribute{
                        "as": schema.Int64Attribute{Optional: true},
                    },
                },
            },
        },
        map[string]cty.Value{
            "a": cty.ObjectVal(map[string]cty.Value{
                "as": cty.NumberIntVal(123),
            }),
        },
        crosstests.ConfigureProviderInfo(map[string]*info.Schema{
            "a": {
                Name: "puAttr",
                Elem: &info.Schema{Fields: map[string]*info.Schema{
                    "as": {Name: "puNestedAttrField"},
                }},
            },
        }),
    )
}
            stdout: Previewing update (test):

             +  pulumi:pulumi:Stack project-test create 
             +  pulumi:pulumi:Stack project-test create Error: Property as does not exist on 'test:index/ProviderPuAttr:ProviderPuAttr'
             +  pulumi:pulumi:Stack project-test create   on Pulumi.yaml line 8:
             +  pulumi:pulumi:Stack project-test create    8:                 as: 123
             +  pulumi:pulumi:Stack project-test create Cannot assign '{puAttr: {as: number}}' to 'pulumi:providers:test':
             +  pulumi:pulumi:Stack project-test create   puAttr: Cannot assign '{as: number}' to 'test:index/ProviderPuAttr:ProviderPuAttr':
             +  pulumi:pulumi:Stack project-test create     Existing properties are: puNestedAttrField
             +  pulumi:pulumi:Stack project-test create 6 messages
            Diagnostics:
              pulumi:pulumi:Stack (project-test):
                Error: Property as does not exist on 'test:index/ProviderPuAttr:ProviderPuAttr'
                  on Pulumi.yaml line 8:
                   8:                 as: 123
                Cannot assign '{puAttr: {as: number}}' to 'pulumi:providers:test':
                  puAttr: Cannot assign '{as: number}' to 'test:index/ProviderPuAttr:ProviderPuAttr':
                    Existing properties are: puNestedAttrField

            Resources:
                + 1 to create         

Since cty.Value to resource.PropertyMap conversion is performed using the same library (convert) that PF uses at runtime, I suspect that this is a genuine bug. If not, then pf/.../cross-tests is holding the library wrong.

VenelinMartinov commented 1 week ago

@iwahbe Does the issue repro if you specify both programs manually? That'd help us determine if it is the testing library or the runtime going wrong.

iwahbe commented 1 week ago

Good question. The issue does repro:

func TestSingleNestedAttrFieldOverride(t *testing.T) {
    t.Parallel()

    crosstests.Configure(t,
        schema.Schema{
            Attributes: map[string]schema.Attribute{
                "a": schema.SingleNestedAttribute{
                    Optional: true,
                    Attributes: map[string]schema.Attribute{
                        "as": schema.Int64Attribute{Optional: true},
                    },
                },
            },
        },
        map[string]cty.Value{
            "a": cty.ObjectVal(map[string]cty.Value{
                "as": cty.NumberIntVal(123),
            }),
        },
        crosstests.ConfigurePulumiConfig(resource.PropertyMap{
            "puAttr": resource.NewProperty(resource.PropertyMap{
                "puNestedAttrField": resource.NewProperty(123.0),
            }),
        }),
        crosstests.ConfigureProviderInfo(map[string]*info.Schema{
            "a": {
                Name: "puAttr",
                Elem: &info.Schema{Fields: map[string]*info.Schema{
                    "as": {Name: "puNestedAttrField"},
                }},
            },
        }),
    )
}
                                Diff:
                                --- Expected
                                +++ Actual
                                @@ -36,13 +36,3 @@
                                       },
                                -      value: (*big.Float)({
                                -       prec: (uint32) 64,
                                -       mode: (big.RoundingMode) 0,
                                -       acc: (big.Accuracy) 0,
                                -       form: (big.form) 1,
                                -       neg: (bool) false,
                                -       mant: (big.nat) (len=1) {
                                -        (big.Word) 17726168133330272256
                                -       },
                                -       exp: (int32) 7
                                -      })
                                +      value: (interface {}) <nil>
                                      }
                Test:           TestSingleNestedAttrFieldOverride/compare

It looks like we silently drop the value.