7 // Module is an address for a module call within configuration. This is
8 // the static counterpart of ModuleInstance, representing a traversal through
9 // the static module call tree in configuration and does not take into account
10 // the potentially-multiple instances of a module that might be created by
11 // "count" and "for_each" arguments within those calls.
13 // This type should be used only in very specialized cases when working with
14 // the static module call tree. Type ModuleInstance is appropriate in more cases.
16 // Although Module is a slice, it should be treated as immutable after creation.
19 // RootModule is the module address representing the root of the static module
20 // call tree, which is also the zero value of Module.
22 // Note that this is not the root of the dynamic module tree, which is instead
23 // represented by RootModuleInstance.
26 // IsRoot returns true if the receiver is the address of the root module,
27 // or false otherwise.
28 func (m Module) IsRoot() bool {
32 func (m Module) String() string {
36 return strings.Join([]string(m), ".")
39 // Child returns the address of a child call in the receiver, identified by the
41 func (m Module) Child(name string) Module {
42 ret := make(Module, 0, len(m)+1)
43 ret = append(ret, m...)
44 return append(ret, name)
47 // Parent returns the address of the parent module of the receiver, or the
48 // receiver itself if there is no parent (if it's the root module address).
49 func (m Module) Parent() Module {
56 // Call returns the module call address that corresponds to the given module
57 // instance, along with the address of the module that contains it.
59 // There is no call for the root module, so this method will panic if called
60 // on the root module address.
62 // In practice, this just turns the last element of the receiver into a
63 // ModuleCall and then returns a slice of the receiever that excludes that
64 // last part. This is just a convenience for situations where a call address
65 // is required, such as when dealing with *Reference and Referencable values.
66 func (m Module) Call() (Module, ModuleCall) {
68 panic("cannot produce ModuleCall for root module")
71 caller, callName := m[:len(m)-1], m[len(m)-1]
72 return caller, ModuleCall{