terraform: connect references
This commit is contained in:
parent
091264e4ba
commit
6914d605c8
|
@ -626,7 +626,7 @@ func TestContext2Plan_moduleVar(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestContext2Plan_moduleVarWrongType(t *testing.T) {
|
func TestContext2Plan_moduleVarWrongTypeBasic(t *testing.T) {
|
||||||
m := testModule(t, "plan-module-wrong-var-type")
|
m := testModule(t, "plan-module-wrong-var-type")
|
||||||
p := testProvider("aws")
|
p := testProvider("aws")
|
||||||
p.DiffFn = testDiffFn
|
p.DiffFn = testDiffFn
|
||||||
|
|
|
@ -80,6 +80,9 @@ func (n *NodePlannableResource) DynamicExpand(ctx EvalContext) (*Graph, error) {
|
||||||
// Attach the state
|
// Attach the state
|
||||||
&AttachStateTransformer{State: state},
|
&AttachStateTransformer{State: state},
|
||||||
|
|
||||||
|
// Connect references so ordering is correct
|
||||||
|
&ReferenceTransformer{},
|
||||||
|
|
||||||
// Make sure there is a single root
|
// Make sure there is a single root
|
||||||
&RootTransformer{},
|
&RootTransformer{},
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ package terraform
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log"
|
||||||
|
|
||||||
"github.com/hashicorp/terraform/config"
|
"github.com/hashicorp/terraform/config"
|
||||||
"github.com/hashicorp/terraform/dag"
|
"github.com/hashicorp/terraform/dag"
|
||||||
|
@ -53,6 +54,14 @@ func (t *ReferenceTransformer) Transform(g *Graph) error {
|
||||||
// Find the things that reference things and connect them
|
// Find the things that reference things and connect them
|
||||||
for _, v := range vs {
|
for _, v := range vs {
|
||||||
parents, _ := m.References(v)
|
parents, _ := m.References(v)
|
||||||
|
parentsDbg := make([]string, len(parents))
|
||||||
|
for i, v := range parents {
|
||||||
|
parentsDbg[i] = dag.VertexName(v)
|
||||||
|
}
|
||||||
|
log.Printf(
|
||||||
|
"[DEBUG] ReferenceTransformer: %q references: %v",
|
||||||
|
dag.VertexName(v), parentsDbg)
|
||||||
|
|
||||||
for _, parent := range parents {
|
for _, parent := range parents {
|
||||||
g.Connect(dag.BasicEdge(v, parent))
|
g.Connect(dag.BasicEdge(v, parent))
|
||||||
}
|
}
|
||||||
|
@ -209,10 +218,9 @@ func NewReferenceMap(vs []dag.Vertex) *ReferenceMap {
|
||||||
func ReferencesFromConfig(c *config.RawConfig) []string {
|
func ReferencesFromConfig(c *config.RawConfig) []string {
|
||||||
var result []string
|
var result []string
|
||||||
for _, v := range c.Variables {
|
for _, v := range c.Variables {
|
||||||
if r := ReferenceFromInterpolatedVar(v); r != "" {
|
if r := ReferenceFromInterpolatedVar(v); len(r) > 0 {
|
||||||
result = append(result, r)
|
result = append(result, r...)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
@ -220,15 +228,16 @@ func ReferencesFromConfig(c *config.RawConfig) []string {
|
||||||
|
|
||||||
// ReferenceFromInterpolatedVar returns the reference from this variable,
|
// ReferenceFromInterpolatedVar returns the reference from this variable,
|
||||||
// or an empty string if there is no reference.
|
// or an empty string if there is no reference.
|
||||||
func ReferenceFromInterpolatedVar(v config.InterpolatedVariable) string {
|
func ReferenceFromInterpolatedVar(v config.InterpolatedVariable) []string {
|
||||||
switch v := v.(type) {
|
switch v := v.(type) {
|
||||||
case *config.ModuleVariable:
|
case *config.ModuleVariable:
|
||||||
return fmt.Sprintf("module.%s.output.%s", v.Name, v.Field)
|
return []string{fmt.Sprintf("module.%s.output.%s", v.Name, v.Field)}
|
||||||
case *config.ResourceVariable:
|
case *config.ResourceVariable:
|
||||||
return v.ResourceId()
|
result := []string{v.ResourceId()}
|
||||||
|
return result
|
||||||
case *config.UserVariable:
|
case *config.UserVariable:
|
||||||
return fmt.Sprintf("var.%s", v.Name)
|
return []string{fmt.Sprintf("var.%s", v.Name)}
|
||||||
default:
|
default:
|
||||||
return ""
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue