Open dotjim opened 6 years ago
There's definitely a bug with using plan files with Terragrunt and extra_arguments
: https://github.com/gruntwork-io/terragrunt/issues/493
I don't think we've ever tried plan-all
and apply-all
with plan files. The provider issue confuses me, as Terragrunt doesn't control where Terraform downloads provider/module code... It just runs terraform init
and lets Terraform do its thing...
I recently set up a CI process using terragrunt plan-all and apply-all commands using the plan generated in a previous step.
My setup is:
~/.terraform.d/plugins/
--terragrunt-source
switch.myvars.auto.tfvars
file instead of using extra_arguments
Also I did notice that I needed to run the apply-all
from the same absolute path as I ran the plan-all
step from in the previous step.
I'm running into this same issue when using this type of setup with Atlantis
@sjungwirth would you be open to sharing your before_hook code?
@mholttech sure, it's nothing too fancy:
#!/bin/bash
parent_dir=$1
relative_path=$2
child_dir="${parent_dir}/${relative_path}";
filename="${child_dir}/create_vars.auto.tfvars";
cat <<EOF > ${filename}
# DO NOT EDIT - File created by bin/create_vars.sh
dept = "${relative_path%/*}"
org_id = "XXXXXX"
billing_account = "XXXXXXXX"
EOF
and the root terragrunt config in /terraform.tfvars:
terragrunt = {
remote_state {
backend = "gcs"
config {
bucket = "XXXXXXX"
prefix = "${path_relative_to_include()}/terraform.tfstate"
project = "XXXXXXX"
}
}
terraform {
before_hook "setup_vars" {
commands = ["${get_terraform_commands_that_need_vars()}"]
execute = [
"${get_parent_tfvars_dir()}/bin/create_vars.sh", "${get_parent_tfvars_dir()}", "${path_relative_to_include()}",
]
run_on_error = false
}
}
}
One thing I think I forgot to mention in my previous post, I needed to run terragrunt validate-all ... || true
in my CI to initialize the create_vars.auto.tfvars
files before trying to do a plan-all
. The || true
part was to allow my CI to continue even though the validate-all
command would return an error code.
@mholttech mholttech I know it's a little bit old issue, but I'm curious if you've ever solved this issue.
I'm unable to run terragrunt plan-all -out=$PLANFILE
and then terragrunt apply-all $PLANFILE
sequentially, terraform is complaining about unsatisfied plugins.. :(
Terragrunt appears to not support operation via Continuous Integration in the Plan and Apply on different machines scenario described by Terraform.
Attempts to have Terragrunt
plan-all
commands produce a plan output file, that would later be used as an input file byapply
in another CI phase (or possibly another machine) fail withError: error satisfying plugin requirements
as no plugins are seen to be installed.I've attempted to address via the
TF_PLUGIN_CACHE_DIR
environment variable, with the intention of having the plugin cache directory produced by theplan-all
phase be part of the CI artifact that is subsequently used in theapply
phase. Results suggest Terragrunt might not fully supportTF_PLUGIN_CACHE_DIR
.Environment summary
Terragrunt project structure mirrors Example infrastructure-live for Terragrunt Tests below performed on Mac with Terragrunt v0.14.11 and Terraform v0.11.7
Steps to reproduce
The above results in the expected plan file being produced, and
/development/plugin-cache
populated with relevant plugins.However attempts to use the plan file produced fail, even from the same machine and working directory as above. For example:
Notes / Observations
With the
TF_LOG=debug
environment variable set the above$ terragrunt apply -lock=true --terragrunt-source /development/infrastructure-modules/ /development/tfplan
command includes the below output, that suggeststerragrunt apply
does not utilizeTF_PLUGIN_CACHE_DIR
and instead continues to look in.terraform/plugins/
--terragrunt-source
is used in bothplan
andapply
commands as automation seeks to guarantee the same contents is used by both phases and avoid performance penalties of downloading multiple times.Although
plan-all
is used to produce the plan output file, it seems onlyapply
supports a plan input file. Is this correct? A plan input file withapply-all
results in:I've attempted various scenarios with
--terragrunt-non-interactive
,-input=false
and-auto-approve
type flags which have not influence the outcome above.If I've missed something and there are other approaches for Terragrunt working in an automation / continuous integration world it would be great to have details included in the documentation.