From 39d2bf4629ca5667e2e7194a680ad1373beda3b2 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 20 Feb 2015 15:48:06 -0800 Subject: [PATCH] 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. :( --- terraform/eval_context_builtin.go | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/terraform/eval_context_builtin.go b/terraform/eval_context_builtin.go index 461e43542..15acb01eb 100644 --- a/terraform/eval_context_builtin.go +++ b/terraform/eval_context_builtin.go @@ -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 }