Documentation ¶
Index ¶
- type Expander
- func (e *Expander) ExpandModule(addr addrs.Module) []addrs.ModuleInstance
- func (e *Expander) ExpandModuleResource(moduleAddr addrs.Module, resourceAddr addrs.Resource) []addrs.AbsResourceInstance
- func (e *Expander) ExpandResource(resourceAddr addrs.AbsResource) []addrs.AbsResourceInstance
- func (e *Expander) GetModuleInstanceRepetitionData(addr addrs.ModuleInstance) RepetitionData
- func (e *Expander) GetResourceInstanceRepetitionData(addr addrs.AbsResourceInstance) RepetitionData
- func (e *Expander) SetModuleCount(parentAddr addrs.ModuleInstance, callAddr addrs.ModuleCall, count int)
- func (e *Expander) SetModuleForEach(parentAddr addrs.ModuleInstance, callAddr addrs.ModuleCall, ...)
- func (e *Expander) SetModuleSingle(parentAddr addrs.ModuleInstance, callAddr addrs.ModuleCall)
- func (e *Expander) SetResourceCount(moduleAddr addrs.ModuleInstance, resourceAddr addrs.Resource, count int)
- func (e *Expander) SetResourceForEach(moduleAddr addrs.ModuleInstance, resourceAddr addrs.Resource, ...)
- func (e *Expander) SetResourceSingle(moduleAddr addrs.ModuleInstance, resourceAddr addrs.Resource)
- type RepetitionData
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Expander ¶
type Expander struct {
// contains filtered or unexported fields
}
Expander instances serve as a coordination point for gathering object repetition values (count and for_each in configuration) and then later making use of them to fully enumerate all of the instances of an object.
The two repeatable object types in Terraform are modules and resources. Because resources belong to modules and modules can nest inside other modules, module expansion in particular has a recursive effect that can cause deep objects to expand exponentially. Expander assumes that all instances of a module have the same static objects inside, and that they differ only in the repetition count for some of those objects.
Expander is a synchronized object whose methods can be safely called from concurrent threads of execution. However, it does expect a certain sequence of operations which is normally obtained by the caller traversing a dependency graph: each object must have its repetition mode set exactly once, and this must be done before any calls that depend on the repetition mode. In other words, the count or for_each expression value for a module must be provided before any object nested directly or indirectly inside that module can be expanded. If this ordering is violated, the methods will panic to enforce internal consistency.
The Expand* methods of Expander only work directly with modules and with resources. Addresses for other objects that nest within modules but do not themselves support repetition can be obtained by calling ExpandModule with the containing module path and then producing one absolute instance address per module instance address returned.
func NewExpander ¶
func NewExpander() *Expander
NewExpander initializes and returns a new Expander, empty and ready to use.
func (*Expander) ExpandModule ¶
func (e *Expander) ExpandModule(addr addrs.Module) []addrs.ModuleInstance
ExpandModule finds the exhaustive set of module instances resulting from the expansion of the given module and all of its ancestor modules.
All of the modules on the path to the identified module must already have had their expansion registered using one of the SetModule* methods before calling, or this method will panic.
func (*Expander) ExpandModuleResource ¶
func (e *Expander) ExpandModuleResource(moduleAddr addrs.Module, resourceAddr addrs.Resource) []addrs.AbsResourceInstance
ExpandModuleResource finds the exhaustive set of resource instances resulting from the expansion of the given resource and all of its containing modules.
All of the modules on the path to the identified resource and the resource itself must already have had their expansion registered using one of the SetModule*/SetResource* methods before calling, or this method will panic.
func (*Expander) ExpandResource ¶
func (e *Expander) ExpandResource(resourceAddr addrs.AbsResource) []addrs.AbsResourceInstance
ExpandResource finds the set of resource instances resulting from the expansion of the given resource within its module instance.
All of the modules on the path to the identified resource and the resource itself must already have had their expansion registered using one of the SetModule*/SetResource* methods before calling, or this method will panic.
func (*Expander) GetModuleInstanceRepetitionData ¶
func (e *Expander) GetModuleInstanceRepetitionData(addr addrs.ModuleInstance) RepetitionData
GetModuleInstanceRepetitionData returns an object describing the values that should be available for each.key, each.value, and count.index within the call block for the given module instance.
func (*Expander) GetResourceInstanceRepetitionData ¶
func (e *Expander) GetResourceInstanceRepetitionData(addr addrs.AbsResourceInstance) RepetitionData
GetResourceInstanceRepetitionData returns an object describing the values that should be available for each.key, each.value, and count.index within the definition block for the given resource instance.
func (*Expander) SetModuleCount ¶
func (e *Expander) SetModuleCount(parentAddr addrs.ModuleInstance, callAddr addrs.ModuleCall, count int)
SetModuleCount records that the given module call inside the given parent module instance uses the "count" repetition argument, with the given value.
func (*Expander) SetModuleForEach ¶
func (e *Expander) SetModuleForEach(parentAddr addrs.ModuleInstance, callAddr addrs.ModuleCall, mapping map[string]cty.Value)
SetModuleForEach records that the given module call inside the given parent module instance uses the "for_each" repetition argument, with the given map value.
In the configuration language the for_each argument can also accept a set. It's the caller's responsibility to convert that into an identity map before calling this method.
func (*Expander) SetModuleSingle ¶
func (e *Expander) SetModuleSingle(parentAddr addrs.ModuleInstance, callAddr addrs.ModuleCall)
SetModuleSingle records that the given module call inside the given parent module does not use any repetition arguments and is therefore a singleton.
func (*Expander) SetResourceCount ¶
func (e *Expander) SetResourceCount(moduleAddr addrs.ModuleInstance, resourceAddr addrs.Resource, count int)
SetResourceCount records that the given resource inside the given module uses the "count" repetition argument, with the given value.
func (*Expander) SetResourceForEach ¶
func (e *Expander) SetResourceForEach(moduleAddr addrs.ModuleInstance, resourceAddr addrs.Resource, mapping map[string]cty.Value)
SetResourceForEach records that the given resource inside the given module uses the "for_each" repetition argument, with the given map value.
In the configuration language the for_each argument can also accept a set. It's the caller's responsibility to convert that into an identity map before calling this method.
func (*Expander) SetResourceSingle ¶
func (e *Expander) SetResourceSingle(moduleAddr addrs.ModuleInstance, resourceAddr addrs.Resource)
SetResourceSingle records that the given resource inside the given module does not use any repetition arguments and is therefore a singleton.
type RepetitionData ¶
type RepetitionData struct { // CountIndex is the value for count.index, or cty.NilVal if evaluating // in a context where the "count" argument is not active. // // For correct operation, this should always be of type cty.Number if not // nil. CountIndex cty.Value // EachKey and EachValue are the values for each.key and each.value // respectively, or cty.NilVal if evaluating in a context where the // "for_each" argument is not active. These must either both be set // or neither set. // // For correct operation, EachKey must always be either of type cty.String // or cty.Number if not nil. EachKey, EachValue cty.Value }
RepetitionData represents the values available to identify individual repetitions of a particular object.
This corresponds to the each.key, each.value, and count.index symbols in the configuration language.