Explicit zero values in provider schemas

This is a question about authoring a provider rather than using it, and I can’t find a better category for this question.

I have run into an interesting challenge with terraform-provider-snowflake - we have a field in our schema with a non-zero default for which we need to allow zero.

Unfortunately there seems to be no way to distinguish between configurations where this field is not present and present but zero. I hoped that GetOK would work, but it explicitly does not (since it considers a zero to be “not set”).

Is there a workaround for this?

Hey @ryanking,

So, bad news and (slightly) good news.

The bad news is this is kind of the Terraform white whale–a core engineer once joked to me that every few years someone comes along believing they can fix the issue and make it possible to detect a zero value. They are always almost right. But because of the lossy way Terraform stores values it doesn’t actually work in all situations.

The (slightly) good news is that terraform-plugin-go does not inherit this problem, and providers built with it are able to reliable distinguish between not-set (null) and zero values for all types. This is only “slightly” good news because terraform-plugin-go is difficult and very verbose to use, making it not an ideal general-purpose solution. I only mention it for completeness in case the bug is so time-sensitive that that’s the only reasonable workaround and is worth the extra effort. There are future efforts planned to bring this kind of accuracy and faithful representation of data to an approachable development experience like the SDK, but we have nothing to announce at this time.

In the meantime, some providers have found success in using strings instead of numbers, which is a confusing user experience, but unlocks the ability to use "" to detect “unset” and "0" for 0. This is far from ideal, but again, is another option that can unblock you immediately.