terragrunt
terragrunt copied to clipboard
include_in_copy not working as documented (breaks asdf)
Describe the bug
The include_in_copy attribute for the terraform block is not working as documented. It fails to copy my .tool-versions file into the download_dir, such that asdf can pick up the desired version from it when the terraform command is run.
To Reproduce Steps to reproduce the behavior, code snippets and examples which can be used to reproduce the issue.
$ tree -a
.
├── live
│ └── prod
│ └── mystack
│ └── terragrunt.hcl
├── stacks
│ └── mystack
│ └── main.tf
├── terragrunt.hcl
└── .tool-versions
# .tools-versions
terraform 1.7.4
terragrunt 0.54.5
# terragrunt.hcl
# this code works when uncommented
# generate "asdf_tool_versions" {
# path = ".tool-versions"
# if_exists = "overwrite_terragrunt"
#
# contents = file("${get_repo_root()}/.tool-versions")
# }
# this code does not work
terraform {
include_in_copy = ["${get_repo_root()}/.tool-versions"]
}
download_dir = pathexpand("~/.terragrunt.d/downloads")
include "root" {
path = find_in_parent_folders()
}
terraform {
source = "${path_relative_from_include("root")}/stacks/${basename(get_terragrunt_dir())}"
}
# stacks/mystack/main.tf
resource "null_resource" "default" {
provisioner "local-exec" {
command = "echo 'Hello World'"
}
}
Expected behavior I expect that the following should work:
git init
cd live/prod/mystack
terragrunt init
Instead, I get the following. Note that the .tool-versions file was NOT copied to the download_dir.
~/terragrunt/live/prod/mystack$ terragrunt --terragrunt-log-level debug --terragrunt-source-update init
DEBU[0000] Terragrunt Version: 0.54.5
DEBU[0000] Did not find any locals block: skipping evaluation.
DEBU[0000] Did not find any locals block: skipping evaluation.
DEBU[0000] [Partial] Included config /home/nhavens/terragrunt/terragrunt.hcl has strategy shallow merge: merging config in (shallow).
DEBU[0000] Running command: terraform --version prefix=[/home/nhavens/terragrunt/live/prod/mystack]
DEBU[0000] terraform version: 1.7.4
DEBU[0000] Reading Terragrunt config file at /home/nhavens/terragrunt/live/prod/mystack/terragrunt.hcl
DEBU[0000] Did not find any locals block: skipping evaluation.
DEBU[0000] Did not find any locals block: skipping evaluation.
DEBU[0000] [Partial] Included config /home/nhavens/terragrunt/terragrunt.hcl has strategy shallow merge: merging config in (shallow).
DEBU[0000] Did not find any locals block: skipping evaluation.
DEBU[0000] Did not find any locals block: skipping evaluation.
DEBU[0000] Included config /home/nhavens/terragrunt/terragrunt.hcl has strategy shallow merge: merging config in (shallow) for dependency.
DEBU[0000] Did not find any locals block: skipping evaluation.
DEBU[0000] Did not find any locals block: skipping evaluation.
DEBU[0000] git show-toplevel result:
DEBU[0000] Included config /home/nhavens/terragrunt/terragrunt.hcl has strategy shallow merge: merging config in (shallow).
DEBU[0000] The --terragrunt-source-update flag is set, so deleting the temporary folder /home/nhavens/.terragrunt.d/downloads/aAanXV8z0RsnE0e8Pd50fQjfviM/bw8b_YNr-FzBqiXrg_Tlfcll4sE before downloading source.
DEBU[0000] Downloading Terraform configurations from file:///home/nhavens/terragrunt/stacks/mystack into /home/nhavens/.terragrunt.d/downloads/aAanXV8z0RsnE0e8Pd50fQjfviM/bw8b_YNr-FzBqiXrg_Tlfcll4sE
DEBU[0000] Copying files from /home/nhavens/terragrunt/live/prod/mystack into /home/nhavens/.terragrunt.d/downloads/aAanXV8z0RsnE0e8Pd50fQjfviM/bw8b_YNr-FzBqiXrg_Tlfcll4sE
DEBU[0000] Setting working directory to /home/nhavens/.terragrunt.d/downloads/aAanXV8z0RsnE0e8Pd50fQjfviM/bw8b_YNr-FzBqiXrg_Tlfcll4sE
DEBU[0000] Running command: terraform init prefix=[/home/nhavens/terragrunt/live/prod/mystack]
No version is set for command terraform
Consider adding one of the following versions in your config file at
terraform 1.3.5
terraform 1.3.9
terraform 1.7.4
ERRO[0000] terraform invocation failed in /home/nhavens/.terragrunt.d/downloads/aAanXV8z0RsnE0e8Pd50fQjfviM/bw8b_YNr-FzBqiXrg_Tlfcll4sE prefix=[/home/nhavens/terragrunt/live/prod/mystack]
ERRO[0000] 1 error occurred:
* [/home/nhavens/.terragrunt.d/downloads/aAanXV8z0RsnE0e8Pd50fQjfviM/bw8b_YNr-FzBqiXrg_Tlfcll4sE] exit status 126
~/terragrunt/live/prod/mystack$ tree -a /home/nhavens/.terragrunt.d/downloads/aAanXV8z0RsnE0e8Pd50fQjfviM/bw8b_YNr-FzBqiXrg_Tlfcll4sE
/home/nhavens/.terragrunt.d/downloads/aAanXV8z0RsnE0e8Pd50fQjfviM/bw8b_YNr-FzBqiXrg_Tlfcll4sE
├── main.tf
├── terragrunt.hcl
├── .terragrunt-init-required
├── .terragrunt-module-manifest
├── .terragrunt-source-manifest
└── .terragrunt-source-version
0 directories, 6 files
~/terragrunt/live/prod/mystack$
Versions
- asdf version: v0.14.0-ccdd47d
- Terragrunt version: v0.54.5
- Terraform version: v1.7.4
- Environment details: Linux Mint 21.3
Additional context
A key part of the problem is that the download_dir is outside the git repo's directory structure, so as to nullify the effect of the in-repo .tool-versions file.
If I uncomment the generate block in my top-level terragrunt.hcl, the .tool-versions file is generated and terragrunt init works properly.
Hi,
AFAIK, hidden files aren't copied to download_dir, can be used include_in_copy to pass configurations to copy hidden files
https://terragrunt.gruntwork.io/docs/reference/config-blocks-and-attributes/
@denis256 Yup, The include_in_copy documentation uses .python-versions (a hidden file) as its example.
Hi,
I'm having the same issue with include_in_copy, wanting to copy .git hidden folder.
In my case however I noticed the .git folder was included when the source was remote (source = "git::https://MYURL) so this was a workaround for me, but even without the use of include_in_copy
If I'm not mistaken according to documentation I should be able to use include_in_copy attribute to copy the .git folder from my local repo .
By default, Terragrunt excludes hidden files and folders during the copy step. This feature allows you to specify glob patterns of files that should always be copied from the Terragrunt working directory For example, if your terraform module source contains a hidden file that you want to copy over (e.g., a .python-version file), you can specify that in this list to ensure it gets copied over to the scratch copy (e.g., include_in_copy = [".python-version"]).
https://terragrunt.gruntwork.io/docs/reference/config-blocks-and-attributes/
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for raising this issue.