tfmigrate
tfmigrate copied to clipboard
Feature request pre-plan / pre-apply - run command
I would love a feature flag / config feature to run a command in affected dir's before plans / migrations
Why: For folks who leverage terragrunt or other terraform wrappers not all required files may exist in the folder. eg autogenerated aws providers etc.
So for us being able to run terragrunt init in the affected dir's would be a big plus.
In a git ops pipeline there may be other uses like forcing a hard reset of the git dir to make sure there are no unexpected files in place
Hi, thank you for opening this! Because I'm not terragrunt user, so I'm not sure why is it not enough to run the custom command before the tfmigrate command?
Terragrunt generates files that may not exist in the folder. Having the ability to make tfmigrate run an alternate re-init command is important for users of terragrunt. Literally just running terragrunt init instead of terraform init.
This can be down to the fact that things like remote state config commands are just not in standard tf files in a lot of terragrunt based configs
You can replace terraform command to terragrunt with exporting an environment variable TFMIGRATE_EXEC_PATH=terragrunt. I guess it's what you request.
Sadly not. Ive tried that but it causes issues at the first pass when tfmigrate trys move to local state as it conflicts with terragrunts config where it wants to force remote state
On Mon 23 Aug 2021 at 14:15, Masayuki Morita @.***> wrote:
You can replace terraform command to terragrunt with exporting an environment variable TFMIGRATE_EXEC_PATH=terragrunt. I guess it's what you request.
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/minamijoyo/tfmigrate/issues/20#issuecomment-903757651, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAMJ3OPJRBUF6ZZUU5EB7RTT6JCX3ANCNFSM42KMKRQA .
Again I'm not terragrunt user, at least please provide executable examples to help us understand what you are trying. There are some issues claimed that the tfmigrate doesn't work with terragrunt, but no one provide executable examples to me.
In addition, if you have any idea to resolve the conflict by adding new pre-plan / pre-apply hooks, could you clarify how to use and how it works. The word pre- is very ambiguous when the hook is invoked.
Hey I think I can provide more context here. Terragrunt has a feature to auto generate remote_state config using a block like below. Before any terragrunt command runs backend.tf is auto-generated. This means you there is no effect when you run terragrunt plan --state=/tmp/hello.plan it will still look for the state file mentioned in the backend.tf which is auto generated.
remote_state = {
backend = "s3"
generate = {
path = "${get_terragrunt_dir()}/backend.tf"
if_exists = "overwrite"
}
config = {
encrypt = true
bucket = local.env_vars.bucket
key = "${local.env_vars.remote_state_path_prefix}/${replace(path_relative_to_include(), "../", "")}/terraform.tfstate"
region = local.env_vars.region
profile = local.env_vars.account
}
}
Unfortunately I don't have an open-source example, but I am happy to make one and update the comment later in the day.
It would be less complicated if temporarily you update the remote state when running plan and rollback. I know this changes behaviour and might not be desirable to everyone but maybe have a flag to support this.
Maybe instead of using -statefile= use https://www.terraform.io/docs/language/files/override.html
I have no plans to implement this feature as is at this time, but there have been a few reports of the tfmigrate does not work with the terragrunt, so if you have problems with the terragrunt, please feel free to open a new issue with minimal reproductive examples so that someone can help debugging with you. Thanks!