Can I overwrite statefile schema field from one type to another (bool to List)

Hi All
Assume I have two terraform provider plugin version.

  1. 1st provider plugin version a schema field is of type boolean and i created the resources in my local setup.
  2. 2nd provider plugin version I change the schema field from boolean to list type.

But when I am upgrading form 1st version to 2nd version it is failing as in state file type is boolean but in schema it is of type list.

Without deleting the statefile can I generate/upgrade the resource/statefile.

can you suggest any solution for above issue?

Hi @ranktocrack01 :wave: Thank you for raising this topic and welcome to HashiCorp Discuss. :tada:

This type of change can be accomplished by using Terraform’s state upgrade functionality, which is where a provider signals to Terraform that there is a breaking change in a resource schema and implements logic to update the state. This is done by:

  • Increasing the schema version number within the resource
  • Writing additional code in your provider with how to convert existing states using the old schema version to the new state used by the new schema version

How to accomplish these will depend on which Terraform Provider SDK you are using:

Please note that from a practitioner standpoint, it is recommended to perform this type of change in a major version release of the provider, since they will be required to update their configurations.

Hope this helps!

1 Like