Add the remote or cloud backend type to your Terraform code to allow for the local workspace to interact with the backend. Make sure to update your values and add the workspace that you want to move resources from:
Now, pull the state:
Switch the backend from the remote/cloud mode to local by commenting out the remote backend configuration from the source code:
Now run a reconfigure to make sure the backend updates:
Depending on the Terraform version, you may have to add the backend as local for reconfigure to work. If it already worked, ignore this step:
If the above fails with the error “Backend initialization required, please run "terraform init": Reason: Unsetting the previously set backend "remote"”, please see the Step 5a.
If it works, you’ll see the following output:
After the resources have been split, you can start refactoring the source Terraform code into different folders. In my case, I now have 2 directories for each workspace.
Now , you must re-enable the backend in each workspace by removing the previous commented out lines: