terraform: provisioner dependencies are reflected in graph
This commit is contained in:
parent
d4d58ae44b
commit
f74a27d75f
|
@ -1190,8 +1190,20 @@ func nounAddVariableDeps(
|
|||
name = fmt.Sprintf("module.%s", v.Name)
|
||||
target = g.Noun(name)
|
||||
case *config.ResourceVariable:
|
||||
name = v.ResourceId()
|
||||
target = g.Noun(v.ResourceId())
|
||||
// For resource variables, if we ourselves are a resource, then
|
||||
// we have to check whether to expand or not to create the proper
|
||||
// resource dependency.
|
||||
rn, ok := n.Meta.(*GraphNodeResource)
|
||||
if !ok || rn.ExpandMode > ResourceExpandNone {
|
||||
name = v.ResourceId()
|
||||
target = g.Noun(v.ResourceId())
|
||||
break
|
||||
}
|
||||
|
||||
// We're an expanded resource, so add the specific index
|
||||
// as the dependency.
|
||||
name = fmt.Sprintf("%s.%d", v.ResourceId(), v.Index)
|
||||
target = g.Noun(name)
|
||||
default:
|
||||
}
|
||||
|
||||
|
@ -1640,6 +1652,9 @@ func (n *GraphNodeResource) Expand() (*depgraph.Graph, error) {
|
|||
}
|
||||
}
|
||||
|
||||
// Add all the variable dependencies
|
||||
graphAddVariableDeps(g)
|
||||
|
||||
// If we're just expanding the apply, then filter those out and
|
||||
// return them now.
|
||||
if n.ExpandMode == ResourceExpandApply {
|
||||
|
|
|
@ -1007,6 +1007,38 @@ func TestGraphNodeResourceExpand(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestGraphNodeResourceExpand_provDeps(t *testing.T) {
|
||||
m := testModule(t, "graph-resource-expand-prov-deps")
|
||||
provs := map[string]ResourceProvisionerFactory{
|
||||
"remote-exec": func() (ResourceProvisioner, error) {
|
||||
return new(MockResourceProvisioner), nil
|
||||
},
|
||||
}
|
||||
|
||||
g, err := Graph(&GraphOpts{Module: m, Provisioners: provs})
|
||||
if err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
|
||||
// Get the resource we care about expanding
|
||||
n := g.Noun("aws_instance.web")
|
||||
if n == nil {
|
||||
t.Fatal("could not find")
|
||||
}
|
||||
rn := n.Meta.(*GraphNodeResource)
|
||||
|
||||
g, err = rn.Expand()
|
||||
if err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
|
||||
actual := strings.TrimSpace(g.String())
|
||||
expected := strings.TrimSpace(testTerraformGraphResourceExpandProvDepsStr)
|
||||
if actual != expected {
|
||||
t.Fatalf("bad:\n\nactual:\n%s\n\nexpected:\n%s", actual, expected)
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
func TestGraphNodeResourceExpand_tainted(t *testing.T) {
|
||||
m := testModule(t, "graph-resource-expand")
|
||||
|
@ -1381,6 +1413,19 @@ root
|
|||
root -> aws_instance.web.2
|
||||
`
|
||||
|
||||
const testTerraformGraphResourceExpandProvDepsStr = `
|
||||
root: root
|
||||
aws_instance.web.0
|
||||
aws_instance.web.1
|
||||
aws_instance.web.1 -> aws_instance.web.0
|
||||
aws_instance.web.2
|
||||
aws_instance.web.2 -> aws_instance.web.0
|
||||
root
|
||||
root -> aws_instance.web.0
|
||||
root -> aws_instance.web.1
|
||||
root -> aws_instance.web.2
|
||||
`
|
||||
|
||||
const testTerraformGraphResourceExpandTaintStr = `
|
||||
root: root
|
||||
aws_instance.web.0
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
resource "aws_instance" "web" {
|
||||
count = 3
|
||||
|
||||
provisioner "remote-exec" {
|
||||
inline = ["echo ${aws_instance.web.0.foo}"]
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue