Merge pull request #5772 from hashicorp/phinze/var-concurrent-map-race

terraform: share graph walker's variables lock w/ interpolater
This commit is contained in:
Paul Hinze 2016-03-21 18:29:25 -05:00
commit 7efc8b25a5
2 changed files with 14 additions and 10 deletions

View File

@ -81,11 +81,12 @@ func (w *ContextGraphWalker) EnterPath(path []string) EvalContext {
StateValue: w.Context.state, StateValue: w.Context.state,
StateLock: &w.Context.stateLock, StateLock: &w.Context.stateLock,
Interpolater: &Interpolater{ Interpolater: &Interpolater{
Operation: w.Operation, Operation: w.Operation,
Module: w.Context.module, Module: w.Context.module,
State: w.Context.state, State: w.Context.state,
StateLock: &w.Context.stateLock, StateLock: &w.Context.stateLock,
Variables: variables, Variables: variables,
VariablesLock: &w.interpolaterVarLock,
}, },
InterpolaterVars: w.interpolaterVars, InterpolaterVars: w.interpolaterVars,
InterpolaterVarLock: &w.interpolaterVarLock, InterpolaterVarLock: &w.interpolaterVarLock,

View File

@ -23,11 +23,12 @@ const (
// Interpolater is the structure responsible for determining the values // Interpolater is the structure responsible for determining the values
// for interpolations such as `aws_instance.foo.bar`. // for interpolations such as `aws_instance.foo.bar`.
type Interpolater struct { type Interpolater struct {
Operation walkOperation Operation walkOperation
Module *module.Tree Module *module.Tree
State *State State *State
StateLock *sync.RWMutex StateLock *sync.RWMutex
Variables map[string]string Variables map[string]string
VariablesLock *sync.Mutex
} }
// InterpolationScope is the current scope of execution. This is required // InterpolationScope is the current scope of execution. This is required
@ -273,6 +274,8 @@ func (i *Interpolater) valueUserVar(
n string, n string,
v *config.UserVariable, v *config.UserVariable,
result map[string]ast.Variable) error { result map[string]ast.Variable) error {
i.VariablesLock.Lock()
defer i.VariablesLock.Unlock()
val, ok := i.Variables[v.Name] val, ok := i.Variables[v.Name]
if ok { if ok {
result[n] = ast.Variable{ result[n] = ast.Variable{