7 "github.com/hashicorp/terraform/config"
10 // EvalDeleteOutput is an EvalNode implementation that deletes an output
12 type EvalDeleteOutput struct {
17 func (n *EvalDeleteOutput) Eval(ctx EvalContext) (interface{}, error) {
18 state, lock := ctx.State()
23 // Get a write lock so we can access this instance
27 // Look for the module state. If we don't have one, create it.
28 mod := state.ModuleByPath(ctx.Path())
33 delete(mod.Outputs, n.Name)
38 // EvalWriteOutput is an EvalNode implementation that writes the output
39 // for the given name to the current state.
40 type EvalWriteOutput struct {
43 Value *config.RawConfig
47 func (n *EvalWriteOutput) Eval(ctx EvalContext) (interface{}, error) {
48 cfg, err := ctx.Interpolate(n.Value, nil)
50 // Log error but continue anyway
51 log.Printf("[WARN] Output interpolation %q failed: %s", n.Name, err)
54 state, lock := ctx.State()
56 return nil, fmt.Errorf("cannot write state to nil state")
59 // Get a write lock so we can access this instance
63 // Look for the module state. If we don't have one, create it.
64 mod := state.ModuleByPath(ctx.Path())
66 mod = state.AddModule(ctx.Path())
69 // Get the value from the config
70 var valueRaw interface{} = config.UnknownVariableValue
73 valueRaw, ok = cfg.Get("value")
77 if cfg.IsComputed("value") {
78 valueRaw = config.UnknownVariableValue
82 switch valueTyped := valueRaw.(type) {
84 mod.Outputs[n.Name] = &OutputState{
86 Sensitive: n.Sensitive,
90 mod.Outputs[n.Name] = &OutputState{
92 Sensitive: n.Sensitive,
95 case map[string]interface{}:
96 mod.Outputs[n.Name] = &OutputState{
98 Sensitive: n.Sensitive,
101 case []map[string]interface{}:
102 // an HCL map is multi-valued, so if this was read out of a config the
103 // map may still be in a slice.
104 if len(valueTyped) == 1 {
105 mod.Outputs[n.Name] = &OutputState{
107 Sensitive: n.Sensitive,
108 Value: valueTyped[0],
112 return nil, fmt.Errorf("output %s type (%T) with %d values not valid for type map",
113 n.Name, valueTyped, len(valueTyped))
115 return nil, fmt.Errorf("output %s is not a valid type (%T)\n", n.Name, valueTyped)