diff --git a/terraform/graph_config_node.go b/terraform/graph_config_node.go index 52ac95322..b39fb0420 100644 --- a/terraform/graph_config_node.go +++ b/terraform/graph_config_node.go @@ -94,6 +94,37 @@ func (n *GraphNodeConfigModule) ProvidedBy() []string { return result } +// GraphNodeConfigOutput represents an output configured within the +// configuration. +type GraphNodeConfigOutput struct { + Output *config.Output +} + +func (n *GraphNodeConfigOutput) Name() string { + return fmt.Sprintf("output.%s", n.Output.Name) +} + +func (n *GraphNodeConfigOutput) DependableName() []string { + return []string{n.Name()} +} + +func (n *GraphNodeConfigOutput) DependentOn() []string { + vars := n.Output.RawConfig.Variables + result := make([]string, 0, len(vars)) + for _, v := range vars { + if vn := varNameForVar(v); vn != "" { + result = append(result, vn) + } + } + + return result +} + +// GraphNodeEvalable impl. +func (n *GraphNodeConfigOutput) EvalTree() EvalNode { + return nil +} + // GraphNodeConfigProvider represents a configured provider within the // configuration graph. These are only immediately in the graph when an // explicit `provider` configuration block is in the configuration. diff --git a/terraform/test-fixtures/graph-outputs/main.tf b/terraform/test-fixtures/graph-outputs/main.tf new file mode 100644 index 000000000..92c4bf226 --- /dev/null +++ b/terraform/test-fixtures/graph-outputs/main.tf @@ -0,0 +1,5 @@ +resource "aws_instance" "foo" {} + +output "foo" { + value = "${aws_instance.foo.value}" +} diff --git a/terraform/transform_config.go b/terraform/transform_config.go index e62074068..3b115688b 100644 --- a/terraform/transform_config.go +++ b/terraform/transform_config.go @@ -63,6 +63,11 @@ func (t *ConfigTransformer) Transform(g *Graph) error { }) } + // Write all the outputs out + for _, o := range config.Outputs { + nodes = append(nodes, &GraphNodeConfigOutput{Output: o}) + } + // Err is where the final error value will go if there is one var err error diff --git a/terraform/transform_config_test.go b/terraform/transform_config_test.go index b361e91be..371f01448 100644 --- a/terraform/transform_config_test.go +++ b/terraform/transform_config_test.go @@ -72,6 +72,20 @@ func TestConfigTransformer_modules(t *testing.T) { } } +func TestConfigTransformer_outputs(t *testing.T) { + g := Graph{Path: RootModulePath} + tf := &ConfigTransformer{Module: testModule(t, "graph-outputs")} + if err := tf.Transform(&g); err != nil { + t.Fatalf("err: %s", err) + } + + actual := strings.TrimSpace(g.String()) + expected := strings.TrimSpace(testGraphOutputsStr) + if actual != expected { + t.Fatalf("bad:\n\n%s", actual) + } +} + func TestConfigTransformer_errMissingDeps(t *testing.T) { g := Graph{Path: RootModulePath} tf := &ConfigTransformer{Module: testModule(t, "graph-missing-deps")} @@ -106,3 +120,9 @@ module.consul aws_security_group.firewall provider.aws ` + +const testGraphOutputsStr = ` +aws_instance.foo +output.foo + aws_instance.foo +`