pulumi / pulumi-terraform-bridge

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

Detailed diff shows diff on __defaults when number of elements changes #2400

Open VenelinMartinov opened 3 weeks ago

VenelinMartinov commented 3 weeks ago

What happened?

When adding/removing elements from a block type we seem to display a diff on the __defaults:

  ~ prov:index/test:Test: (update)
      [id=newid]
      [urn=urn:pulumi:test::test::prov:index/test:Test::mainRes]
    ~ listBlocks: [
        ~ [0]: {
                + __defaults: []
                  prop      : "val1"
              }
        ~ [1]: {
                + __defaults: []
                  prop      : "val2"
              }
        + [2]: {
                + prop      : "val3"
              }
      ]

Example

https://github.com/pulumi/pulumi-terraform-bridge/pull/2398 list block element added back

Output of pulumi about

.

Additional context

No response

Contributing

Vote on this issue by adding a 👍 reaction. To contribute a fix for this issue, leave a comment (and link to your pull request, if you've opened one already).

VenelinMartinov commented 5 days ago

This one is not an issue with the detailed diff calculation:

detailedDiff=map[string]*pulumirpc.PropertyDiff{
           "maxItemsOneBlock": &pulumirpc.PropertyDiff{
               state:         impl.MessageState{},
               sizeCache:     0,
               unknownFields: nil,
               Kind:          4,
               InputDiff:     false,
           },
           "maxItemsOneBlock.prop": &pulumirpc.PropertyDiff{
               state:         impl.MessageState{},
               sizeCache:     0,
               unknownFields: nil,
               Kind:          4,
               InputDiff:     false,
           },
       }

There is no defaults marked here - instead this seems to be an issue with the news - the block object contains the defaults key when it looks like there is no reason for that: https://github.com/pulumi/pulumi-terraform-bridge/blob/6b95c60de71a628bf0d2dbed288198c9d91474f2/pkg/tfbridge/schema.go#L131

Non-top level defaults don't seem to get used anywhere.

Also: https://github.com/pulumi/pulumi-terraform-bridge/blob/6b95c60de71a628bf0d2dbed288198c9d91474f2/pkg/tfbridge/schema.go#L1749 suggests the __defaults are not necessary.

VenelinMartinov commented 5 days ago

Perhaps we can remove all empty nested defaults arrays.

VenelinMartinov commented 5 days ago

this is all sidestepped if we only return the bottom-most property which has a diff, instead of all the properties in the tree - this works so much better.