Error: can't use tftypes.List[tftypes.String] as value of List with ElementType basetypes.missingType

Intent: To develop custom type of list with interface implementation of basetypes.ListTypable and basetypes.ListValuable

Doc Reference for above implementaion: Plugin Development - Framework: Handling Data - Custom Types | Terraform | HashiCorp Developer

Description:

While trying to convert an attribute value from the configuration, the following error occurred:

│ Error: Configuration Read Error

│ with powerstore_nfs_export.test1,
│ on main.tf line 44, in resource “powerstore_nfs_export” “test1”:
│ 44: no_access_hosts = [“10.0.0.1”]

│ An unexpected error was encountered trying to convert an attribute value from the configuration. This is always an error in the provider. Please report the following to the provider developer:

│ Error: can’t use tftypes.List[tftypes.String]<tftypes.String<“10.0.0.1”>> as value of List with ElementType basetypes.missingType, can only use tftypes.DynamicPseudoType values

Please review the code and provide the necessary information to resolve this issue.
Schema: terraform-provider-powerstore/powerstore/resource_nfs_export.go at 1e37856acbb784b983a0ccc03686970791e9e0b0 · dell/terraform-provider-powerstore · GitHub
Model: terraform-provider-powerstore/models/nfsExport.go at 1e37856acbb784b983a0ccc03686970791e9e0b0 · dell/terraform-provider-powerstore · GitHub

Custom Type Implementation:
terraform-provider-powerstore/powerstore/customtype/hosts_type.go at nfs-host-add · dell/terraform-provider-powerstore
terraform-provider-powerstore/powerstore/customtype/hosts_value.go at nfs-host-add · dell/terraform-provider-powerstore

Hey there @Krishnan-Priyanshu :wave:, sorry you’re running into trouble there and thanks for providing the source links!


That error message is suggesting that there is no element type set on your custom list (default of the embedded ListType is missingType to avoid any panics)

Taking a look at your custom type implementation, there are more methods you need to override for ListType, the ElementType() and WithElementType(attr.Type) methods. The ElementType property on the ListAttribute is not carried over to the custom type implementation, so you’ll need to provide a way to set that on customtype.HostsType{}.

If you know the custom list will always be of element type string, you could also hardcode it in your custom type implementation like this: terraform-provider-sandbox/internal/xtypes/dynamic_list_type.go at 070a0c4af00b4998b17557a37abf8211867b2d27 · austinvalle/terraform-provider-sandbox · GitHub

  • In this example, I’m setting the element type to basetypes.DynamicType, but you could replace this with basetypes.StringType{}.

You’ll also need to set the element type in the custom value as well, like so: terraform-provider-sandbox/internal/xtypes/dynamic_list_value.go at 070a0c4af00b4998b17557a37abf8211867b2d27 · austinvalle/terraform-provider-sandbox · GitHub


Hopefully that helps!