Skip to content

Commit

Permalink
Migrate state from cloud over to s3
Browse files Browse the repository at this point in the history
When you try to do it out of the box, you get this error:

```
Initializing the backend...
Migrating from Terraform Cloud to s3 state.
╷
│ Error: Migrating state from Terraform Cloud to another backend is not yet implemented.
│
│ Please use the API to do this: https://www.terraform.io/docs/cloud/api/state-versions.html
```
The instructions on that page are not every helpful.

Luckily this fine fellow on the internet tells us how to do it here:
https://nedinthecloud.com/2022/03/03/migrating-state-data-off-terraform-cloud/

tl;dr is to do this:
1. `terraform init` with the cloud provider
2. `mkdir -p terraform.tfstate.d/tfc-migration-test`
3. `terraform state pull > terraform.tfstate.d/production-tier1/terraform.tfstate`
4. `mv .terraform/terraform.tfstate .terraform/terraform.tfstate.old`
5. Drop the cloud section of the terraform provider and replace it with
   s3
6. `terraform init`
  • Loading branch information
hellais committed Feb 6, 2024
1 parent 4718462 commit 745ab37
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions tf/environments/production/main.tf
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
# Store terraform state in s3
terraform {
#backend "s3" {
# bucket = "ooni-secrets"
# key = "terraform/production/terraform-production.tfstate"
# region = "eu-central-1"
#}

cloud {
organization = "ooni"
workspaces {
name = "production-tier1"
}
backend "s3" {
bucket = "ooni-secrets"
key = "terraform/production/terraform-production.tfstate"
region = "eu-central-1"
}

#cloud {
# organization = "ooni"
# workspaces {
# name = "production-tier1"
# }
#}

}

provider "aws" {
Expand Down

0 comments on commit 745ab37

Please sign in to comment.