terraform: delete legacy outputs

This commit is contained in:
Mitchell Hashimoto 2017-01-26 18:07:37 -08:00
parent be56ebf770
commit 114315d502
No known key found for this signature in database
GPG Key ID: 744E147AA52F5B0A
7 changed files with 0 additions and 292 deletions

View File

@ -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)
}

View File

@ -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)

View File

@ -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

View File

@ -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")}

View File

@ -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

View File

@ -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,
},
}
}

View File

@ -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
`