terraform: eval for variables
This commit is contained in:
parent
e544e1d401
commit
9a54dddc85
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue