terraform: transform module variables does parent first
This commit is contained in:
parent
924f7a49e0
commit
9ac4ee4b52
|
@ -28,21 +28,16 @@ func (t *ModuleVariableTransformer) transform(g *Graph, parent, m *module.Tree)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we have no parent, then don't do anything. This is because
|
// If we have a parent, we can determine if a module variable is being
|
||||||
// we need to be able to get the set value from the module declaration.
|
// used, so we transform this.
|
||||||
if err := t.transformSingle(g, parent, m); err != nil {
|
if parent != nil {
|
||||||
return nil
|
if err := t.transformSingle(g, parent, m); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Transform all the children. This has to be _after_ the above
|
// Transform all the children. This must be done AFTER the transform
|
||||||
// since children can reference parent variables but parents can't
|
// above since child module variables can reference parent module variables.
|
||||||
// access children. Example:
|
|
||||||
//
|
|
||||||
// module foo { value = "${var.foo}" }
|
|
||||||
//
|
|
||||||
// The "value" var in "foo" (a child) is accessing the "foo" bar
|
|
||||||
// in the parent (current module). However, there is no way for the
|
|
||||||
// current module to reference a variable in the child module.
|
|
||||||
for _, c := range m.Children() {
|
for _, c := range m.Children() {
|
||||||
if err := t.transform(g, m, c); err != nil {
|
if err := t.transform(g, m, c); err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -53,11 +48,6 @@ func (t *ModuleVariableTransformer) transform(g *Graph, parent, m *module.Tree)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *ModuleVariableTransformer) transformSingle(g *Graph, parent, m *module.Tree) error {
|
func (t *ModuleVariableTransformer) transformSingle(g *Graph, parent, m *module.Tree) error {
|
||||||
// If we have no parent, we can't determine if the parent uses our variables
|
|
||||||
if parent == nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// If we have no vars, we're done!
|
// If we have no vars, we're done!
|
||||||
vars := m.Config().Variables
|
vars := m.Config().Variables
|
||||||
if len(vars) == 0 {
|
if len(vars) == 0 {
|
||||||
|
|
Loading…
Reference in New Issue