1
votes

I am using terraform to deploy to multiple AWS accounts and each account with its own set of environments. I'm using terraform workspaces and s3 remote state. When I switch between these accounts my terraform workspace list is empty now for one of the accounts. Is there a way to sync the state of workspace from the s3 remote state? Please advise. Thanks,

I have tried to create the workspace but when I run terraform plan it does create all the resources even though they exists already in the remote state.

1

1 Answers

0
votes

I managed to fix it using the following:

  1. I created the new namespaces manually using terraform workspace command
terraform workspace new dev

Created and switched to workspace "dev"!

You're now on a new, empty workspace. Workspaces isolate their state,
so if you run "terraform plan" Terraform will not see any existing state
for this configuration.
  1. I went to S3 where I have the remote state and now under the environment dev I have duplicate states.

I copied the state from the old folder key and added to the new folder key (using copy/paste) in S3 console window

  1. IN dynamo db lock state I have duplicate id of LockID for my environment with different digests. I had to copy the Digest of the old entry and replace the digest for the new entry. After that when I run terraform plan everything went smoothly and I had to repeat the same process for all the environments.

I hope this helps anyone else having the same use case. Thanks,