Hi everyone. I've been reading a lot of the discussions here before working up the nerve to post. I'm in the middle of a pretty big infrastructure consolidation and need to move all our existing Terraform workspaces to a new backend. We're currently using a simple S3 backend, but we're standardizing on Terraform Cloud for all teams.
My understanding is that I need to handle both the state migration and the workspace structure itself. For the state, I think the process is to use `terraform init -migrate-state` after reconfiguring the backend block, but I'm nervous about doing this across dozens of workspaces. What if the state gets corrupted or locked?
Also, our current workspaces in the S3 backend are just prefixed state files. Terraform Cloud has a different concept of named workspaces. Does this mean I essentially have to re-import every resource into new, defined workspaces in TFC? That sounds like a massive undertaking, and I'm worried about drift or downtime.
Has anyone gone through a similar migration from a traditional backend to Terraform Cloud? I'm particularly interested in how you managed the mapping of old state files to new workspaces, and if there were any scripts or tools that helped automate parts of it. Was the move worth the effort in the end?
I did this exact migration last year, so I feel your pain! That nervousness is totally valid, especially with so many workspaces on the line.
For the mapping issue: we solved it by writing a small script that used the TFC API. It basically read our list of old S3 state file prefixes, created a correspondingly named workspace in TFC, and then used the `terraform state push` command to inject the state file directly into that new workspace. This avoided having to re-run init and migrate-state on every single one manually. You just have to be meticulous about your authentication and the order of operations.
The tricky part was handling any existing state locks in S3, which we had to manually clear before the push. Have you checked if your current setup uses locking with DynamoDB?