hashicorp / terraform-provider-google

Terraform Provider for Google Cloud Platform
https://registry.terraform.io/providers/hashicorp/google/latest/docs
Mozilla Public License 2.0
2.36k stars 1.75k forks source link

Provider-level string type arguments should all have non-empty-string validation in the plugin-framework provider schema #19643

Open SarahFrench opened 2 months ago

SarahFrench commented 2 months ago

Community Note

Description

Currently the Google provider offers validation feedback to users when they set some provider-level string fields as empty strings. In the past empty strings would be silently ignored, because the SDK treats empty strings and null or unknown string values in the same way. In the plugin-framework empty strings are acknowledged and used because the PF can differentiate "" from null/unknown strings. This can lead to bugs such as this one, specifically about credentials: https://github.com/hashicorp/terraform-provider-google/issues/14255.

We should have consistent validation on string provider-level arguments but we currently do not.

Fields where validation rejects an empty string value:

Fields currently missing validation for empty strings:

It's worth noting that adding new validation in the schema of the plugin-framework provider is a breaking change:

New or Affected Resource(s)

Potential Terraform Configuration

N/A

References

No response

SarahFrench commented 2 months ago

Note to add: This suggested change is still relevant after the 'muxing fix' changes I am in the process of getting accepted and merged because even when the SDK and PF providers share the same meta the SDK and PF providers will have separate schemas. Validation placed on the PF schema that can detect and reject empty strings benefits the 'whole' provider, regardless of whether a user's config is provisioning anything implemented with the PF.

SarahFrench commented 2 weeks ago

Labelled as plugin-framework because this would be achieved by adding a Validator on the PF provider's schema, similar to this:

https://github.com/hashicorp/terraform-provider-google/blob/e92b53f3b83c4b154e8923ec92dcd15f8b71236d/google/fwprovider/framework_provider.go#L90-L95