How to set a list of strings as a default value in the schema.TypeList (SDKv2)

Is there any way to set a list of strings as a default value for schema.TypeList?
The documentation says it’s impossible, but maybe there some hackish way of doing this?
// Default cannot be used if the Schema is directly an
// implementation of an Elem field of another Schema, such as trying to
// set a default value for a TypeList or TypeSet.

Hi @danielmkn :wave: Welcome to HashiCorp Discuss and thank you for raising this topic.

While this functionality is not supported by the Default schema field in terraform-plugin-sdk based provider code, it may be possible to implement schema.Resource type CustomizeDiff field logic to cover this use case. In particular, the ResourceDiff type SetNew() method may be able to modify the plan to set the default value for a list after checking whether it is not set. Please note though that CustomizeDiff logic can be problematic without extensive resource testing (e.g. acceptance tests), since it affects how the resource operates during many Terraform operations.

Another option is that this functionality can be implemented in terraform-plugin-framework based provider code since it has less restricted schema-based plan modification support.

Hope this helps.

1 Like