My Terraform Git repository ended-up having some unreconciliable data error and I couldn't push a recent change. I exported my commit to a patch, recloned, applied the patch, and then realized I just blew-away all of my local state. I used AWS CLI to sync-down the whole tree of state files, copied the one into/as the .terraform/terraform.tfstate of the path that I wanted to apply, ran init, and am now getting a version error.
This is the exact same running environment that produced the state files in the first place. This is also the only machine that apply changes so everything should still be in sync (not that it relates to the immediate problem, but it won't cause any additional issues once we get past this).
Commands that I've tried running:
$ terraform init
$ terraform init -upgrade
$ terraform init -upgrade -migrate-state
The inevitable, unwavering output:
Initializing the backend...
╷
│ Error: Failed to load state: Terraform 1.3.9 does not support state version 4, please update.
I can't seem to find any posts or write-ups anywhere about how to restore from remote state, and yet I'm guessing that almost everyone has had to restore from remote state at some point. I can't understand it.
What should be the process to restore from remote? Why would I have version issues if the environment, project config, and project state haven't changed?
Thank you. Any help is appreciated.
When I ran
terraform init
, it had initialized the state to .terraform/terraform.tfstate . So, I had cleared the metadata and restored my state file to that file-path instead (a copy of the state that I had manually downloaded from S3). That's when I started seeing the error above. Not sure why. None of that makes sense. However, after noting a subtle reference from a post, I moved the state file back to the root of that project path and things magically worked.