Terraform state is messed up after moving folders

Hi Alexander,

The first thing to do is make sure you still have the state files. I would suggest going back to the old folder structure to verify this. Terragrunt has certain modes where it will wipe the cache, and if you are using local state, this is the equivalent to losing all the state! It is more than likely that you still have the state files, but in any case this is a good sanity check.

Once you verify the state files are still intact, I would suggest backing up the terragrunt cache directory before doing anything else to make sure you don’t have any risk of losing the state.

Next, I will suggest updating one module at a time to the new folder structure. This is more tedious, but is much easier to guarantee the state files remain intact. To do this while keeping state, for each module do the following:

  1. Dump out the state to a known, temporary location using terragrunt state pull > $PATH_TO_TEMP_LOCATION
  2. Move the module to the location in the refactored folder structure.
  3. In the new folder structure, import the state using terragrunt state push $PATH_TO_TEMP_LOCATION

Hope this helps!

Best regards,