terraform: look up provider fqns from
configs.Module.ProviderRequirements This is close to a no-op - we aren't accepting the provider source attribute yet, so the only entires in the ProviderRequirements will already be legacy provider addrs. This PR also removes the unused `uid` field from ResourceProvider and ResourceProvisioner. It's unused now and even less likely to be useful now that we have a specific addrs.Provider type.
This commit is contained in:
parent
6494591ec1
commit
c242f9389d
|
@ -13,16 +13,13 @@ import (
|
||||||
// This factory gets more information than the raw maps using to initialize
|
// This factory gets more information than the raw maps using to initialize
|
||||||
// a Context. This information is used for debugging.
|
// a Context. This information is used for debugging.
|
||||||
type contextComponentFactory interface {
|
type contextComponentFactory interface {
|
||||||
// ResourceProvider creates a new ResourceProvider with the given
|
// ResourceProvider creates a new ResourceProvider with the given type.
|
||||||
// type. The "uid" is a unique identifier for this provider being
|
ResourceProvider(typ string) (providers.Interface, error)
|
||||||
// initialized that can be used for internal tracking.
|
|
||||||
ResourceProvider(typ, uid string) (providers.Interface, error)
|
|
||||||
ResourceProviders() []string
|
ResourceProviders() []string
|
||||||
|
|
||||||
// ResourceProvisioner creates a new ResourceProvisioner with the
|
// ResourceProvisioner creates a new ResourceProvisioner with the given
|
||||||
// given type. The "uid" is a unique identifier for this provisioner
|
// type.
|
||||||
// being initialized that can be used for internal tracking.
|
ResourceProvisioner(typ string) (provisioners.Interface, error)
|
||||||
ResourceProvisioner(typ, uid string) (provisioners.Interface, error)
|
|
||||||
ResourceProvisioners() []string
|
ResourceProvisioners() []string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,7 +46,7 @@ func (c *basicComponentFactory) ResourceProvisioners() []string {
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *basicComponentFactory) ResourceProvider(typ, uid string) (providers.Interface, error) {
|
func (c *basicComponentFactory) ResourceProvider(typ string) (providers.Interface, error) {
|
||||||
f, ok := c.providers[addrs.NewLegacyProvider(typ)]
|
f, ok := c.providers[addrs.NewLegacyProvider(typ)]
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("unknown provider %q", typ)
|
return nil, fmt.Errorf("unknown provider %q", typ)
|
||||||
|
@ -58,7 +55,7 @@ func (c *basicComponentFactory) ResourceProvider(typ, uid string) (providers.Int
|
||||||
return f()
|
return f()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *basicComponentFactory) ResourceProvisioner(typ, uid string) (provisioners.Interface, error) {
|
func (c *basicComponentFactory) ResourceProvisioner(typ string) (provisioners.Interface, error) {
|
||||||
f, ok := c.provisioners[typ]
|
f, ok := c.provisioners[typ]
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("unknown provisioner %q", typ)
|
return nil, fmt.Errorf("unknown provisioner %q", typ)
|
||||||
|
|
|
@ -96,8 +96,12 @@ func (c *Context) Input(mode InputMode) tfdiags.Diagnostics {
|
||||||
UIInput: c.uiInput,
|
UIInput: c.uiInput,
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: get provider FQN
|
var providerFqn addrs.Provider
|
||||||
providerFqn := addrs.NewLegacyProvider(pa.LocalName)
|
if existing, exists := c.config.Module.ProviderRequirements[pa.LocalName]; exists {
|
||||||
|
providerFqn = existing.Type
|
||||||
|
} else {
|
||||||
|
providerFqn = addrs.NewLegacyProvider(pa.LocalName)
|
||||||
|
}
|
||||||
schema := c.schemas.ProviderConfig(providerFqn)
|
schema := c.schemas.ProviderConfig(providerFqn)
|
||||||
if schema == nil {
|
if schema == nil {
|
||||||
// Could either be an incorrect config or just an incomplete
|
// Could either be an incorrect config or just an incomplete
|
||||||
|
|
|
@ -124,7 +124,7 @@ func (ctx *BuiltinEvalContext) InitProvider(typeName string, addr addrs.AbsProvi
|
||||||
|
|
||||||
key := absAddr.String()
|
key := absAddr.String()
|
||||||
|
|
||||||
p, err := ctx.Components.ResourceProvider(typeName, key)
|
p, err := ctx.Components.ResourceProvider(typeName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -254,7 +254,7 @@ func (ctx *BuiltinEvalContext) InitProvisioner(n string) (provisioners.Interface
|
||||||
ctx.ProvisionerLock.Lock()
|
ctx.ProvisionerLock.Lock()
|
||||||
defer ctx.ProvisionerLock.Unlock()
|
defer ctx.ProvisionerLock.Unlock()
|
||||||
|
|
||||||
p, err := ctx.Components.ResourceProvisioner(n, "")
|
p, err := ctx.Components.ResourceProvisioner(n)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -212,12 +212,12 @@ func (d *evaluationStateData) staticValidateResourceReference(modCfg *configs.Co
|
||||||
return diags
|
return diags
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: This is wrong: it's assuming that the local type is the same
|
var providerFqn addrs.Provider
|
||||||
// as the type from the provider FQN, which will not hold once we eliminate
|
if existing, exists := modCfg.Module.ProviderRequirements[cfg.ProviderConfigAddr().LocalName]; exists {
|
||||||
// legacy addresses. d.Evaluator.Schemas.ResourceTypeConfig below ought to
|
providerFqn = existing.Type
|
||||||
// change to take an addrs.Provider, and then that's what we should be
|
} else {
|
||||||
// passing in here.
|
providerFqn = addrs.NewLegacyProvider(cfg.ProviderConfigAddr().LocalName)
|
||||||
providerFqn := addrs.NewLegacyProvider(cfg.ProviderConfigAddr().LocalName)
|
}
|
||||||
schema, _ := d.Evaluator.Schemas.ResourceTypeConfig(providerFqn, addr.Mode, addr.Type)
|
schema, _ := d.Evaluator.Schemas.ResourceTypeConfig(providerFqn, addr.Mode, addr.Type)
|
||||||
|
|
||||||
if schema == nil {
|
if schema == nil {
|
||||||
|
|
|
@ -82,9 +82,12 @@ func configTreeConfigDependencies(root *configs.Config, inheritProviders map[str
|
||||||
// allowing for more terse declaration in situations where both a
|
// allowing for more terse declaration in situations where both a
|
||||||
// configuration and a constraint are defined in the same module.
|
// configuration and a constraint are defined in the same module.
|
||||||
for _, pCfg := range module.ProviderConfigs {
|
for _, pCfg := range module.ProviderConfigs {
|
||||||
//FIXME: lookup the provider localname in the TBD map and see if
|
var fqn addrs.Provider
|
||||||
//there is an FQN associated
|
if existing, exists := module.ProviderRequirements[pCfg.Name]; exists {
|
||||||
fqn := addrs.NewLegacyProvider(pCfg.Name)
|
fqn = existing.Type
|
||||||
|
} else {
|
||||||
|
fqn = addrs.NewLegacyProvider(pCfg.Name)
|
||||||
|
}
|
||||||
|
|
||||||
discoConstraints := discovery.AllVersions
|
discoConstraints := discovery.AllVersions
|
||||||
if pCfg.Version.Required != nil {
|
if pCfg.Version.Required != nil {
|
||||||
|
@ -105,9 +108,15 @@ func configTreeConfigDependencies(root *configs.Config, inheritProviders map[str
|
||||||
// an explicit dependency on the same provider.
|
// an explicit dependency on the same provider.
|
||||||
for _, rc := range module.ManagedResources {
|
for _, rc := range module.ManagedResources {
|
||||||
addr := rc.ProviderConfigAddr()
|
addr := rc.ProviderConfigAddr()
|
||||||
//FIXME: lookup the provider localname in the TBD map and see if
|
//look up the provider localname in the provider requirements map and see if
|
||||||
//there is an FQN associated
|
//there is a non-default FQN associated
|
||||||
fqn := addrs.NewLegacyProvider(addr.LocalName)
|
var fqn addrs.Provider
|
||||||
|
if existing, exists := module.ProviderRequirements[addr.LocalName]; exists {
|
||||||
|
fqn = existing.Type
|
||||||
|
} else {
|
||||||
|
fqn = addrs.NewLegacyProvider(addr.LocalName)
|
||||||
|
}
|
||||||
|
|
||||||
if _, exists := providers[fqn]; exists {
|
if _, exists := providers[fqn]; exists {
|
||||||
// Explicit dependency already present
|
// Explicit dependency already present
|
||||||
continue
|
continue
|
||||||
|
@ -125,9 +134,14 @@ func configTreeConfigDependencies(root *configs.Config, inheritProviders map[str
|
||||||
}
|
}
|
||||||
for _, rc := range module.DataResources {
|
for _, rc := range module.DataResources {
|
||||||
addr := rc.ProviderConfigAddr()
|
addr := rc.ProviderConfigAddr()
|
||||||
//FIXME: lookup the provider localname in the TBD map and see if
|
//look up the provider localname in the provider requirements map and see if
|
||||||
//there is an FQN associated
|
//there is a non-default FQN associated
|
||||||
fqn := addrs.NewLegacyProvider(addr.LocalName)
|
var fqn addrs.Provider
|
||||||
|
if existing, exists := module.ProviderRequirements[addr.LocalName]; exists {
|
||||||
|
fqn = existing.Type
|
||||||
|
} else {
|
||||||
|
fqn = addrs.NewLegacyProvider(addr.LocalName)
|
||||||
|
}
|
||||||
if _, exists := providers[fqn]; exists {
|
if _, exists := providers[fqn]; exists {
|
||||||
// Explicit dependency already present
|
// Explicit dependency already present
|
||||||
continue
|
continue
|
||||||
|
|
|
@ -101,7 +101,7 @@ func loadProviderSchemas(schemas map[addrs.Provider]*ProviderSchema, config *con
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Printf("[TRACE] LoadSchemas: retrieving schema for provider type %q", typeName)
|
log.Printf("[TRACE] LoadSchemas: retrieving schema for provider type %q", typeName)
|
||||||
provider, err := components.ResourceProvider(typeName, "early/"+typeName)
|
provider, err := components.ResourceProvider(typeName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// We'll put a stub in the map so we won't re-attempt this on
|
// We'll put a stub in the map so we won't re-attempt this on
|
||||||
// future calls.
|
// future calls.
|
||||||
|
@ -191,7 +191,7 @@ func loadProvisionerSchemas(schemas map[string]*configschema.Block, config *conf
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Printf("[TRACE] LoadSchemas: retrieving schema for provisioner %q", name)
|
log.Printf("[TRACE] LoadSchemas: retrieving schema for provisioner %q", name)
|
||||||
provisioner, err := components.ResourceProvisioner(name, "early/"+name)
|
provisioner, err := components.ResourceProvisioner(name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// We'll put a stub in the map so we won't re-attempt this on
|
// We'll put a stub in the map so we won't re-attempt this on
|
||||||
// future calls.
|
// future calls.
|
||||||
|
|
Loading…
Reference in New Issue