Upgrading terraform version and update the state file

Hi,
I am upgrading the terraform configuration files from 0.11.11 to 0.12.37 and as par of i wrote a script which will remove .terraform folder if any then do terraform init and terraform 0.12upgrade and then running terraform refresh to update the state file.
when running terraform refresh its updating the state file to the newest version , but I am seeing few missing resources, where as tfstate backup file, have all the resources and also refreshed to newest version. Please let me know if Iam doing something wrong , or a better way to upgrade the files.

Hi @swetharamk,

If your result from terraform refresh is that some objects are no longer tracked in the state then that typically suggests that those objects no longer exist in the remote system. Have you confirmed that the resource instances that Terraform removed do still have corresponding objects in the remote system?

Another way this can happen is if you configure the provider in a way that changes its view of the remote system. For example, on AWS if you choose a different region then it appears to the AWS provider that none of the existing objects exist any longer, because when the provider asks the new region for those objects it will indicate that they don’t exist. This can also happen if you use credentials that refer to a different AWS account, in which case the API might return that an object doesn’t exist even though it still does, in order to avoid telling other users which objects exist in your account.

You might be able to confirm this by running terraform plan after you upgrade to Terraform v0.12. If the provider is indicating that these objects don’t exist anymore then Terraform will propose to create them, and then you can investigate each of the objects Terraform proposes to create to see if you can find that object in the admin console of whatever remote system the object belongs to.