github.com/trawler/terraform@v0.10.8-0.20171106022149-4b1c7a1d9b48/terraform/node_local.go (about) 1 package terraform 2 3 import ( 4 "fmt" 5 "strings" 6 7 "github.com/hashicorp/terraform/config" 8 ) 9 10 // NodeLocal represents a named local value in a particular module. 11 // 12 // Local value nodes only have one operation, common to all walk types: 13 // evaluate the result and place it in state. 14 type NodeLocal struct { 15 PathValue []string 16 Config *config.Local 17 } 18 19 func (n *NodeLocal) Name() string { 20 result := fmt.Sprintf("local.%s", n.Config.Name) 21 if len(n.PathValue) > 1 { 22 result = fmt.Sprintf("%s.%s", modulePrefixStr(n.PathValue), result) 23 } 24 25 return result 26 } 27 28 // GraphNodeSubPath 29 func (n *NodeLocal) Path() []string { 30 return n.PathValue 31 } 32 33 // RemovableIfNotTargeted 34 func (n *NodeLocal) RemoveIfNotTargeted() bool { 35 return true 36 } 37 38 // GraphNodeReferenceable 39 func (n *NodeLocal) ReferenceableName() []string { 40 name := fmt.Sprintf("local.%s", n.Config.Name) 41 return []string{name} 42 } 43 44 // GraphNodeReferencer 45 func (n *NodeLocal) References() []string { 46 var result []string 47 result = append(result, ReferencesFromConfig(n.Config.RawConfig)...) 48 for _, v := range result { 49 split := strings.Split(v, "/") 50 for i, s := range split { 51 split[i] = s + ".destroy" 52 } 53 54 result = append(result, strings.Join(split, "/")) 55 } 56 57 return result 58 } 59 60 // GraphNodeEvalable 61 func (n *NodeLocal) EvalTree() EvalNode { 62 return &EvalSequence{ 63 Nodes: []EvalNode{ 64 &EvalOpFilter{ 65 Ops: []walkOperation{ 66 walkInput, 67 walkValidate, 68 walkRefresh, 69 walkPlan, 70 walkApply, 71 }, 72 Node: &EvalSequence{ 73 Nodes: []EvalNode{ 74 &EvalLocal{ 75 Name: n.Config.Name, 76 Value: n.Config.RawConfig, 77 }, 78 }, 79 }, 80 }, 81 &EvalOpFilter{ 82 Ops: []walkOperation{ 83 walkPlanDestroy, 84 walkDestroy, 85 }, 86 Node: &EvalSequence{ 87 Nodes: []EvalNode{ 88 &EvalDeleteLocal{ 89 Name: n.Config.Name, 90 }, 91 }, 92 }, 93 }, 94 }, 95 } 96 }