-
Notifications
You must be signed in to change notification settings - Fork 9.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow replace_triggered_by
to refer to module or module resource
#31713
Comments
Thanks for filing this request! |
Hi @FWest98! Thanks for sharing this idea. I think one crucial part of designing this will be to try to define exactly what a "change inside a module" means. I say this because we already have one existing behavior where we use a module as a whole as a dependency node: if a And we've seen from questions elsewhere that authors find this behavior surprising: their intent was often to single out just a few managed resources inside the module but they used whole-module I would therefore worry about a similar problem if The comparison to dependencies might also help inform an answer, though: the usual answer to making finer-grain dependencies across a module boundary is to use dependencies on individual input variables and individual output values rather than the module as a whole, and let the dependencies "flow through" those external integration points. That isn't currently possible for "replace triggering" because Terraform only knows how to walk one hop and check whether the directly-mentioned object has changed. For example, we could investigate the possibility of allowing output values themselves having I think an initial challenge to overcome with that is how it would work with modules that have either |
Hi @FWest98, this use case was definitely discussed during the initial investigation into this feature. There were many reasons that the triggering events are limited to changes in managed resources, but the reason for the scope being limited to the containing module is more about the fact that the designed scope for all references is limited to the current module. The ability to reference something in an expression outside of one's scope would be quite a major change. The recommended way to trigger something based on a change in a separate module is to route the desired outputs into a managed resource which can be monitored for changes. Currently the most convent resource for this is a |
Thanks for both of your replies! I see the issues in both linking to a resource inside a module, and with a resource as a whole, like you describe. Indeed then, I think linking to an output value of a module is the most robust option for nwo, and indeed the pattern with the I do still think some better overarching vision on replacement-dependencies, cycles and ephemeral resources (as in my other issue) would be good to have in the long term, as currently "plumbing" everything with |
Given that |
@jbardin I'm currently facing this exact problem. When I found this issue I was happy to hear there is a solution. But as far as I can see the referenced merge request has not been part of a release yet. Is that the case? If so, would you know when it might be released? |
@MLNW there is no set date for the v1.4 release yet. Note that the intended solution for v1.3 and earlier is to use |
@jbardin we were able to get a workaround going via an output from our module and using it as a trigger in a |
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. |
Terraform Version
Use Cases
I would like to have a resource be automatically recreated when one of the subresources of a module is recreated. An example use case would be: a module to deploy and provision a VM; then outside of the module we would add a
time_sleep
resource that will wait for the provisioning to be done, after which further resources are created. When the VM has to be recreated, I would like to be able to also automatically recreate the timeout.Attempted Solutions
Currently, attempting to refer a module (or subresource) in the
replace_triggered_by
field gives an error sayingMissing resource reference in replace_triggered_by expression
. The best I can do is have a trigger on some output variable of the module.Proposal
I think it might be tricky to get this right, as I can see the argument of having the module function as a "black box" and that the consuming code shouldn't have to bother with implementation details; allowing a lifecycle dependency on a subresource would break this abstraction and might cause maintenance issues where modules are no longer easily replaceable.
So maybe something is possible on the module level? For example, allowing to depend on the module as a whole and making any change inside the module trigger the recreation of the dependent resource.
References
No response
The text was updated successfully, but these errors were encountered: