title: How can I move Terraform state in an old S3 bucket to a new S3 bucket?
body: <p>We have a few terraform configurations for which we use s3 as the backend. We have multiple AWS accounts, one for each of our environments.</p>
  <p>In all the environments and across multiple region, we have different s3 bucket &amp; dynamodb_table names used which as of now do not follow a valid convention and make it difficult to identify the purpose of buckets from its name. We now want to follow a convention based naming for all the s3 terraform state buckets. For this I will need to migrate the state of existing terraform resources to the new s3 buckets.</p>
  <p>I am not sure what would be the best way to achieve this without having to run destroy on old state bucket and apply on the new one.</p>
  <p>A few options that I could think of were as below but I am not sure if they are the right thing to do.</p>
  <ol>
  <li>Rename the s3 bucket: I understand this is not possible (or is it?)</li>
  <li>Move the s3 bucket: A solution to renaming is as mentioned <a href="https://stackoverflow.com/a/43275331/4653423">here</a>. Not sure if this approach will disturb the setup we have.</li>
  <li>State migration: The terraform source code is Git controlled but <code>.terraform</code> is not. So, I can make changes to the source code with new bucket, commit it and create a new git tag from this commit. Now when actually doing the migration, I would checkout old git tag being used in my environment, run <code>terraform init</code>, checkout the new git tag and run <code>terraform init</code> again which would ideally ask me if I want to do a migration and do the needful. This process is something similar to what terraform suggests <a href="https://www.terraform.io/docs/cloud/migrate/index.html" rel="nofollow noreferrer">here</a>, but what I am not sure is, will this approach work in the kind of movement that I am expecting to do.</li>
  </ol>
  <p>P.S.: I assume renaming the DynamoDB table or just using a new one instead of old would work out of the box as I would be making sure that when doing the state migration, I do not have any live terraform runs in progress.</p>