terraform: cache provider configuration with the provider name

/cc @sethvargo

This was causing a race with whichever provider was configured first
would "win" the configuration slot. We need to make sure to append the
unique provider name to the end of the key.

Note: this doesn't have tests. We don't test this yet. :(
This commit is contained in:
Mitchell Hashimoto 2015-02-20 15:48:06 -08:00
parent 40ee70d5c9
commit 39d2bf4629
1 changed files with 13 additions and 3 deletions

View File

@ -106,9 +106,13 @@ func (ctx *BuiltinEvalContext) ConfigureProvider(
return fmt.Errorf("Provider '%s' not initialized", n)
}
providerPath := make([]string, len(ctx.Path())+1)
copy(providerPath, ctx.Path())
providerPath[len(providerPath)-1] = n
// Save the configuration
ctx.ProviderLock.Lock()
ctx.ProviderConfigCache[PathCacheKey(ctx.Path())] = cfg
ctx.ProviderConfigCache[PathCacheKey(providerPath)] = cfg
ctx.ProviderLock.Unlock()
return p.Configure(cfg)
@ -132,9 +136,15 @@ func (ctx *BuiltinEvalContext) ParentProviderConfig(n string) *ResourceConfig {
ctx.ProviderLock.Lock()
defer ctx.ProviderLock.Unlock()
// Make a copy of the path so we can safely edit it
path := ctx.Path()
for i := len(path) - 1; i >= 1; i-- {
k := PathCacheKey(path[:i])
pathCopy := make([]string, len(path)+1)
copy(pathCopy, path)
// Go up the tree.
for i := len(path) - 1; i >= 0; i-- {
pathCopy[i+1] = n
k := PathCacheKey(pathCopy[:i+2])
if v, ok := ctx.ProviderConfigCache[k]; ok {
return v
}