hashicorp / terraform-plugin-framework

A next-generation framework for building Terraform providers.
https://developer.hashicorp.com/terraform/plugin/framework
Mozilla Public License 2.0
284 stars 92 forks source link

Extend `attr.Value` interface to support `IsFullyNullableKnown()` #980

Open magodo opened 2 months ago

magodo commented 2 months ago

This new method is similar to the Value.IsFullyKnown() that is available in the github.com/hashicorp/terraform-plugin-go/tftypes.

The difference here is that in tftypes, each value can only has two states: a concrete value (including nil) or "unknown". While in the fw, each value can has three states: null, unknown and known. This is why the method name is chose so (as I can't figure out another better name, as IsFullyNotKnown or IsPartiallyUnknown are ambiguous than the current one, IMO).

The reason for introducing this method is to allow provider developers to check the state of an aggregate value during the ModifyPlan, where the code might stop processing that property if its value contains any unknwon value. Currently, the developer has two solutions:

This PR tries to put this common logic to the FW so that more developers can save the run/develop time effort for the same purpose. I chose to extend the attr.Value interface, instead of introducing a helper method in the attr package, as a random choice. If the latter looks better, then I can rework this PR.

bflad commented 2 months ago

Related feature request issue: https://github.com/hashicorp/terraform-plugin-framework/issues/597

For any reviewers, please note that the current attr.Value interface change is a breaking change since it would force all existing custom type implementations to need to include the new method. I'm adding the GitHub label to call this out. @magodo I'm not providing a full review, but it might be good to update the proposed implementation to avoid the breaking change so it potentially can get into any release, rather than needing to wait for a future major version of the Go module. If you would like to discuss available options there, please reach out.

magodo commented 2 months ago

@bflad The other possible option I can think of is the 2nd one I mentioned above, which won't handle the custom types. I don't know how can we avoid breaking change while still taking custom types into consideration at this moment..