It is often useful to be able to generate a plan file using the -out planfile.tfplan option passed to Terraform, and then have the subsequent terraform apply use the same plan file as input.
This works fine in vanilla Terraform, however it breaks when using Terragrunt:
$ terragrunt plan -out tgf.plan
[terragrunt] 2018/03/29 12:59:16 Running command: terraform plan -var-file=/platform/dev/us-east-1/playground_module/../../account.tfvars -out tgf.plan
Refreshing Terraform state in-memory prior to plan...
The refreshed state will be used to calculate this plan, but will not be
persisted to local or remote state storage.
null_resource.resource_1: Refreshing state... (ID: 5541669811424217406)
null_resource.resource_1: Refreshing state... (ID: 4765190517361501877)
------------------------------------------------------------------------
No changes. Infrastructure is up-to-date.
This means that Terraform did not detect any differences between your
configuration and real physical resources that exist. As a result, no
actions need to be performed.
$ terragrunt apply tgf.plan
[terragrunt] [/platform/dev/us-east-1/playground_module] 2018/03/29 12:59:31 Running command: terraform --version
[terragrunt] 2018/03/29 12:59:32 Reading Terragrunt config file at /platform/dev/us-east-1/playground_module/terraform.tfvars
[terragrunt] 2018/03/29 12:59:32 WARNING: no double-slash (//) found in source URL /NextGear/ngc-tf-mod-playground.git. Relative paths in downloaded Terraform code may not work.
[terragrunt] 2018/03/29 12:59:32 Terraform files in /Users/kamil.markowicz/.terragrunt/1FJt07AQRrpS8SZ_9uJ4JgBVAGE/JKvATcHaiXbEHrZ6QWznmOsnJfQ are up to date. Will not download again.
[terragrunt] 2018/03/29 12:59:32 Copying files from /platform/dev/us-east-1/playground_module into /Users/kamil.markowicz/.terragrunt/1FJt07AQRrpS8SZ_9uJ4JgBVAGE/JKvATcHaiXbEHrZ6QWznmOsnJfQ
[terragrunt] 2018/03/29 12:59:32 Setting working directory to /Users/kamil.markowicz/.terragrunt/1FJt07AQRrpS8SZ_9uJ4JgBVAGE/JKvATcHaiXbEHrZ6QWznmOsnJfQ
[terragrunt] 2018/03/29 12:59:32 Backend s3 has not changed.
[terragrunt] 2018/03/29 12:59:32 Running command: terraform apply -var-file=/platform/dev/us-east-1/playground_module/../../account.tfvars tgf.plan
You can't set variables with the '-var' or '-var-file' flag
when you're applying a plan file. The variables used when
the plan was created will be used. If you wish to use different
variable values, create a new plan file.
[terragrunt] 2018/03/29 12:59:32 exit status 1
If this is not currently supported, I would like to know if it's feasible to implement this feature based on how Terragrunt works with Terraform?
You can't set variables with the '-var' or '-var-file' flag
when you're applying a plan file. The variables used when
the plan was created will be used. If you wish to use different
variable values, create a new plan file.
I think that's the real cause of the issue. Do you have an extra_args block for apply that adds account.tfvars?
Well, that's embarrassing :). I do indeed have the extra_args block, as I wanted to propagate certain "global" root-level variables down to all modules.
Looks like I could just replace ${get_terraform_commands_that_need_vars()} interpolation with the list of actual commands (other than apply).
But then of course this will break running a direct apply without a plan being passed in.
I guess that I am OK with that, because it actually forces a certain workflow to occur.
Hello.
I'm having the same issue but with 'apply-all' scenario.
I made the similar workaround with
extra_arguments "common_vars" {
# do not use `get_terraform_commands_that_need_vars()` here
# as there is an issue with `apply-all` command
# https://github.com/gruntwork-io/terragrunt/issues/493
# https://github.com/gruntwork-io/terragrunt/issues/457
commands = [
"plan"
]
in root terragrunt.hcl file
@geekifier Here it's said that for apply command there is a way to make it working.
Most helpful comment
Well, that's embarrassing :). I do indeed have the extra_args block, as I wanted to propagate certain "global" root-level variables down to all modules.
Looks like I could just replace
${get_terraform_commands_that_need_vars()}interpolation with the list of actual commands (other thanapply).But then of course this will break running a direct
applywithout a plan being passed in.I guess that I am OK with that, because it actually forces a certain workflow to occur.