From 37294d5ad2c9ee310432d74bedb8b0484b7f6ff2 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Thu, 26 Jan 2017 20:04:39 -0800 Subject: [PATCH] terraform: remove old variable node --- terraform/graph_config_node_variable.go | 174 ------------------- terraform/graph_config_node_variable_test.go | 19 -- terraform/transform_targets.go | 9 - 3 files changed, 202 deletions(-) delete mode 100644 terraform/graph_config_node_variable.go delete mode 100644 terraform/graph_config_node_variable_test.go diff --git a/terraform/graph_config_node_variable.go b/terraform/graph_config_node_variable.go deleted file mode 100644 index b15e09dca..000000000 --- a/terraform/graph_config_node_variable.go +++ /dev/null @@ -1,174 +0,0 @@ -package terraform - -import ( - "fmt" - "log" - - "github.com/hashicorp/terraform/config" - "github.com/hashicorp/terraform/config/module" - "github.com/hashicorp/terraform/dag" -) - -// GraphNodeConfigVariable represents a Variable in the config. -type GraphNodeConfigVariable struct { - Variable *config.Variable - - // Value, if non-nil, will be used to set the value of the variable - // during evaluation. If this is nil, evaluation will do nothing. - // - // Module is the name of the module to set the variables on. - Module string - Value *config.RawConfig - - ModuleTree *module.Tree - ModulePath []string -} - -func (n *GraphNodeConfigVariable) Name() string { - return fmt.Sprintf("var.%s", n.Variable.Name) -} - -func (n *GraphNodeConfigVariable) DependableName() []string { - return []string{n.Name()} -} - -// RemoveIfNotTargeted implements RemovableIfNotTargeted. -// When targeting is active, variables that are not targeted should be removed -// from the graph, because otherwise module variables trying to interpolate -// their references can fail when they're missing the referent resource node. -func (n *GraphNodeConfigVariable) RemoveIfNotTargeted() bool { - return true -} - -func (n *GraphNodeConfigVariable) DependentOn() []string { - // If we don't have any value set, we don't depend on anything - if n.Value == nil { - return nil - } - - // Get what we depend on based on our value - vars := n.Value.Variables - result := make([]string, 0, len(vars)) - for _, v := range vars { - if vn := varNameForVar(v); vn != "" { - result = append(result, vn) - } - } - - return result -} - -func (n *GraphNodeConfigVariable) VariableName() string { - return n.Variable.Name -} - -// GraphNodeDestroyEdgeInclude impl. -func (n *GraphNodeConfigVariable) DestroyEdgeInclude(v dag.Vertex) bool { - // Only include this variable in a destroy edge if the source vertex - // "v" has a count dependency on this variable. - log.Printf("[DEBUG] DestroyEdgeInclude: Checking: %s", dag.VertexName(v)) - cv, ok := v.(GraphNodeCountDependent) - if !ok { - log.Printf("[DEBUG] DestroyEdgeInclude: Not GraphNodeCountDependent: %s", dag.VertexName(v)) - return false - } - - for _, d := range cv.CountDependentOn() { - for _, d2 := range n.DependableName() { - log.Printf("[DEBUG] DestroyEdgeInclude: d = %s : d2 = %s", d, d2) - if d == d2 { - return true - } - } - } - - return false -} - -// GraphNodeEvalable impl. -func (n *GraphNodeConfigVariable) EvalTree() EvalNode { - // If we have no value, do nothing - if n.Value == nil { - return &EvalNoop{} - } - - // Otherwise, interpolate the value of this variable and set it - // within the variables mapping. - var config *ResourceConfig - variables := make(map[string]interface{}) - return &EvalSequence{ - Nodes: []EvalNode{ - &EvalInterpolate{ - Config: n.Value, - Output: &config, - }, - - &EvalVariableBlock{ - Config: &config, - VariableValues: variables, - }, - - &EvalCoerceMapVariable{ - Variables: variables, - ModulePath: n.ModulePath, - ModuleTree: n.ModuleTree, - }, - - &EvalTypeCheckVariable{ - Variables: variables, - ModulePath: n.ModulePath, - ModuleTree: n.ModuleTree, - }, - - &EvalSetVariables{ - Module: &n.Module, - Variables: variables, - }, - }, - } -} - -// GraphNodeFlattenable impl. -func (n *GraphNodeConfigVariable) Flatten(p []string) (dag.Vertex, error) { - return &GraphNodeConfigVariableFlat{ - GraphNodeConfigVariable: n, - PathValue: p, - }, nil -} - -type GraphNodeConfigVariableFlat struct { - *GraphNodeConfigVariable - - PathValue []string -} - -func (n *GraphNodeConfigVariableFlat) Name() string { - return fmt.Sprintf( - "%s.%s", modulePrefixStr(n.PathValue), n.GraphNodeConfigVariable.Name()) -} - -func (n *GraphNodeConfigVariableFlat) DependableName() []string { - return []string{n.Name()} -} - -func (n *GraphNodeConfigVariableFlat) DependentOn() []string { - // We only wrap the dependencies and such if we have a path that is - // longer than 2 elements (root, child, more). This is because when - // flattened, variables can point outside the graph. - prefix := "" - if len(n.PathValue) > 2 { - prefix = modulePrefixStr(n.PathValue[:len(n.PathValue)-1]) - } - - return modulePrefixList( - n.GraphNodeConfigVariable.DependentOn(), - prefix) -} - -func (n *GraphNodeConfigVariableFlat) Path() []string { - if len(n.PathValue) > 2 { - return n.PathValue[:len(n.PathValue)-1] - } - - return nil -} diff --git a/terraform/graph_config_node_variable_test.go b/terraform/graph_config_node_variable_test.go deleted file mode 100644 index 17a1d06a8..000000000 --- a/terraform/graph_config_node_variable_test.go +++ /dev/null @@ -1,19 +0,0 @@ -package terraform - -import ( - "testing" - - "github.com/hashicorp/terraform/dag" -) - -func TestGraphNodeConfigVariable_impl(t *testing.T) { - var _ dag.Vertex = new(GraphNodeConfigVariable) - var _ dag.NamedVertex = new(GraphNodeConfigVariable) - var _ graphNodeConfig = new(GraphNodeConfigVariable) -} - -func TestGraphNodeConfigVariableFlat_impl(t *testing.T) { - var _ dag.Vertex = new(GraphNodeConfigVariableFlat) - var _ dag.NamedVertex = new(GraphNodeConfigVariableFlat) - var _ graphNodeConfig = new(GraphNodeConfigVariableFlat) -} diff --git a/terraform/transform_targets.go b/terraform/transform_targets.go index 0ba98ee15..d83c13f65 100644 --- a/terraform/transform_targets.go +++ b/terraform/transform_targets.go @@ -90,15 +90,6 @@ func (t *TargetsTransformer) selectTargetedNodes( var err error if t.Destroy { deps, err = g.Descendents(v) - - // Select any variables that we depend on in case we need them later for - // interpolating in the count - ancestors, _ := g.Ancestors(v) - for _, a := range ancestors.List() { - if _, ok := a.(*GraphNodeConfigVariableFlat); ok { - deps.Add(a) - } - } } else { deps, err = g.Ancestors(v) }