-
Notifications
You must be signed in to change notification settings - Fork 9.6k
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
The way terraform variables are defined can cause cyclic dependencies #36226
Comments
Modules are not a single entity, but more like a namespace for holding a portion of the configuration. A module itself cannot depend on another module, but there can be dependencies that flow between them. There are a few cases where this feature is very convenient, but the module must be very well documented to explain how to use it correctly. In general it's not going to be a good idea to have dependencies crossing between modules, only because it makes the configuration hard to understand. I'm not sure I understand what it is you are reporting as a bug however. You can create a cycle between many things in Terraform, and it just happens that some of those cycles can pass through input variables, but variables themselves cannot cause a cycle which doesn't not otherwise exist. Can you give an example of the cycle, and how you would expect it to behave differently? |
Oh, I think I see what you are doing, something descending from from one of
That will plan just fine, because the data flows from
|
Hi @jbardin I can supply more info than below, but I am just about to go on holiday, so will have to follow up in Jan. But I have provided the config below - which I have snipped a lot from to make it readable but hopefully it should be enough to see what it is doing. Here is a working config - note the lines in the root module that read from module outputs, there is a dependency between the modules - and this is working fine. Root module:
The ALB module is public. Here is my Lambda module:
So the above works fine, however, if I alter the variables in the lambda module to be as follows, and of course alter my calling module to pass in the variable values as needed, then I get a cyclic dependcy. The only difference between the two sets of code is the way the variables in the lambda module are defined:
|
Thanks for the extra detail. Yes, that is the exact same situation in my simplified example, it's not anything endemic to variables or modules, it's just a cycle which you cannot have in the configuration. |
I suppose a way to always avoid this problem, would be to only scope an object variable to a single resource in a module, if that module relies on inputs from outside the module itself. I think that would ensure I'd never hit this particular type of cyclic issue at all. Thanks for the replies. |
Terraform Version
Terraform Configuration Files
Variable type A
Variable type B
Debug Output
N/A
Expected Behavior
Two modules can depend on one another. Two resources cannot.
The above config shows two types of variables - one with a separate
external_source_permissions
variable, and one with a single variables that includesexternal_source_permissions
inside that single variable.Variable type A works fine.
Variable type B causes a cyclic dependency in certain situations when there is a cross dependency between two modules.
In effect - the difference in how I layout the variables can cause a cyclic dependecy to happen.
Is this expected - I appreciate the above config is not enough to determine the issue. The question is whether the way modules are set is expected to potentially cause cyclic issues.
If not, then I can send more config to show what exactly happens.
Actual Behavior
N/A
Steps to Reproduce
N/A
Additional Context
No response
References
No response
Generative AI / LLM assisted development?
No response
The text was updated successfully, but these errors were encountered: