core: Context.InitProvider must cache providers using absolute addresses

Previously InitProvider was incorrectly using only the relative address,
which (due to the ambiguity in the string representation of absolute vs.
relative addresses) caused it to always initialize providers in the root
module.

Now we use the absolute address as the key, which then agrees with the
Provider method and ensures that each module gets its own separate
instance of each provider if explicit configuration is present.
This commit is contained in:
Martin Atkins 2018-05-11 16:53:52 -07:00
parent b8c3b8d45d
commit 0c4c7c5a5f
1 changed files with 2 additions and 1 deletions

View File

@ -105,13 +105,14 @@ func (ctx *BuiltinEvalContext) InitProvider(typeName string, addr addrs.Provider
ctx.ProviderLock.Lock()
defer ctx.ProviderLock.Unlock()
key := addr.String()
key := absAddr.String()
p, err := ctx.Components.ResourceProvider(typeName, key)
if err != nil {
return nil, err
}
log.Printf("[TRACE] BuiltinEvalContext: Initialized %q provider for %s", typeName, absAddr)
ctx.ProviderCache[key] = p
// Also fetch and cache the provider's schema.