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.
$ 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 = "~> 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.