diff --git a/terraform/eval_context_builtin.go b/terraform/eval_context_builtin.go index 7e1eac310a..d355e36ef1 100644 --- a/terraform/eval_context_builtin.go +++ b/terraform/eval_context_builtin.go @@ -29,7 +29,8 @@ type BuiltinEvalContext struct { StateValue *State StateLock *sync.RWMutex - once sync.Once + once sync.Once + varLock sync.Mutex } func (ctx *BuiltinEvalContext) Hook(fn func(Hook) (HookAction, error)) error { @@ -238,6 +239,9 @@ func (ctx *BuiltinEvalContext) Path() []string { } func (ctx *BuiltinEvalContext) SetVariables(vs map[string]string) { + ctx.varLock.Lock() + defer ctx.varLock.Unlock() + for k, v := range vs { ctx.Interpolater.Variables[k] = v } diff --git a/terraform/graph_config_node_variable.go b/terraform/graph_config_node_variable.go index 964b7b0067..46aeff4a35 100644 --- a/terraform/graph_config_node_variable.go +++ b/terraform/graph_config_node_variable.go @@ -66,3 +66,33 @@ func (n *GraphNodeConfigVariable) SetVariableValue(v *config.RawConfig) { func (n *GraphNodeConfigVariable) Proxy() bool { return true } + +// 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]string) + return &EvalSequence{ + Nodes: []EvalNode{ + &EvalInterpolate{ + Config: n.Value, + Output: &config, + }, + + &EvalVariableBlock{ + Config: &config, + Variables: variables, + }, + + &EvalSetVariables{ + Variables: variables, + }, + }, + } +}