From 114315d502888302ea192a43923b6b140e6cd59c Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Thu, 26 Jan 2017 18:07:37 -0800 Subject: [PATCH] terraform: delete legacy outputs --- terraform/graph_config_node_output.go | 106 ---------------------- terraform/graph_config_node_test.go | 8 -- terraform/transform_config_old.go | 5 - terraform/transform_config_old_test.go | 14 --- terraform/transform_flatten_test.go | 7 -- terraform/transform_output_orphan.go | 101 --------------------- terraform/transform_output_orphan_test.go | 51 ----------- 7 files changed, 292 deletions(-) delete mode 100644 terraform/graph_config_node_output.go delete mode 100644 terraform/transform_output_orphan.go delete mode 100644 terraform/transform_output_orphan_test.go diff --git a/terraform/graph_config_node_output.go b/terraform/graph_config_node_output.go deleted file mode 100644 index 0704a0cb7..000000000 --- a/terraform/graph_config_node_output.go +++ /dev/null @@ -1,106 +0,0 @@ -package terraform - -import ( - "fmt" - - "github.com/hashicorp/terraform/config" - "github.com/hashicorp/terraform/dag" -) - -// 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) ConfigType() GraphNodeConfigType { - return GraphNodeConfigTypeOutput -} - -func (n *GraphNodeConfigOutput) OutputName() string { - return 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 &EvalOpFilter{ - Ops: []walkOperation{walkRefresh, walkPlan, walkApply, - walkDestroy, walkInput, walkValidate}, - Node: &EvalSequence{ - Nodes: []EvalNode{ - &EvalWriteOutput{ - Name: n.Output.Name, - Sensitive: n.Output.Sensitive, - Value: n.Output.RawConfig, - }, - }, - }, - } -} - -// GraphNodeProxy impl. -func (n *GraphNodeConfigOutput) Proxy() bool { - return true -} - -// GraphNodeDestroyEdgeInclude impl. -func (n *GraphNodeConfigOutput) DestroyEdgeInclude(dag.Vertex) bool { - return false -} - -// GraphNodeFlattenable impl. -func (n *GraphNodeConfigOutput) Flatten(p []string) (dag.Vertex, error) { - return &GraphNodeConfigOutputFlat{ - GraphNodeConfigOutput: n, - PathValue: p, - }, nil -} - -// Same as GraphNodeConfigOutput, but for flattening -type GraphNodeConfigOutputFlat struct { - *GraphNodeConfigOutput - - PathValue []string -} - -func (n *GraphNodeConfigOutputFlat) Name() string { - return fmt.Sprintf( - "%s.%s", modulePrefixStr(n.PathValue), n.GraphNodeConfigOutput.Name()) -} - -func (n *GraphNodeConfigOutputFlat) Path() []string { - return n.PathValue -} - -func (n *GraphNodeConfigOutputFlat) DependableName() []string { - return modulePrefixList( - n.GraphNodeConfigOutput.DependableName(), - modulePrefixStr(n.PathValue)) -} - -func (n *GraphNodeConfigOutputFlat) DependentOn() []string { - prefix := modulePrefixStr(n.PathValue) - return modulePrefixList( - n.GraphNodeConfigOutput.DependentOn(), - prefix) -} diff --git a/terraform/graph_config_node_test.go b/terraform/graph_config_node_test.go index 670f07b39..f49b0a550 100644 --- a/terraform/graph_config_node_test.go +++ b/terraform/graph_config_node_test.go @@ -8,14 +8,6 @@ import ( "github.com/hashicorp/terraform/dag" ) -func TestGraphNodeConfigOutput_impl(t *testing.T) { - var _ dag.Vertex = new(GraphNodeConfigOutput) - var _ dag.NamedVertex = new(GraphNodeConfigOutput) - var _ graphNodeConfig = new(GraphNodeConfigOutput) - var _ GraphNodeOutput = new(GraphNodeConfigOutput) - var _ GraphNodeProxy = new(GraphNodeConfigOutput) -} - func TestGraphNodeConfigProvider_impl(t *testing.T) { var _ dag.Vertex = new(GraphNodeConfigProvider) var _ dag.NamedVertex = new(GraphNodeConfigProvider) diff --git a/terraform/transform_config_old.go b/terraform/transform_config_old.go index 5f9851681..94e4ce6cd 100644 --- a/terraform/transform_config_old.go +++ b/terraform/transform_config_old.go @@ -79,11 +79,6 @@ func (t *ConfigTransformerOld) 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_old_test.go b/terraform/transform_config_old_test.go index a5b0bbfbc..8ef840d42 100644 --- a/terraform/transform_config_old_test.go +++ b/terraform/transform_config_old_test.go @@ -72,20 +72,6 @@ func TestConfigTransformerOld_modules(t *testing.T) { } } -func TestConfigTransformerOld_outputs(t *testing.T) { - g := Graph{Path: RootModulePath} - tf := &ConfigTransformerOld{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 TestConfigTransformerOld_providerAlias(t *testing.T) { g := Graph{Path: RootModulePath} tf := &ConfigTransformerOld{Module: testModule(t, "graph-provider-alias")} diff --git a/terraform/transform_flatten_test.go b/terraform/transform_flatten_test.go index 47bc5d2c5..68b49d9a5 100644 --- a/terraform/transform_flatten_test.go +++ b/terraform/transform_flatten_test.go @@ -69,11 +69,8 @@ func TestFlattenTransformer_withProxy(t *testing.T) { const testTransformFlattenStr = ` aws_instance.parent aws_instance.parent-output - module.child.output.output module.child.aws_instance.child module.child.var.var -module.child.output.output - module.child.aws_instance.child module.child.plan-destroy module.child.var.var aws_instance.parent @@ -82,13 +79,9 @@ module.child.var.var 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.plan-destroy module.child.var.var aws_instance.parent diff --git a/terraform/transform_output_orphan.go b/terraform/transform_output_orphan.go deleted file mode 100644 index ffaa0b7e2..000000000 --- a/terraform/transform_output_orphan.go +++ /dev/null @@ -1,101 +0,0 @@ -package terraform - -import ( - "fmt" - - "github.com/hashicorp/terraform/dag" -) - -// GraphNodeOutput is an interface that nodes that are outputs must -// implement. The OutputName returned is the name of the output key -// that they manage. -type GraphNodeOutput interface { - OutputName() string -} - -// AddOutputOrphanTransformer is a transformer that adds output orphans -// to the graph. Output orphans are outputs that are no longer in the -// configuration and therefore need to be removed from the state. -// -// NOTE: This is the _old_ way to add output orphans that is used with -// legacy graph builders. The new way is OrphanOutputTransformer. -type AddOutputOrphanTransformer struct { - State *State -} - -func (t *AddOutputOrphanTransformer) Transform(g *Graph) error { - // Get the state for this module. If we have no state, we have no orphans - state := t.State.ModuleByPath(g.Path) - if state == nil { - return nil - } - - // Create the set of outputs we do have in the graph - found := make(map[string]struct{}) - for _, v := range g.Vertices() { - on, ok := v.(GraphNodeOutput) - if !ok { - continue - } - - found[on.OutputName()] = struct{}{} - } - - // Go over all the outputs. If we don't have a graph node for it, - // create it. It doesn't need to depend on anything, since its just - // setting it empty. - for k, _ := range state.Outputs { - if _, ok := found[k]; ok { - continue - } - - g.Add(&graphNodeOrphanOutput{OutputName: k}) - } - - return nil -} - -type graphNodeOrphanOutput struct { - OutputName string -} - -func (n *graphNodeOrphanOutput) Name() string { - return fmt.Sprintf("output.%s (orphan)", n.OutputName) -} - -func (n *graphNodeOrphanOutput) EvalTree() EvalNode { - return &EvalOpFilter{ - Ops: []walkOperation{walkApply, walkDestroy, walkRefresh}, - Node: &EvalDeleteOutput{ - Name: n.OutputName, - }, - } -} - -// GraphNodeFlattenable impl. -func (n *graphNodeOrphanOutput) Flatten(p []string) (dag.Vertex, error) { - return &graphNodeOrphanOutputFlat{ - graphNodeOrphanOutput: n, - PathValue: p, - }, nil -} - -type graphNodeOrphanOutputFlat struct { - *graphNodeOrphanOutput - - PathValue []string -} - -func (n *graphNodeOrphanOutputFlat) Name() string { - return fmt.Sprintf( - "%s.%s", modulePrefixStr(n.PathValue), n.graphNodeOrphanOutput.Name()) -} - -func (n *graphNodeOrphanOutputFlat) EvalTree() EvalNode { - return &EvalOpFilter{ - Ops: []walkOperation{walkApply, walkDestroy, walkRefresh}, - Node: &EvalDeleteOutput{ - Name: n.OutputName, - }, - } -} diff --git a/terraform/transform_output_orphan_test.go b/terraform/transform_output_orphan_test.go deleted file mode 100644 index 1c930ffa3..000000000 --- a/terraform/transform_output_orphan_test.go +++ /dev/null @@ -1,51 +0,0 @@ -package terraform - -import ( - "strings" - "testing" -) - -func TestAddOutputOrphanTransformer(t *testing.T) { - mod := testModule(t, "transform-orphan-output-basic") - state := &State{ - Modules: []*ModuleState{ - &ModuleState{ - Path: RootModulePath, - Outputs: map[string]*OutputState{ - "foo": &OutputState{ - Value: "bar", - Type: "string", - }, - "bar": &OutputState{ - Value: "baz", - Type: "string", - }, - }, - }, - }, - } - - g := Graph{Path: RootModulePath} - { - tf := &ConfigTransformerOld{Module: mod} - if err := tf.Transform(&g); err != nil { - t.Fatalf("err: %s", err) - } - } - - transform := &AddOutputOrphanTransformer{State: state} - if err := transform.Transform(&g); err != nil { - t.Fatalf("err: %s", err) - } - - actual := strings.TrimSpace(g.String()) - expected := strings.TrimSpace(testTransformOrphanOutputBasicStr) - if actual != expected { - t.Fatalf("bad:\n\n%s", actual) - } -} - -const testTransformOrphanOutputBasicStr = ` -output.bar (orphan) -output.foo -`