TypeList has nil elements when required string attribute is set to empty string #216
Labels
shims/maybe
Issues that may be caused by our backwards-compatibility shims.
subsystem/types
Issues and feature requests related to the type system of Terraform and our shims around it.
terraform-plugin-framework
Resolved in terraform-plugin-framework
I'm working on a custom provider and I'm noticing some strange behavior with a
TypeList
, in which each element is a schema with a single required string attribute. If you set this attribute to an empty string, the element itself isnil
, instead of amap[string]interface{}
.Terraform Version
Terraform Configuration Files
Given a schema that looks like this:
And HCL that looks like this:
The following provider code produces a panic:
As
v.([]interface{})[0]
isnil
.Expected Behavior
In the example above, I expect
v.([]interface{})[0]
to be amap[string]interface{}
with a single key,a_string
, with the value of""
Actual Behavior
In the example above,
v.([]interface{})[0]
wasnil
, causing the example code to panic.Additional Context
I'm a little confused with what the intended behavior is when the end user specifies an empty string for a string attribute that is marked as required. I actually expected the example HCL I posted to fail validation, since I interpreted a "required string" to also be non-empty.
If it is expected for users to be able to use an empty string for required string attributes, then what is the recommended way for a provider developer to ensure that required string attributes are also non-empty? I did a quick search in the
validation
package and didn't find a helper function that looked like it would help.Thanks!
The text was updated successfully, but these errors were encountered: