Repository navigation
Relative source on a block injected by a stack-level autoinclude fails stack generate ("relative paths require a module with a pwd")
#7145
Replies: 2 comments 8 replies
|
I don't think this should be changed, @igor-raits . I'd like to discuss it a bit. Mysteriously changing the value of Why isn't |
|
Fair point — dropping the automatic rewrite of plain relative sources; |
Uh oh!
There was an error while loading. Please reload this page.
Describe the bug
A
unitorstackblock injected through a stack-levelautoinclude(theautoincludeof astackblock) can't use a relativesource.stack generatefails with:A base block in the same file with the same relative
sourcegenerates fine. The same injected block with an absolute source (git::…,${get_repo_root()}/…) also works. That is probably why the stack-level autoinclude docs example uses${get_repo_root()}.The injected block is copied verbatim into
terragrunt.autoinclude.stack.hclin the nested stack's directory. Its relative source then resolves against that generated directory instead of the stack file that declares it. The bug shows up in two ways:update_source_with_cas = true). The CAS walk rewrites relative sources of top-levelunit/stackblocks tocas::references, but never looks inside astackblock'sautoinclude. The injected block keeps../..//units/echoin the generated.terragrunt-stack/<stack>/terragrunt.stack.hcl, even withupdate_source_with_cas = true. This is the normal layout for a catalog stack that nests another catalog stack and overrides one of its units.source = "../catalog/units/echo"is relative to the liveterragrunt.stack.hcl. It's written unchanged into.terragrunt-stack/fn/terragrunt.autoinclude.stack.hcland resolved against.terragrunt-stack/fn/.This is the
sourcecounterpart of #7073 / #7074, which madeunit[...]/stack[...]references inside injected blocks resolve in the stack file that declares them.Steps To Reproduce
Layout, with every path under one directory
$Rand absolute catalog paths in the live files:Both fail with
relative paths require a module with a pwd. Replacing either injectedsourcewith an absolute path makes both succeed.Expected behavior
A relative
sourceon an injected block resolves against the stack file that declares it, the same as a base block'ssourcein that file and asunit[...]/stack[...]references in injected blocks after #7074:update_source_with_cas = trueon the injected block makes CAS rewrite it to acas::reference, like any other block in the catalog file.terragrunt.autoinclude.stack.hclcarries a source that resolves to the same directory from where it's written.Must haves
Nice to haves
Versions
main@ 30af009stack generate.Additional context
Code pointers on
main:unit/stackblocks, so blocks inside astackblock'sautoincludeare never rewritten:ReadStackBlocksRewriteStackBlockSourceprocessStackFilesourcekeeps its original relative value:GenerateAutoIncludeFile→writeNonDependencyContentcopyBlocksourceDir:generateUnitsfetchViaCAS/resolveLocalCASSourcecopyFilesA catalog control: a nested catalog stack whose base block has a relative source and no
update_source_with_casfails the same way. That's expected, because relative sources in catalog files need the CAS rewrite. So in a catalog, the injected block needsupdate_source_with_cas = truelike any other block. The bug is that setting it has no effect.I have a fix with regression tests ready and can open a PR.
All reactions