3

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?

Ben Whaley
  • 32,811
  • 7
  • 87
  • 85
Paul
  • 53
  • 4

1 Answers1

5

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.

Ben Whaley
  • 32,811
  • 7
  • 87
  • 85
  • Thanks for the answer. The use cases I'm thinking of for terragrunt include some `.tf` files _not_ generated by terragrunt. However, I guess that while you are configuring the terragrunt `.hcl` files you could just add the terragrunt-generated `.tf` files in a`.gitignore` in the local directories. For that matter, I guess you could have terragrunt create the `.gitignore` files. – Paul Aug 18 '21 at 11:44
  • 1
    Yes, or you could add the specific names of the generated files to gitignore instead of *.tf. – Ben Whaley Aug 18 '21 at 14:14
  • 1
    I'd upvote, but embarrassingly, I don't have the measly reputation to do that! – Paul Aug 20 '21 at 11:53