terraform: fix crash if depends_on used when state has orphans
This commit is contained in:
parent
1510f12efc
commit
129e4fc453
|
@ -744,6 +744,11 @@ func graphAddExplicitDeps(g *depgraph.Graph) {
|
|||
if !ok {
|
||||
continue
|
||||
}
|
||||
if rn.Config == nil {
|
||||
// Orphan. It can't be depended on or have depends (explicit)
|
||||
// anyways.
|
||||
continue
|
||||
}
|
||||
|
||||
rs[rn.Resource.Id] = n
|
||||
if rn.Config != nil && len(rn.Config.DependsOn) > 0 {
|
||||
|
|
|
@ -97,6 +97,37 @@ func TestGraph_dependsOnCount(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestGraph_dependsOnWithOrphan(t *testing.T) {
|
||||
m := testModule(t, "graph-depends-on")
|
||||
|
||||
state := &State{
|
||||
Modules: []*ModuleState{
|
||||
&ModuleState{
|
||||
Path: []string{"root"},
|
||||
Resources: map[string]*ResourceState{
|
||||
"aws_instance.old": &ResourceState{
|
||||
Type: "aws_instance",
|
||||
Primary: &InstanceState{
|
||||
ID: "foo",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
g, err := Graph(&GraphOpts{Module: m, State: state})
|
||||
if err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
|
||||
actual := strings.TrimSpace(g.String())
|
||||
expected := strings.TrimSpace(testTerraformGraphDependsOrphanStr)
|
||||
if actual != expected {
|
||||
t.Fatalf("bad:\n\n%s", actual)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGraph_modules(t *testing.T) {
|
||||
m := testModule(t, "graph-modules")
|
||||
|
||||
|
@ -1012,6 +1043,18 @@ root
|
|||
root -> aws_instance.web
|
||||
`
|
||||
|
||||
const testTerraformGraphDependsOrphanStr = `
|
||||
root: root
|
||||
aws_instance.db
|
||||
aws_instance.db -> aws_instance.web
|
||||
aws_instance.old
|
||||
aws_instance.web
|
||||
root
|
||||
root -> aws_instance.db
|
||||
root -> aws_instance.old
|
||||
root -> aws_instance.web
|
||||
`
|
||||
|
||||
const testTerraformGraphDiffStr = `
|
||||
root: root
|
||||
aws_instance.foo
|
||||
|
|
Loading…
Reference in New Issue