pulumi / pulumi-terraform-bridge

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

Disallow re-mapping attributes to existing attributes #2283

Open corymhall opened 1 month ago

corymhall commented 1 month ago

Hello!

Issue details

map[string]rschema.Attribute{
    "id": StringAttribute{Computed: true},
    "s":  rschema.StringAttribute{Optional: true},
}

info.Resource{
    "some_resource": {
        Tok:       "...",
        ComputeID: computeIDField,
        Fields: map[string]*info.Schema{
            "id": {
                Name: "s",
            },
        },
    },
}

The above is an example of having an attribute that you have re-mapped (via Schema.Name) to an existing attribute. Typically the Schema.Name is used to rename the attribute, but it is technically possible to create a collision with an existing attribute. This should probably be disallowed.

Affected area/feature

We should probably add a check that fails during tfgen.

iwahbe commented 1 month ago

I agree that this would be a good warning. We would need to do some cycle checking (A renamed to "b", B renamed to "a" is ok), but I think that could be as simple as verifying that the number of unique property names is the same as the number of properties.