From e544e1d4019ce3431eaf40a2310d821962235c3e Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 1 May 2015 11:45:42 -0700 Subject: [PATCH] terraform: hook up the proxies --- terraform/graph_config_node.go | 5 +++ terraform/graph_config_node_module.go | 9 +++++ terraform/graph_config_node_test.go | 2 ++ terraform/graph_config_node_variable.go | 5 +++ terraform/transform_flatten_test.go | 45 +++++++++++++++++++++++++ 5 files changed, 66 insertions(+) diff --git a/terraform/graph_config_node.go b/terraform/graph_config_node.go index 3e21e8052..55c90df8b 100644 --- a/terraform/graph_config_node.go +++ b/terraform/graph_config_node.go @@ -94,6 +94,11 @@ func (n *GraphNodeConfigOutput) EvalTree() EvalNode { } } +// GraphNodeProxy impl. +func (n *GraphNodeConfigOutput) Proxy() bool { + return true +} + // 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/graph_config_node_module.go b/terraform/graph_config_node_module.go index 48c1b6a4f..15fa29ace 100644 --- a/terraform/graph_config_node_module.go +++ b/terraform/graph_config_node_module.go @@ -283,6 +283,15 @@ func (n *graphNodeModuleFlatWrap) DependentOn() []string { return result } +func (n *graphNodeModuleFlatWrap) Proxy() bool { + pn, ok := n.graphNodeModuleWrappable.(GraphNodeProxy) + if !ok { + return false + } + + return pn.Proxy() +} + func (n *graphNodeModuleFlatWrap) prefixList(result []string, prefix string) { for i, v := range result { result[i] = fmt.Sprintf("%s.%s", prefix, v) diff --git a/terraform/graph_config_node_test.go b/terraform/graph_config_node_test.go index b297c6c13..977f5c25f 100644 --- a/terraform/graph_config_node_test.go +++ b/terraform/graph_config_node_test.go @@ -13,6 +13,7 @@ func TestGraphNodeConfigOutput_impl(t *testing.T) { var _ dag.NamedVertex = new(GraphNodeConfigOutput) var _ graphNodeConfig = new(GraphNodeConfigOutput) var _ GraphNodeOutput = new(GraphNodeConfigOutput) + var _ GraphNodeProxy = new(GraphNodeConfigOutput) } func TestGraphNodeConfigProvider_impl(t *testing.T) { @@ -113,4 +114,5 @@ func TestGraphNodeConfigVariable_impl(t *testing.T) { var _ dag.NamedVertex = new(GraphNodeConfigVariable) var _ graphNodeConfig = new(GraphNodeConfigVariable) var _ GraphNodeVariable = new(GraphNodeConfigVariable) + var _ GraphNodeProxy = new(GraphNodeConfigVariable) } diff --git a/terraform/graph_config_node_variable.go b/terraform/graph_config_node_variable.go index b6e539006..964b7b006 100644 --- a/terraform/graph_config_node_variable.go +++ b/terraform/graph_config_node_variable.go @@ -61,3 +61,8 @@ func (n *GraphNodeConfigVariable) VariableName() string { func (n *GraphNodeConfigVariable) SetVariableValue(v *config.RawConfig) { n.Value = v } + +// GraphNodeProxy impl. +func (n *GraphNodeConfigVariable) Proxy() bool { + return true +} diff --git a/terraform/transform_flatten_test.go b/terraform/transform_flatten_test.go index eddad8897..749102469 100644 --- a/terraform/transform_flatten_test.go +++ b/terraform/transform_flatten_test.go @@ -35,6 +35,37 @@ func TestFlattenTransformer(t *testing.T) { } } +func TestFlattenTransformer_withProxy(t *testing.T) { + mod := testModule(t, "transform-flatten") + + var b BasicGraphBuilder + b = BasicGraphBuilder{ + Steps: []GraphTransformer{ + &ConfigTransformer{Module: mod}, + &VertexTransformer{ + Transforms: []GraphVertexTransformer{ + &ExpandTransform{ + Builder: &b, + }, + }, + }, + &FlattenTransformer{}, + &ProxyTransformer{}, + }, + } + + g, err := b.Build(rootModulePath) + if err != nil { + t.Fatalf("err: %s", err) + } + + actual := strings.TrimSpace(g.String()) + expected := strings.TrimSpace(testTransformFlattenProxyStr) + if actual != expected { + t.Fatalf("bad:\n\n%s", actual) + } +} + const testTransformFlattenStr = ` aws_instance.parent aws_instance.parent-output @@ -46,3 +77,17 @@ module.child.output.output module.child.var.var aws_instance.parent ` + +const testTransformFlattenProxyStr = ` +aws_instance.parent +aws_instance.parent-output + module.child.aws_instance.child + module.child.output.output +module.child.aws_instance.child + aws_instance.parent + module.child.var.var +module.child.output.output + module.child.aws_instance.child +module.child.var.var + aws_instance.parent +`