terraform: Encode dependencies of ResourceMeta ndoes

This commit is contained in:
Armon Dadgar 2014-09-18 11:22:40 -07:00
parent d61f199d6f
commit a9c4b523db
2 changed files with 51 additions and 1 deletions

View File

@ -199,7 +199,13 @@ func EncodeDependencies(g *depgraph.Graph) {
continue
}
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)
}
}
}

View File

@ -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 = `
root: root
aws_instance.web