Migrating to s3 remote state

Hello. I’m in the process of migrating to backend = "s3" terraform_remote_storage types. After confirming my states were perfectly aligned. I change from local storage to remote

If i make a change locally, run a plan, and an apply, i see an update in a local terraform.tfsate, but not in s3 (i realize modified times can take a while)

My migration from local to remote was along the lines of
aws s3 cp terraform.tfstate s3://mybucket/environment/terraform.state

for each environment and then change my data sources to:

data "terraform_remote_state" "staging" {

  backend = "s3"
  config = {
    bucket = "mybucket"
    key = "staging/terraform.tfstate"
    region = "us-east-1"
  }
}

Hopefully this will lead to an RTFM link, but i have not found it. Thanks!

I found the RTFM/post that looks like what i need…you need to ask before you can find it yourself!

Please don’t copy the state file.
Create the S3 backend https://www.terraform.io/docs/backends/types/s3.html and do an init, then TF will ask if you want to migrate the contents.

The remote_state data resource is for using another TF configuration as data source and refer to its definitions in yours. I.e. somebody has created a VPC using TF, and you want to deploy into it.

1 Like

Yes, that was my mistake…ultimately not having the terraform block in main.tf, so when i ran reconfigure nothing happened. /facepalm

terraform {
  backend "s3" {
    bucket = "bucket-tfstate"
    key = "prod/terraform.tfstate"
    region = "us-east-1"
  }
}