terraform: eval for variables

This commit is contained in:
Mitchell Hashimoto 2015-05-01 14:10:41 -07:00
parent e544e1d401
commit 9a54dddc85
2 changed files with 35 additions and 1 deletions

View File

@ -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
}

View File

@ -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,
},
},
}
}