crossplane / upjet

A code generation framework and runtime for Crossplane providers
Apache License 2.0
302 stars 87 forks source link

Empty value for a block or a map in `forProvider` causes a panic #419

Open villevsv-upcloud opened 3 months ago

villevsv-upcloud commented 3 months ago

What happened?

Preparing the diff plan response will cause a panic, if the diff.Value1 for a path is nil.

How can we reproduce it?

  1. Apply a resource with non-empty values for block or map fields.
  2. Updating the resource with empty values such as [] and {} will cause a panic.

This is most likely related to the way the diff in terraform-plugin-go seems to work, but also how the library handles empty values when marshaling to msgpack.

Using a forked version of upjet repo with a small change made to the external_tfpluginfw.go:282 seems to mitigate the issue:

        if diff.Value1 != nil && diff.Value1.IsKnown() && !diff.Value1.IsNull() {

In addition, deleting the resource with also cause some troubles, if the field with the empty value is marked as required.

Related omitempty issue: https://github.com/crossplane-contrib/provider-upjet-aws/issues/1357