terragrunt

Should terragrunt-generated files be added to source control?


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?


Solution

  • 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.