We have terraform provider for one of our products, terraform-provider-citrixadc. We are using terraform SDK v1.
There are some attributes under some resource that accept 0 values, and they are of type int. But whenever the user gives 0 value in the configuration, it doesn’t appear in the payload, meaning sdk doesn’t detect the 0 values and doesn’t proceed to add it to payload.
Initailly, I was using the go lang, struct(json struct in golang) to refer to all the attributes but it wasn’t possible with that, because if I remove omitempty from json struct tag, it would add 0 to every request for that attribute, irrespective if the user is set or not. So, I used map[string]interface{} for payload, and validating each attribute from user configuration.
I’m using GetOk() to check whether the value is set by user or not, it is considering 0 as not set and not processing the if part, but on the other hand if I use GetOkExist() it is able to detect 0 and consider it. but GetOkExist() has a deprecated message.
Please refer here for example:
There is no way to work around the problem, because the type system in the legacy SDK cannot differentiate between zero and unset values. While basically the same underneath, the SDKv2 was release 4 years ago and has some additional GetRaw helpers and updated protocol which can give you access to the actual values coming from Terraform to help work around issues like this. It is however fundamentally still the same SDK, so there are still going to be some problems which can’t be fully resolved.
New providers should be using the Terraform Plugin Framework, an updated SDK which implements the current protocols and has a type system fully compatible with that of Terraform core.