hashicorp / terraform-plugin-go

A low-level Go binding for the Terraform protocol for integrations to be built on top of.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

tfprotov5+tfprotov6: Add DynamicValue Null Checking Without Type Information

bflad opened this issue · comments

terraform-plugin-go version

v0.16.0

Use cases

terraform-plugin-mux, tfprotov5.ProviderServer, and tfprotov6.ProviderServer implementations generally need to check whether a DynamicValue is null. For example, this type of check can be used in PlanResourceChange RPCs to verify whether the intended resource operation is creation or deletion. Currently, DynamicValue only supports an Unmarshal() method, which must be given the expected type information (e.g. from a schema), which may not always be available immediately in implementations.

Attempted solutions

Caching schema information, calling (DynamicValue).Unmarshal(), then checking (tftypes.Value).IsNull().

Proposal

Checking whether a DynamicValue is null can be performed by peeking into the underlying JSON and MessagePack data without fully decoding it. JSON data should have a null value (nil json.Token) and MessagePack data should have a msgpcode.Nil code.

In both tfprotov5 and tfprotov6 packages, add a new IsNull() method to the DynamicValue type.

References