gruntwork-io / terragrunt

Terragrunt is a flexible orchestration tool that allows Infrastructure as Code written in OpenTofu/Terraform to scale.
https://terragrunt.gruntwork.io/
MIT License
7.96k stars 967 forks source link

Inconsistency of relative path functions between base commands and *-all commands #1237

Open fitzoh opened 4 years ago

fitzoh commented 4 years ago

Versions

Terragrunt v0.23.29 Terraform v0.12.28

Short Description

The path_relative_*_include functions appear to behave differently when used in a base terraform command in a child directory (terragrunt plan) than when used in a *-all command in the parent directory (terragrunt plan-all).

Reproducing

I have included a minimal example here: https://github.com/fitzoh/terragrunt-relative-paths

Use case

I'm creating multiple instances of the same module and am planning on storing the version of the module to use in a yaml file in the directory for each instance.

The parent terragrunt file will then set the source modules based on a tag stored in the yaml file.

This currently works fine if I run it directly from the repo, but blows up when I try to run it using the *-all functions as it can't find the config files.

yorinasub17 commented 4 years ago

Thanks for providing the repro!

The bug here is that xxx-all is trying to parse the terragrunt.hcl you have at the root folder in isolation when it is building up the stack (see Configuration parsing order for more details), and it can't do that because file fails. Note that skip = true has no effect because the error is during the parsing step: it can't even skip the file because it hasn't parsed skip!

I think the fix for this is to update the parsing logic to do 2 passes: the first pass is just partially parsing the skip attribute to ignore the root terragrunt.hcl, and then exclude those with skip=true before going through the second pass to parse the configs.

With that said, here are two workarounds: