WIP start only referring to provier by adddress

Don't try to build a full adress based on the context path for providers
in EvalContextBuiltin. Only use the name explicitly provided.
This commit is contained in:
James Bardin 2017-10-31 17:41:44 -04:00
parent f0727501c1
commit 1d54d4b10d
1 changed files with 5 additions and 18 deletions

View File

@ -92,18 +92,13 @@ func (ctx *BuiltinEvalContext) InitProvider(n string) (ResourceProvider, error)
ctx.ProviderLock.Lock()
defer ctx.ProviderLock.Unlock()
providerPath := make([]string, len(ctx.Path())+1)
copy(providerPath, ctx.Path())
providerPath[len(providerPath)-1] = n
key := PathCacheKey(providerPath)
typeName := strings.SplitN(n, ".", 2)[0]
p, err := ctx.Components.ResourceProvider(typeName, key)
p, err := ctx.Components.ResourceProvider(typeName, n)
if err != nil {
return nil, err
}
ctx.ProviderCache[key] = p
ctx.ProviderCache[n] = p
return p, nil
}
@ -113,11 +108,7 @@ func (ctx *BuiltinEvalContext) Provider(n string) ResourceProvider {
ctx.ProviderLock.Lock()
defer ctx.ProviderLock.Unlock()
providerPath := make([]string, len(ctx.Path())+1)
copy(providerPath, ctx.Path())
providerPath[len(providerPath)-1] = n
return ctx.ProviderCache[PathCacheKey(providerPath)]
return ctx.ProviderCache[n]
}
func (ctx *BuiltinEvalContext) CloseProvider(n string) error {
@ -126,15 +117,11 @@ func (ctx *BuiltinEvalContext) CloseProvider(n string) error {
ctx.ProviderLock.Lock()
defer ctx.ProviderLock.Unlock()
providerPath := make([]string, len(ctx.Path())+1)
copy(providerPath, ctx.Path())
providerPath[len(providerPath)-1] = n
var provider interface{}
provider = ctx.ProviderCache[PathCacheKey(providerPath)]
provider = ctx.ProviderCache[n]
if provider != nil {
if p, ok := provider.(ResourceProviderCloser); ok {
delete(ctx.ProviderCache, PathCacheKey(providerPath))
delete(ctx.ProviderCache, n)
return p.Close()
}
}