--config
Path to the Terragrunt configuration file to use to migrate the resources. Note that this path is relative to the directory of each of the source and destination units, not the current working directory.
Environment Variables:
TG_CONFIG
Migrate OpenTofu/Terraform state from one unit to another.
Migrate backend state from `unit` to `unit-renamed`.
backend migrate old-unit-name new-unit-name
Force state migration, even if the bucket doesn't have versioning enabled.
backend migrate --force old-unit-name new-unit-name
This command will migrate the OpenTofu/Terraform state backend from one unit to another.
You will typically want to use this command if you are using a key
attribute for your remote_state
block that uses the relative_path_to_include
function, and you want to rename the unit.
For example, given the following filesystem structure:
remote_state { backend = "s3" generate = { path = "backend.tf" if_exists = "overwrite" } config = { bucket = "my-tofu-state" key = "${path_relative_to_include()}/tofu.tfstate" region = "us-east-1" encrypt = true dynamodb_table = "my-lock-table" }}
include "root" { path = find_in_parent_folders("root.hcl")}
You couldn’t simply rename the old-unit-name
directory to new-unit-name
and run terragrunt apply
in new-unit-name
, because the change in the evaluated value for path_relative_to_include()
would result in a new state key for the new-unit-name
unit.
Instead, you can use the backend migrate
command to migrate the backend state from the old-unit-name
unit to the new-unit-name
unit.
cp -R old-unit-name new-unit-nameterragrunt backend migrate old-unit-name new-unit-namerm -rf old-unit-name
This will migrate the backend state from the old-unit-name
unit to the new-unit-name
unit, and then delete the old-unit-name
unit.
Terragrunt performs migrations in one of two ways, depending on the level of support for the backends being migrated, and the state of configuration between the two units.
--config
Path to the Terragrunt configuration file to use to migrate the resources. Note that this path is relative to the directory of each of the source and destination units, not the current working directory.
Environment Variables:
TG_CONFIG
--download-dir
Path to download OpenTofu/Terraform modules into. The default is `.terragrunt-cache`. Note that this path is relative to the directory of each of the source and destination units, not the current working directory.
Environment Variables:
TG_DOWNLOAD_DIR
--force
When this flag is set, Terragrunt will force the migration of the backend state, even if the bucket containing it has versioning disabled.
Environment Variables:
TG_FORCE