I have a terragrunt setup where instead of having multiple directories for each region in which resources are deployed, the applying region and account are passed in as env variables, which are consumed in the root terragrunt config, used to determine state path, then passed to the module with a generate block. I’m getting some strange errors with this setup that i think are related to an update from 0.31 to 0.35. the issue I’m seeing is, i think, related to the optimizations in Optimize dependency output retrieval · gruntwork-io/terragrunt@0bf8185 · GitHub , which does seem to be consistent with the fact that that commit is part of version 0.35 and didn’t exist in my previous version (i think lol). anyway the problem is like this: if i have module A that depends on an output from module B, and module B was last applied in us-west-2 account 123, but now I’m trying to apply module A in us-east-1 account 456, then in the plan for the apply of module A, I’ll see that the dependency output from module B is for resources created in us-west-2 account 123 instead of the region and account I want. this didn’t used to happen previously, so i went looking in the terragrunt source to figure out why and found this comment that says terragrunt will try to use the remote statefile to get dependency outputs instead of the results of a terraform output
within the module as long as there are no dependency outputs in the state path. it kinda makes sense why this is problematic for my setup, since I’m using region and account inputs taken from the env as part of the state path, and i figure terragrunt is going to the terragrunt cache to determine where the remote state file lives for the dependent module instead of figuring it out by calculating the remote state path with what I’ve put in the remote state configuration. all good i figured, that comment indicates that if i just put a dependency output in the state path, then terragrunt will do a full terraform output like before in order to get dependency outputs and will therefore start respecting my account and region inputs again like before i upgraded. I made a new terrragrunt module that does nothing except outputs a string that was previously hardcoded into the state path, so now i technically have a dependency output in there and should see terragrunt using terraform output results to get dependency outputs, and i do. it even seems like it fixes my problem i had before? only issue is that i see some errors that don’t make a ton of sense:
ERRO[0003] Could not convert include to the execution context to evaluate additional locals prefix=[/Users/me/repo/infrastructure/deployment/global/module1]
ERRO[0003] Encountered error while evaluating locals. prefix=[/Users/me/repo/infrastructure/deployment/global/module1]
ERRO[0003] Could not convert include to the execution context to evaluate additional locals prefix=[/Users/me/repo/infrastructure/deployment/account/module2
ERRO[0003] Encountered error while evaluating locals. prefix=[/Users/me/repo/infrastructure/deployment/account/module2]
and so on for all my dependencies. thing is though, just before those errors i see something like this in the debug log:
time=2021-12-19T18:20:17-08:00 level=debug msg=Evaluated 6 locals (remaining 0): var1, var2, var3, var4, var5, var6, prefix=[/Users/me/repo/infrastructure/deployment/account/module2]
comprising all the locals I set in the top level terragrunt config being sourced like:
include "global_configs" {
path = find_in_parent_folders()
merge_strategy = "deep"
expose = true
}
i tried messing with merge strategy to no avail. the fallback to terraform output is working at least:
time=2021-12-19T18:20:17-08:00 level=debug msg=Could not parse remote_state block from target config /Users/me/repo/blahblah
time=2021-12-19T18:20:17-08:00 level=debug msg=Falling back to terragrunt output.
is there some kind of workaround anyone can think of? can i just ignore these errors? if they’re ignoreable, is it possible to silence them somehow? I’d rather not just grep out errors matching this pattern cuz there might be a legit error in there sometimes.
long term, would it make sense to submit a PR changing the dependency output optimization to recalculate the remote state path for each dependency instead of using whatever’s precalculated in the cache? I assume this isn’t currently happening, but i haven’t looked too much into the code yet. and if I’m right about where terragrunt is getting its information about where remote state lives, would it be possible to use a pre-commit hook to force recalculation of the remote state path within dependencies? seems like a bit of a long shot but yeah.
would greatly appreciate any input from anyone who might know more about the internals of this part of terragrunt than i do