Reputation: 118
Terragrunt documentation specifically addresses whether .terraform.lock.hcl
files should be checked into source control repos.
What is the recommendation for .tf
files generated by terragrunt? Should they also be added to source control?
If they are not added, it seems like they would just be regenerated during the next init/plan/apply. But, it also seems like it would be a pain to manage .gitignore
file(s) so that developers don't have to worry about these files that they didn't touch during an edit.
If the recommendation is that they should be added to source control, then developers would have to ensure that they at least run terragrunt init
or terragrunt plan
so that terragrunt creates/updates the files that it is responsible for. That doesn't seem ideal either.
What's the "right" way to handle those files?
Upvotes: 6
Views: 2167
Reputation: 11
I would advise against adding *.tf
to your .gitignore
, as you might want/need some native Terraform capabilities within your repository.
By default, generated files from Terragrunt should be created inside .terragrunt-cache
(unless specified otherwise within the path
attribute) UNLESS the Terraform block is not being used within the live-call (as stated here), which in that case they will be created alongside the live-call itself.
Simply adding .terragrunt-cache
to the .gitignore
, while using Terraform block should be enough (as shown in the official Terragrunt example repo).
Upvotes: 1
Reputation: 34426
Do not add generated .tf
files to the repo. As you state, they will be regenerated on each run, so it doesn't make sense to have stale files lying around. Simply add *.tf
to .gitignore
in the repo root.
One further note regarding lock files: you can commit the lock files, but note that this may impair cross platform compatibility. So if you're running terragrunt/terraform on multiple platforms (e.g. MacOS and Linux), you may not want to check in the lock file. Alternatively, you can generate a lock file that works for multiple platforms using the providers lock command. For example, to generate a lock file that is compatible with Intel based MacBooks and Linux:
terragrunt run-all providers lock -platform=darwin_amd64 -platform=linux_amd64
Refer to https://www.terraform.io/docs/cli/commands/providers/lock.html for more info.
Upvotes: 6