Fix inconsistent results with self interpolation

Due to a race in interpolateForce(), a reference to self could return
inconsistent results.
This commit is contained in:
James Bardin 2016-08-30 14:16:37 -04:00
parent dea2860735
commit 632c16c212
2 changed files with 18 additions and 1 deletions

View File

@ -48,6 +48,18 @@ func NewRawConfig(raw map[string]interface{}) (*RawConfig, error) {
return result, nil
}
// RawMap returns a copy of the RawConfig.Raw map.
func (r *RawConfig) RawMap() map[string]interface{} {
r.lock.Lock()
defer r.lock.Unlock()
m := make(map[string]interface{})
for k, v := range r.Raw {
m[k] = v
}
return m
}
// Copy returns a copy of this RawConfig, uninterpolated.
func (r *RawConfig) Copy() *RawConfig {
r.lock.Lock()
@ -192,6 +204,9 @@ func (r *RawConfig) Merge(other *RawConfig) *RawConfig {
}
func (r *RawConfig) init() error {
r.lock.Lock()
defer r.lock.Unlock()
r.config = r.Raw
r.Interpolations = nil
r.Variables = nil
@ -261,6 +276,8 @@ func (r *RawConfig) merge(r2 *RawConfig) *RawConfig {
// UnknownKeys returns the keys of the configuration that are unknown
// because they had interpolated variables that must be computed.
func (r *RawConfig) UnknownKeys() []string {
r.lock.Lock()
defer r.lock.Unlock()
return r.unknownKeys
}

View File

@ -239,6 +239,6 @@ func (c *ResourceConfig) interpolateForce() {
}
c.ComputedKeys = c.raw.UnknownKeys()
c.Raw = c.raw.Raw
c.Raw = c.raw.RawMap()
c.Config = c.raw.Config()
}