Import existing state
A tar.gz bundle, or a single terraform.tfstate, becomes the state of a stack's units.
How files map to units
- Each
<path>/terraform.tfstatein the bundle becomes the unit<path>. A state inside a unit's.terragrunt-cachegoes to that unit. prefixremoves the start of the paths, so the key matchespath_relative_to_include().- Backups (
*.tfstate.backup),.terraformfolders and macOS metadata (._*) are ignored. - Any other file, a link, a path with
..or an invalid state refuses the whole bundle, with the list of what is wrong. - The import writes everything or nothing.
Dry run, then import
# Dry run: shows, per unit, the serial, the resources and what would happen. Writes nothing.
curl -X POST -H "Authorization: Bearer $ADMIN" "$API/api/v1/orgs/$ORG/stacks/$STACK/state/import?dry_run=true" \
-F [email protected] -F prefix=environments/prod
# Import.
curl -X POST -H "Authorization: Bearer $ADMIN" "$API/api/v1/orgs/$ORG/stacks/$STACK/state/import" \
-F [email protected] -F prefix=environments/prod
Units that already have state
A unit with no state gets version 1. A unit that already has state appears as one of these, and only changes if you mark it with -F replace=<unit>, once per unit:
| Result | Meaning |
|---|---|
same |
same as the current state |
newer |
newer than the current state |
older |
older than the current state |
conflict |
another lineage |
A replaced unit gets a new version, and the history stays. If the imported state has the same lineage and a serial no higher than the current one, the serial is raised, so that a plan saved earlier can't be applied on top of it.
A locked unit can't receive an import.
Import through the UI comes with the State tab, which is planned.