Why does Graph contain modules?

I am trying to debug a problem where Terraform detects a Cycle in apply/destroy (wrongly in my opinion ;)). Now looking at the outputted graph I am quite surprised that every Resource has a reference to its Module. E.g.:
** module.foo (expand)**

Can anyone explain what is going on there? I was under the expression that Modules would be totally transparent - but them turning up in the graph worries me.
Is there a general documentation how to interpret the Graph and the steps it takes to transforms said Graph?

Hi @AndreasBergmeier6176,

The graph output by Terraform is based on internal implementation details, and doesn’t directly reflect the configuration as seen by users. This makes it unsuitable for many end-user applications, however sometimes you can still find it contains some useful information.

Modules are present in the graph because they are an object which must be evaluated, and can also create other objects within the graph. Modules can be expanded with count and for_each, and any references within the module’s meta-attributes will connect that module, and transitively all of its contents, to those references.

There’s no real documentation on the operational graphs within terraform, other than the implementation itself. Individual details of the graphs change quite often as we add and fix various features and bugs.

We do have an open issue to research better ways to communicate cycles to users to help with their debugging, and one idea is to have a separate graph representation dedicated to only showing the configuration. This would help show the simple cases that are detectable statically in the configuration. The hard part is more complicated cases which can only arise during apply, or after instances are expanded, which are much harder to communicate to users without exposing internal implementation details.

1 Like