The file path .../versions.tf already exists and was not generated by terragrunt
Fixes Terragrunt's 'The file path .../versions.tf already exists and was not generated by terragrunt' by choosing the right if_exists strategy. Use when a generate block collides with a module's own versions.tf. Not for genuinely missing version constraints.
TL;DR: Your generate block targets versions.tf, but the module you're consuming ships its own versions.tf, and overwrite_terragrunt refuses to clobber a file it didn't write. Don't switch to overwrite (it silently deletes the module's constraints); scope the generate block so it doesn't fire for modules that bring their own, or drop the generate in favor of the module's file.
ERROR: The file path .../versions.tf already exists and was not generated by terragrunt.Steps
- Confirm the collision: the error names the path; check the module source for a
versions.tfit ships.
Expected: the module (e.g. a terraform-aws-modules package) contains its own versions.tf.
- Pick one:
- If the module's pins are acceptable: stop generating
versions.tffor that unit (condition thegenerateblock or move it out of the shared config). - If you must enforce your pins: generate to a differently-named file is NOT enough (only one
required_providersper module); instead constrain via the module call or a version constraint the module honors.
Expected: exactly one source of required_providers per unit.
- Re-run.
Expected: the error is gone and tofu init/terraform init resolves providers.
When this applies
- A
generateblock withif_exists = "overwrite_terragrunt"(orerror) targets a filename the module also ships. - Common with
versions.tf,provider.tf,backend.tfinjected from a root config.
When it doesn't apply
- You WROTE the existing file by hand and want Terragrunt's version: that's what
overwrite_terragruntis for; check the file's signature comment to see why Terragrunt doesn't recognize it (e.g.disable_signature = truewas used).
Tool versions
All Terragrunt 1.x.
Why it happens
overwrite_terragrunt replaces a file only if Terragrunt generated it (recognized by its signature comment). A module's own versions.tf was written by a human upstream, so Terragrunt stops rather than silently deleting someone else's version pins.
Edge cases
if_exists = "skip"makes the error go away but silently disables your pin wherever the module ships the file; the inconsistency is invisible.if_exists = "overwrite"deletes the module's constraints entirely, and you must then redeclare every provider the module needs and track module updates yourself.
Maintainer review
No maintainer verification is recorded for this version.
This records the version a maintainer checked. It does not assert that the version is the latest upstream release.