2016-09-16 01:20:35 -05:00
|
|
|
package terraform
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2016-11-08 11:35:57 -06:00
|
|
|
"strings"
|
2016-09-16 01:20:35 -05:00
|
|
|
|
|
|
|
"github.com/hashicorp/terraform/config"
|
2017-05-10 20:27:49 -05:00
|
|
|
"github.com/hashicorp/terraform/dag"
|
2016-09-16 01:20:35 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
// NodeApplyableOutput represents an output that is "applyable":
|
|
|
|
// it is ready to be applied.
|
|
|
|
type NodeApplyableOutput struct {
|
|
|
|
PathValue []string
|
|
|
|
Config *config.Output // Config is the output in the config
|
|
|
|
}
|
|
|
|
|
|
|
|
func (n *NodeApplyableOutput) Name() string {
|
|
|
|
result := fmt.Sprintf("output.%s", n.Config.Name)
|
|
|
|
if len(n.PathValue) > 1 {
|
|
|
|
result = fmt.Sprintf("%s.%s", modulePrefixStr(n.PathValue), result)
|
|
|
|
}
|
|
|
|
|
|
|
|
return result
|
|
|
|
}
|
|
|
|
|
|
|
|
// GraphNodeSubPath
|
|
|
|
func (n *NodeApplyableOutput) Path() []string {
|
|
|
|
return n.PathValue
|
|
|
|
}
|
|
|
|
|
2017-02-13 14:52:45 -06:00
|
|
|
// RemovableIfNotTargeted
|
|
|
|
func (n *NodeApplyableOutput) RemoveIfNotTargeted() bool {
|
|
|
|
// We need to add this so that this node will be removed if
|
|
|
|
// it isn't targeted or a dependency of a target.
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2017-05-10 20:27:49 -05:00
|
|
|
// GraphNodeTargetDownstream
|
|
|
|
func (n *NodeApplyableOutput) TargetDownstream(targetedDeps, untargetedDeps *dag.Set) bool {
|
|
|
|
// If any of the direct dependencies of an output are targeted then
|
|
|
|
// the output must always be targeted as well, so its value will always
|
|
|
|
// be up-to-date at the completion of an apply walk.
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2016-09-16 01:20:35 -05:00
|
|
|
// GraphNodeReferenceable
|
|
|
|
func (n *NodeApplyableOutput) ReferenceableName() []string {
|
2016-09-16 02:05:57 -05:00
|
|
|
name := fmt.Sprintf("output.%s", n.Config.Name)
|
|
|
|
return []string{name}
|
2016-09-16 01:20:35 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// GraphNodeReferencer
|
|
|
|
func (n *NodeApplyableOutput) References() []string {
|
|
|
|
var result []string
|
2016-11-11 20:16:04 -06:00
|
|
|
result = append(result, n.Config.DependsOn...)
|
2016-09-16 01:20:35 -05:00
|
|
|
result = append(result, ReferencesFromConfig(n.Config.RawConfig)...)
|
2016-10-12 20:43:26 -05:00
|
|
|
for _, v := range result {
|
2016-11-08 11:35:57 -06:00
|
|
|
split := strings.Split(v, "/")
|
|
|
|
for i, s := range split {
|
|
|
|
split[i] = s + ".destroy"
|
|
|
|
}
|
|
|
|
|
|
|
|
result = append(result, strings.Join(split, "/"))
|
2016-10-12 20:43:26 -05:00
|
|
|
}
|
|
|
|
|
2016-09-16 01:20:35 -05:00
|
|
|
return result
|
|
|
|
}
|
|
|
|
|
|
|
|
// GraphNodeEvalable
|
|
|
|
func (n *NodeApplyableOutput) EvalTree() EvalNode {
|
2017-09-26 17:58:43 -05:00
|
|
|
return &EvalSequence{
|
|
|
|
Nodes: []EvalNode{
|
|
|
|
&EvalOpFilter{
|
|
|
|
Ops: []walkOperation{walkRefresh, walkPlan, walkApply,
|
|
|
|
walkInput, walkValidate},
|
|
|
|
Node: &EvalWriteOutput{
|
2016-09-16 01:20:35 -05:00
|
|
|
Name: n.Config.Name,
|
|
|
|
Sensitive: n.Config.Sensitive,
|
|
|
|
Value: n.Config.RawConfig,
|
|
|
|
},
|
|
|
|
},
|
2017-09-26 17:58:43 -05:00
|
|
|
&EvalOpFilter{
|
|
|
|
Ops: []walkOperation{walkDestroy, walkPlanDestroy},
|
|
|
|
Node: &EvalDeleteOutput{
|
|
|
|
Name: n.Config.Name,
|
|
|
|
},
|
|
|
|
},
|
2016-09-16 01:20:35 -05:00
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|