6 "github.com/hashicorp/terraform/config"
9 // EvalLocal is an EvalNode implementation that evaluates the
10 // expression for a local value and writes it into a transient part of
12 type EvalLocal struct {
14 Value *config.RawConfig
17 func (n *EvalLocal) Eval(ctx EvalContext) (interface{}, error) {
18 cfg, err := ctx.Interpolate(n.Value, nil)
20 return nil, fmt.Errorf("local.%s: %s", n.Name, err)
23 state, lock := ctx.State()
25 return nil, fmt.Errorf("cannot write local value to nil state")
28 // Get a write lock so we can access the state
32 // Look for the module state. If we don't have one, create it.
33 mod := state.ModuleByPath(ctx.Path())
35 mod = state.AddModule(ctx.Path())
38 // Get the value from the config
39 var valueRaw interface{} = config.UnknownVariableValue
42 valueRaw, ok = cfg.Get("value")
46 if cfg.IsComputed("value") {
47 valueRaw = config.UnknownVariableValue
51 if mod.Locals == nil {
53 mod.Locals = map[string]interface{}{}
55 mod.Locals[n.Name] = valueRaw
60 // EvalDeleteLocal is an EvalNode implementation that deletes a Local value
61 // from the state. Locals aren't persisted, but we don't need to evaluate them
63 type EvalDeleteLocal struct {
67 func (n *EvalDeleteLocal) Eval(ctx EvalContext) (interface{}, error) {
68 state, lock := ctx.State()
73 // Get a write lock so we can access this instance
77 // Look for the module state. If we don't have one, create it.
78 mod := state.ModuleByPath(ctx.Path())
83 delete(mod.Locals, n.Name)