Repository navigation
Description
The problem I am currently facing with the new Stacks RFC is that it is not possible to pass the output of one unit through to the values of another in the terragrunt.stack.hcl file.
While it is possible to do this in the unit definition, this is not extensible enough because, with stacks, the units will be reused with different inputs.
Proposal
Expand the terragrunt.values.hcl file to use dependencies:
# terragrunt.stack.hcl
unit "dep" {
source = "modules/imadep"
path = "imadep"
}
unit "test" {
source = "modules/test"
path = "test"
values = {
a = "a"
b = unit.dep.output_b
}
}
# .terragrunt-stack/test/terragrunt.values.hcl (auto-generated)
values {
a = "a"
b = dependency.dep.outputs.output_b
}
dependency "dep" {
config_path = "../imadep"
}
There is a POC of this here: #4056
POC Q&A
Recommendation to use a new terragrunt.dependencies.hcl file
I'd be happy to POC this, but I'm curious how you see the relationship between the dependencies file, values file, and terragrunt file.
My current view is that consolodating all dynamic inputs to units in the terragrunt.values.hcl is optimal:
values {
a = "a"
b = dependency.dep.outputs.output_b
}
dependency "dep" {
config_path = "../imadep"
}
Yes, it is more complex than just putting (static) key-value pairs. However:
- the complexity has to go somewhere
- Putting this inside of the values file may be the least complex
Why is this the least complex?
- I think it can clearly define interfaces and boundaries between components:
terragrunt.values.hclcan be processed (i.e. dependencies resolved) and only export a singlevaluesinterface. Processing would be self-contained to the terragrunt.values.hcl file, and terragrunt.hcl would only ever see thevaluesobject from it. - I suspect there may be other constructs that users may want to add in the future. Splitting files by block types may lead to many files with different kinds of relationships between them.
What if two dependencies are named the same thing across these different files? What's the behavior? Can the terragrunt.hcl file make reference to them?
I think the correct choice is to make the terragrunt.values.hcl file hide it's internals and only expose only an interface for retrieving the values. This helps with composability (If there is a dependency in the values file with the same name as a dependency in the terragrunt file, they will not interfere).
Are there any alternative designs that you think would work just as well?
The constraint to keep unit definitions backwards compatible (which I agree with!) reduces the solution space. I haven't been able to come up with another design.
How are mock outputs handled?
I touch on one option for this at the bottom of this comment #3313 (comment), but there are benefits to not implementing this: it trades a simple interface for flexibility. However, with additional changes it may be possible to get the flexibility of mocks with the benefits of a simple interface, and it boils down to where the mocks are defined. Instead of defining them at the "dependency" block, mock outputs could be defined at either or both of (1) the referenced units (the unit would define it's own mock outputs), and (2) in a new mock_inputs block, which is decoupled from the dependency block. I think it makes sense for a module to define mock_outputs, because the author should know what format the output takes. At the same time, I can see the value of defining mock_inputs for certain use-cases (if the dependency's output is dynamic enough where a static mock_output isn't enough).
Activity
yhakbar commentedon Mar 24, 2025
The way that we've approached extending the
terragrunt.hclfile via the availability of theterragrunt.values.hclfile is that the values file is a simple data store, and a way to conveniently introduce dynamicity into units (in a way that is 100% compatible with everything users use to define units without stacks). Users can, for example chose to use zeroterragrunt.stack.hclfiles, and placeterragrunt.values.hclfiles next toterragrunt.hclfiles, and they'll be respected regardless (although for now, we're gating them both behind thestacksexperiment to make sure we can make breaking adjustments prior to general availability).Unfortunately, as OpenTofu works today, this is a bit of a non-starter. Mock outputs aren't just a convenience, but a requirement for the ability to run a plan against units with unapplied dependencies. OpenTofu has no way of allowing certain inputs to be unknown at the root module (values can only be unknown within state between resources), so we have to retain the ability to mock outputs. We've discussed the possibility of introducing an outputs block to move the responsibility for defining outputs on the unit exporting them, but that is likely too much of a shift to make prior to 1.0.
Dependencies aren't just a data fetching mechanism, but also a scheduling mechanism. One unit depending on another will result in scheduling changes in the DAG, so Terragrunt needs a holistic view of all dependencies when it's looking to schedule the run for a unit. It needs to be unambiguous what all the dependencies are for a unit, and conflict resolution needs to be resolved when there are conflicts between different dependencies named the same thing.
Generally, the design we've been going for with the new
terragrunt.stack.hclfile is to approach from the perspective of the assumption that users will want to use different parts of the design for their projects. That's generally what we see in the wild with Terragrunt: People have different parts that they like, and adopt the features that matter the most to them.Given that, would having the
dependencyblock in theterragrunt.values.hclfile be the best design, if taken in isolation? Assume that someone manually wrote up aterragrunt.values.hclfile with no usage of aterragrunt.stack.hclfile. Would there be any benefit to configuring the dependency in theterragrunt.values.hclfile instead of directly in theterragrunt.hclfile? If there was any benefit, would users get the most benefit out of having it be in theterragrunt.values.hclfile?cgetzen commentedon Mar 26, 2025
@yhakbar Thank you for your engagement -- the terragrunt team is unique in how quickly it responds to the community.
BLUF: I have updated the PR so that mock_inputs can be defined, as well as accounting for the dependency graph. I have left the dependencies in the values file for now.
Got it. Here is the adjusted spec to accommodate mock outputs:
I have adjusted the PR to accommodate this.
Thank you for bearing with my naivety about terragrunt. This makes a lot of sense - for now, I have adjusted the PR so that any dependency across terragrunt.hcl or terragrunt.values.hcl is respected in the graph.
I'm thinking about this a bit differently. If we continue to assume that dependencies in terragrunt.hcl cannot be used in terragrunt.values.hcl (and vice-versa), it's OK to have dependencies with the same name across these files.
I would be happy to change the implementation, but I currently believe the best interface is to have a single file contain the dynamic / injected data that the unit uses. Why?
I think the answer is the same to the question "Would there be any benefit to configuring the values in the terragrunt.values.hcl file instead of directly in the terragrunt.hcl file's inputs block?": There would be very little benefit, if any. However, adding dependency blocks to this file doesn't hurt users from creating their own values file (with or without dependencies).
yhakbar commentedon Apr 18, 2025
Hey @cgetzen ,
Someone asked about this RFC in Discord, and I wanted to make sure I am explicit with where this RFC is:
I think it's a productive conversation, and I want to directly answer your questions above, but based on initial conversations, it does seem to me to be a feature that can wait until after general availability of Stacks as is.
If you haven't had a chance, I recommend reading through this blog post if you haven't to see how we're approaching general availability of Terragrunt Stacks:
https://www.gruntwork.io/blog/the-road-to-1-0-terragrunt-stacks-feature-complete
Note that there are some example repositories in there for best practice Terragrunt configurations (which might change if we adopt something like this), and that all the stack examples contain dependencies, which might be worth looking at:
https://github.com/gruntwork-io/terragrunt-infrastructure-catalog-example/tree/main/examples/terragrunt/stacks
Any change we make as a consequence of this RFC will aim to make configurations like those easier to manage.
Regarding timeline, you can expect a full response to your questions above after Stacks is generally available, but before Terragrunt 1.0 (hopefully well before).
If more members of the community engage with this RFC, it might make it easier to reason about, and the design more robust.
Thank you for your patience.
yhakbar commentedon May 16, 2025
Hey @cgetzen !
More folks have been asking about functionality like this, but it doesn't seem to have risen to the level where it's a must-have for Terragrunt 1.0, so as it currently stands, we're still looking to prioritize this as a feature that becomes available post-1.0 (as nothing we've discussed so far would require a breaking change in how Terragrunt operates).
To respond to some of your responses:
I'm not following how this would play into DAG resolution. When trying to determine the correct order of unit runs, how would Terragrunt know which units need to go at a given time without merging the two definitions of dependencies together?
If you had something like this:
It's important that Terragrunt is able to determine that
imadepandimadifferentdepmust run beforetestis able to run (for plans and applies). How would Terragrunt track that these requirements are satisfied otherwise? Furthermore, wouldn't it be confusing to users if the same variable (dependency.dep.outputs.output_b) could mean two different things in the same unit?I'm not sure this is true. If you can define a
dependencyblock in either theterragrunt.values.hclor theterragrunt.hclfile, and they almost work the same way, that feels like a fuzzy boundary. How would you explain to a user how Terragrunt behaves when there is adependencyblock in theterragrunt.hclfile and when it is in theterragrunt.values.hclfile?Note that there's a difference in functionality here, as well. You typically can only use dependency outputs in
inputsforterragrunt.hclfiles, but exposing them asvalueswould mean that you can use dependency outputs for anything, including locals. This has massive performance implications. Callingtofu output -jsonis slow, compared to most Terragrunt configuration parsing. Minimizing the number of timesdependencyblocks have to be evaluated is important for maintaining Terragrunt performance.There's a big difference between these two. You can define more than values for inputs in the
terragrunt.values.hclfile. The values in that file can be used for thesourceattribute of theterraformblock, it can be used to define the path to units in thedependencyblock in theterragrunt.hclfile, etc. It can be used to define values for any variable referenced in unit configurations.cgetzen commentedon May 20, 2025
Thanks for the information! I suspect I'm still operating from a limited viewpoint, and that a new terragrunt.dependency.hcl file is necessary. But for the sake of exploration, I'll go over all the options I see available.
It's nice to see that the community wants this feature! As a quick aside, my ideal state of terragrunt (2.0?) is "no configuration required": We can shard state across modules without any code changes (stacks are a huge step, but there would need to be a solution for defaulting mock outputs, for-loops over units to match terraform functionality, etc). I believe this would substantially lower the barrier to entry for adopting terragrunt. I'm mentioning this because it influences my perspective on the developer interface exposed with each option.
OK, here are the options I see to get stack X-unit references:
A new terragrunt.dependency.hcl file
This is the option you were guiding me towards. Can we flesh this out a bit more? If we assume that this just renders "normal" dependency blocks that can be references in terragrunt.hcl, I'm not sure that it accomplishes dynamic X-unit references.
The underlying problem is how we go from the auto-generated dependency, to being referenced in
terragrunt.hcl. If it's a direct reference (no semantic changes to the dependency block being inside of the terragrunt.hcl file), a strong coupling between stack and unit form:My biggest issue with this option is that it forces the module/unit author to pre-determine how the inputs are going to be used (the inputs of another module, vs static). It prevents someone from changing a dependency input to a value input. My main argument here is that the stack author, not the unit author, should make this decision.
A secondary issue is that it surfaces what I believe should be hidden implementation details (the name "test_dep_one").
I suspect I am off-base on a lot of this! Let me know where I veered off course here :)
JIT Dependency Graph
Since values can be used inside the path, some dependencies would have to be evaluated while the graph is being created. I could see this causing performance issues with
terragrunt graph(although you could add flags to create a partial graph). This option would add a fair amount of complexity, and seems to provide little value (who needs an infrastructure Abstract Factory?).Limit the use of values using dependencies
This option would prevent dependency-based values from being used anywhere except for the
inputsblock. This was the initial intention of this RFC, and seems like a reasonable limitation given that terraform often has the same limitations (variables module paths, etc).Dependency blocks are scoped to the file that defines them. A terragrunt.values.hcl can define
dependencyblocks that are referenced in value definitions, like so:In order to use them in
terragrunt.hcl, reference the value that they were assigned to, like so:riccardomassullo commentedon May 24, 2025
A similar/extended RFC where also stacks values referencing is taken in account would be very helpful (at least from my point of view)
e.g. I want to pass an output value of a unit to other units, stacks or i want to pass the output of a stack into another stack
Is this possible in any way with the new units/stack feature? Using only traditional terragrunt units, defining stacks as folders containing units and referencing the units directly works as i wish.
Obviously (or at least in my case), using the output of the entire stack instead of hundreds of small units referenced between them, in a lot of cases, would lead to a much cleaner infra.
talpa-robin commentedon May 26, 2025
I don't know if that RFC already covers that (or should cover that at all) but one scenario that I haven't seen been mentioned is where a single standalone unit (maybe from times before Stacks) needs an output from a unit in a stack. In our current example we've build an EKS stack that includes a couple of units to bootstrap a fully working EKS cluster and now we have an older module which needs the OIDC provider ARN of the EKS cluster as an input.
But independent from "older / newer" code, IMO, there will always be scenarios where you don't want to wrap everything in a stack but need the output from one and there should be a "native" way to reference the outputs of units within a stack.
anocendi commentedon May 27, 2025
I would love to see this capability implemented in
terragrunt stacksas well!Our existing setup mimics
unitsandstacksin a very hacky way. If the capability in this issue is implemented, we should be able to migrate with some small-sized work to become moreterragruntproper.andromeda306 commentedon Jun 3, 2025
Is there a clear guide on how to implement dependencies in their current state? I'm finding it difficult to differentiate what is a real example vs. what are people proposing with a POC vs. what is in fact a working example but symbolised using generic terminology.
yhakbar commentedon Jun 3, 2025
@andromeda306
Take a look at these examples.
yhakbar commentedon Jun 3, 2025
@talpa-robin
No, that isn't supported right now, or really part of this RFC as I understand it. From what I understand, what you're asking for is the ability to add a dependency that points to a Terragrunt Stack. We are planning on adding that in the future, but to achieve that, we're going to need to implement Runner Pools first.
The reason is that right now, there's nothing in Terragrunt's internals that allows Terragrunt Stacks to be part of the Directed Acyclic Graph (DAG). Only units can be part of the DAG. We're looking to make it possible to have either component be part of the DAG as part of the work that's incidental to getting Runner Pools implemented.
yhakbar commentedon Jun 3, 2025
@cgetzen
Before you read this long response to your comment above, I want to highlight that I really appreciate you putting this RFC together, and creating the prototype to explore the proposal. It might not be obvious, but going through a lot of back and forth on design is something we do a lot of internally at Gruntwork, so I don't want to give the impression that I'm only supplying objections to your proposal. It can be hard to receive critique of designs you put effort into creating, but we try to do this to get to more robust designs before we build anything we have to maintain for a long time.
To be clear, I'm not saying adding a
terragrunt.dependencies.hclfile is the best solution. I was asking if alternatives are being evaluated here. I think there are multiple ways to solve the problem outlined here, and working out the best solution might take some more exploration of alternatives.Dependencies are not simply a value fetching mechanism, they drive a lot of how Terragrunt behaves. For example, when applying units, Terragrunt will always apply dependencies before dependents. When destroying units, Terragrunt will always destroy dependents before dependencies. Without a consistent approach to defining dependencies, it's harder for users to reason about what Terragrunt will do at runtime. This is why it's also important to consider when dependencies are evaluated. In the original proposal, there are two phases where dependencies are evaluated:
terragrunt.values.hclfile is being evaluated.terragrunt.hclfile is being evaluated.Especially considering that the first phase can influence the second phase (the output of one dependency defined in
terragrunt.values.hclcould be interpolated into theconfig_pathof another dependency defined interragrunt.hcl), this means that dependencies for units can't be established in one go, significantly complicating DAG resolution. Ideally, we never have to fork an OpenTofu/Terraform process fortofu output -jsonbefore we have determined the full DAG of units we need to run.I'm not sure where I recommended considering a
terragrunt.dependencies.hclfile, but the idea would have been that you just automatically merge the contents of that file into theterragrunt.hclfile during parsing (similar to anincludeblock), then do a single phase of dependency resolution on the resultant configuration.To that end, I'm asking that approaches which result in a single phase of dependency evaluation is taken into consideration. To explicitly guide you towards evaluating some other options, consider the possibilities of:
terragrunt.hclandterragrunt.stack.hclfiles.terragrunt.hclfiles.In the first possibility,
terragrunt.stack.hclfiles might support something like the following:Similar to the generate block.
Which would result in the generated
.terragrunt-stack/foo/terragrunt.hclfile having the following embedded within it:The benefits here compared to the original proposal are that:
terragrunt.hclfile that's evaluated during runs. Nothing about how unit or values configuration parsing have to change for this to be supported, and users don't have to learn any new syntax (aside from the new configuration block interragrunt.stack.hclfiles).terragrunt.stack.hclfiles, including exclude blocks.terragrunt.hclfile. What you see is what you get.terragrunt.stack.hclfiles are generated with this approach.The trade-offs of this design are that:
terragrunt.hclfiles generated byunitblocks interragrunt.stack.hclfiles will be exactly what they were in the source configuration. If you upgrade the version of your unit configuration, there may be unintended interactions with embeds that you don't expect.terragrunt.hclfile, and the embed from theterragrunt.stack.hclfile. If a user wants to define some inputs in theterragrunt.hclfile and the embed, they're out of luck without some complex logic.terragrunt.hclfiles is less reliable than a configuration that's validated before generation. There might be ways to add additional features to theembedconfiguration block to mitigate this (e.g. validate that it's proper HCL before generation).In the second possibility, it might be preferable to alter the first design to instead require that the embedding is always done in the form of an added include.
Would instead result in the generated
.terragrunt-stack/foo/terragrunt.hclfile like the following:The benefits here compared to the first possibility are that:
terragrunt.hclconfiguration. You don't have to learn any new unit configuration syntax.terragrunt.hclfile, and the embed from theterragrunt.stack.hclfile, following the same rules for allincludeblocks. If, for example, you want to define some inputs in the sourceterragrunt.hclfile, and define includes in the embed, you can do that, and they'll be merged together.terragrunt.stack.hclfile.The trade-offs of this design are that:
terragrunt.hclfile being exactly what they wrote in the source unit configuration. If you upgrade the version of your unit configuration, there may be unintended interactions with includes that you don't expect.includeblock to theterragrunt.hclfile, and then add a new file to the generated unit.terragrunt.hclfile. You have to read theterragrunt.hclfile, find theincludeblock, and then read the file it's pointing to.terragrunt.stack.hclfiles the way that the first design can (though, this might be a reason to add support forincludeblocks interragrunt.stack.hclfiles).To reiterate, I'm not saying that either of these designs are the best solution either. I'm just trying to guide you towards evaluating some other options that don't have the same trade-off involving complicating DAG resolution, as that's where I feel the original proposal will introduce the most unintended side-effects to how Terragrunt behaves.
10 remaining items
bputt-e commentedon Dec 15, 2025
whatever the solution is, hoping there's a path forward to prevent infrastructure from being deleted in order to conform to the updated standard.
Just an example use case, let's say we have 1 aws account that contains multiple environments (prod/staging) and we have account level settings and regional settings that we'd like to configure.
For that example, we'd like to do two things:
Obviously if this is a really bad pattern, feel free to recommend a better approach. For now, we'd accomplish this by merging everything under
<region>into 1 stack filememdealer commentedon Jan 15, 2026
+1 for this feature.
Here's my use case - I want to pass dynamic data (Cloudflare IPs fetched via HTTP)
to firewall rules, while keeping config in tfvars:
The current
values+ path indirection pattern is awkward.Direct unit output references +
inputs+dependencieswould make stacksactually usable for real infrastructure.
ye-orlov commentedon Jan 15, 2026
+1 for this future.
rlaschuk-ledger commentedon Jan 15, 2026
+1
ethangamma24 commentedon Jan 19, 2026
+1. Would be such a huge help for my company's current implementation of Terragrunt.
pdrd commentedon Feb 6, 2026
+1
dunk2k commentedon Feb 9, 2026
+1
My use case is, and is per AWS prescriptive guidance for Hub Spoke networking model:
Using a Terragrunt Stack (Stack 1), deploy a Transit Gateway (TGW) into "Shared Services" VPC hosted in a "Shared Services" AWS Account. Use Resource Access Manager (RAM) to share TGW to multiple ${application}-{environment} AWS Accounts.
Inside each ${application}-{environment} AWS Account, the deployment of resources, as a Terragrunt Stack, references .outputs of Stack 1, i.e. transit gateway ID, transit gateway route tables, security group ID(s)
Going by the current Terragrunt stacks multi-env example, of utilising nested stacks, deploying resources across multiple accounts for multiple differing workloads/purposes using a single "master" Terragrunt stack seems like a backwards and inflexible approach.
Iron-E commentedon Feb 26, 2026
This seems like a related proposal: #4904
Dav3rs commentedon Mar 3, 2026
From my perspective, Terragrunt Stacks are not really usable without this capability.
In our case, this limitation is currently blocking a broader migration effort. We are planning to migrate our GCP infrastructure from vanilla Terraform to an orchestrator, but the current state of Stacks makes it difficult to move forward with Terragrunt.
We are also evaluating Atmos. However, it still doesn’t support SOPS, which is a hard requirement for us. So at the moment, we’re effectively waiting to see which project resolves its gap first.
yhakbar commentedon Mar 3, 2026
To give folks an update: We definitely will support something like this after the release of 1.0.
I've been working on a proposal to address this in a way that will address both this and #4904 in a way that's flexible enough to support all the ways in which dependencies have to work in, across and on stacks. The thing that makes this proposal take a while is ensuring that it addresses the full flexibility required for dependencies, including mock outputs, DAG resolution for units in a stack, etc.
You should have experimental support for this early after the release of 1.0, and it should make it to the release of 1.1.
If you need to wire together dependencies in the interim, you can use the workaround shown here:
https://github.com/gruntwork-io/terragrunt-infrastructure-catalog-example/blob/main/examples/terragrunt/stacks/stateful-asg-service/terragrunt.stack.hcl
yhakbar commentedon Mar 4, 2026
Hey folks,
I've been able to put some time to publish this RFC that outlines a proposed solution to this problem:
#5663
Please share your feedback!
yhakbar commentedon May 14, 2026
Hey @cgetzen,
How would you feel about closing out this issue in favor of #5663?
Does it address the use-case you were asking addressed with this RFC?
cgetzen commentedon May 15, 2026
Sounds good!
yhakbar commentedon May 15, 2026
Closing out in favor of #5663