terraform: Encode dependencies of ResourceMeta ndoes
This commit is contained in:
parent
d61f199d6f
commit
a9c4b523db
|
@ -199,7 +199,13 @@ func EncodeDependencies(g *depgraph.Graph) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
inject = append(inject, target.Resource.Id)
|
inject = append(inject, target.Resource.Id)
|
||||||
// TODO: case *GraphNodeResourceMeta?
|
|
||||||
|
case *GraphNodeResourceMeta:
|
||||||
|
// Inject each sub-resource as a depedency
|
||||||
|
for i := 0; i < target.Count; i++ {
|
||||||
|
id := fmt.Sprintf("%s.%d", target.ID, i)
|
||||||
|
inject = append(inject, id)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -398,6 +398,50 @@ func TestEncodeDependencies(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestEncodeDependencies_Count(t *testing.T) {
|
||||||
|
config := testConfig(t, "graph-count")
|
||||||
|
state := &State{
|
||||||
|
Modules: []*ModuleState{
|
||||||
|
&ModuleState{
|
||||||
|
Path: rootModulePath,
|
||||||
|
Resources: map[string]*ResourceState{
|
||||||
|
"aws_instance.web.0": &ResourceState{
|
||||||
|
Type: "aws_instance",
|
||||||
|
Primary: &InstanceState{
|
||||||
|
ID: "foo",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"aws_load_balancer.weblb": &ResourceState{
|
||||||
|
Type: "aws_load_balancer",
|
||||||
|
Primary: &InstanceState{
|
||||||
|
ID: "foo",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
g, err := Graph(&GraphOpts{Config: config, State: state})
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("err: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// This should encode the dependency information into the state
|
||||||
|
EncodeDependencies(g)
|
||||||
|
|
||||||
|
root := state.RootModule()
|
||||||
|
web := root.Resources["aws_instance.web.0"]
|
||||||
|
if len(web.Dependencies) != 0 {
|
||||||
|
t.Fatalf("bad: %#v", web)
|
||||||
|
}
|
||||||
|
|
||||||
|
weblb := root.Resources["aws_load_balancer.weblb"]
|
||||||
|
if len(weblb.Dependencies) != 3 {
|
||||||
|
t.Fatalf("bad: %#v", weblb)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const testTerraformGraphStr = `
|
const testTerraformGraphStr = `
|
||||||
root: root
|
root: root
|
||||||
aws_instance.web
|
aws_instance.web
|
||||||
|
|
Loading…
Reference in New Issue