From 7332e6e89169339547831afba786fe77fda2a937 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arturo=20Filast=C3=B2?= Date: Fri, 2 Feb 2024 21:48:35 +0100 Subject: [PATCH] Migrate state from cloud over to s3 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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` --- tf/environments/production/main.tf | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/tf/environments/production/main.tf b/tf/environments/production/main.tf index 7b5ccf83..ce2b27fb 100644 --- a/tf/environments/production/main.tf +++ b/tf/environments/production/main.tf @@ -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" {