diff --git a/terraform/graph.go b/terraform/graph.go index b795f4ceb..303a638f4 100644 --- a/terraform/graph.go +++ b/terraform/graph.go @@ -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) + } } } diff --git a/terraform/graph_test.go b/terraform/graph_test.go index 0623c347a..fbf444759 100644 --- a/terraform/graph_test.go +++ b/terraform/graph_test.go @@ -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