diff --git a/terraform/graph_config_node.go b/terraform/graph_config_node.go index 2fc958f0b..84882eae3 100644 --- a/terraform/graph_config_node.go +++ b/terraform/graph_config_node.go @@ -58,7 +58,15 @@ func (n *GraphNodeConfigModule) ConfigType() GraphNodeConfigType { } func (n *GraphNodeConfigModule) DependableName() []string { - return []string{n.Name()} + config := n.Tree.Config() + + result := make([]string, 1, len(config.Outputs)+1) + result[0] = n.Name() + for _, o := range config.Outputs { + result = append(result, fmt.Sprintf("%s.%s", n.Name(), o.Name)) + } + + return result } func (n *GraphNodeConfigModule) DependentOn() []string { diff --git a/terraform/test-fixtures/graph-modules/consul/main.tf b/terraform/test-fixtures/graph-modules/consul/main.tf index aa8f6f032..9e22d04d8 100644 --- a/terraform/test-fixtures/graph-modules/consul/main.tf +++ b/terraform/test-fixtures/graph-modules/consul/main.tf @@ -1 +1,3 @@ resource "aws_instance" "server" {} + +output "security_group" { value = "" } diff --git a/terraform/transform_config.go b/terraform/transform_config.go index 44cc9f57c..878324294 100644 --- a/terraform/transform_config.go +++ b/terraform/transform_config.go @@ -105,7 +105,7 @@ func (t *ConfigTransformer) Transform(g *Graph) error { func varNameForVar(raw config.InterpolatedVariable) string { switch v := raw.(type) { case *config.ModuleVariable: - return fmt.Sprintf("module.%s", v.Name) + return fmt.Sprintf("module.%s.%s", v.Name, v.Field) case *config.ResourceVariable: return v.ResourceId() case *config.UserVariable: diff --git a/terraform/transform_resource.go b/terraform/transform_resource.go index 0289e1a1d..76e65af73 100644 --- a/terraform/transform_resource.go +++ b/terraform/transform_resource.go @@ -174,9 +174,18 @@ func (n *graphNodeExpandedResource) StateDependencies() []string { depsRaw := n.DependentOn() deps := make([]string, 0, len(depsRaw)) for _, d := range depsRaw { - if !strings.HasPrefix(d, "var.") { - deps = append(deps, d) + // Ignore any variable dependencies + if strings.HasPrefix(d, "var.") { + continue } + + // This is sad. The dependencies are currently in the format of + // "module.foo.bar" (the full field). This strips the field off. + if strings.HasPrefix(d, "module.") { + parts := strings.SplitN(d, ".", 3) + d = strings.Join(parts[0:2], ".") + } + deps = append(deps, d) } return deps