Syncing local tfstate to remote

Hi All!

I just started with both Terraform and Terragrunt and built up some code. I’ve realized that instead of ‘remote_state’ I had ‘config’ in my terraform.tfvars files and I’ve been using the local state. Now unfortunately, I don’t see how to move terraform.tfstate into S3 (the preferred terragrunt backend).

I’ve tried apply, refresh, and ‘state push’ with no result of having the tfstate file show up in S3. How do I sync it up without having to manually upload the file to S3?

I believe you’d run the same command as with plain-old terraform: init. That is, run terragrunt init and it should prompt you to copy your state to S3.

Unfortunately, that does nothing:

$ terragrunt init

[terragrunt] [/Users/<... snip ...>/aws/dev/vpc] 2018/11/10 00:52:59 Running command: terraform --version

[terragrunt] 2018/11/10 00:53:00 Reading Terragrunt config file at /Users/<... snip ...>/aws/dev/vpc/terraform.tfvars

[terragrunt] 2018/11/10 00:53:00 Initializing remote state for the s3 backend

[terragrunt] 2018/11/10 00:53:03 Running command: terraform init -backend-config=bucket=<... snip ...> -backend-config=key=dev.vpc.tfstate -backend-config=region=us-west-2 -backend-config=encrypt=true -backend-config=dynamodb_table=terraform-lock

**Initializing modules...**

- module.vpc

**Initializing provider plugins...**

The following providers do not have any version constraints in configuration,

so the latest version was installed.

To prevent automatic upgrades to new major versions that may contain breaking

changes, it is recommended to add version = "..." constraints to the

corresponding provider blocks in configuration, with the constraint strings

suggested below.

* provider.aws: version = "~&gt; 1.42"

**Terraform has been successfully initialized!**

You may now begin working with Terraform. Try running "terraform plan" to see

any changes that are required for your infrastructure. All Terraform commands

should now work.

If you ever set or change modules or backend configuration for Terraform,

rerun this command to reinitialize your working directory. If you forget, other

commands will detect it and remind you to do so if necessary.

I noticed that an older version of terragrunt had an option to push the local terraform.tfstate remote. This version doesn’t seem to have it anymore.

I’m using:
terraform 0.11.10
terragrunt 0.17.1 (and just tried 0.17.2)

Am I supposed to have a Terraform S3 backend configured as well, as have the same backend configured in Terragrunt?

Your Terraform code (.tf) must contain an empty backend configuration:

terraform {
  # The configuration for this backend will be filled in by Terragrunt
  backend "s3" {}
}

:grin: At some point doing my rewrite, I left that part out.

Everything is working as it should now. Thanks Jim!