terraform: replace addrs.NewLegacyProvider with lookups when the

configs.Module is accessible.

Continuing the work of removing all calls to addrs.NewLegacyProvider,
this commit uses configs.Module.ProviderForLocalConfig wherever the
caller has access to that Module.
This commit is contained in:
Kristin Laemmert 2020-02-14 10:19:24 -05:00 committed by Martin Atkins
parent 228d881722
commit ac56d12c5c
4 changed files with 8 additions and 38 deletions

View File

@ -96,12 +96,7 @@ func (c *Context) Input(mode InputMode) tfdiags.Diagnostics {
UIInput: c.uiInput, UIInput: c.uiInput,
} }
var providerFqn addrs.Provider providerFqn := c.config.Module.ProviderForLocalConfig(pa)
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

View File

@ -212,12 +212,7 @@ func (d *evaluationStateData) staticValidateResourceReference(modCfg *configs.Co
return diags return diags
} }
var providerFqn addrs.Provider providerFqn := modCfg.Module.ProviderForLocalConfig(cfg.ProviderConfigAddr())
if existing, exists := modCfg.Module.ProviderRequirements[cfg.ProviderConfigAddr().LocalName]; exists {
providerFqn = existing.Type
} else {
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 {

View File

@ -82,13 +82,7 @@ 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 {
var fqn addrs.Provider fqn := module.ProviderForLocalConfig(pCfg.Addr())
if existing, exists := module.ProviderRequirements[pCfg.Name]; exists {
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 {
discoConstraints = discovery.NewConstraints(pCfg.Version.Required) discoConstraints = discovery.NewConstraints(pCfg.Version.Required)
@ -112,15 +106,7 @@ 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()
//look up the provider localname in the provider requirements map and see if fqn := module.ProviderForLocalConfig(addr)
//there is a non-default FQN associated
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
@ -138,14 +124,7 @@ func configTreeConfigDependencies(root *configs.Config, inheritProviders map[str
} }
for _, rc := range module.DataResources { for _, rc := range module.DataResources {
addr := rc.ProviderConfigAddr() addr := rc.ProviderConfigAddr()
//look up the provider localname in the provider requirements map and see if fqn := module.ProviderForLocalConfig(addr)
//there is a non-default FQN associated
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

View File

@ -673,14 +673,15 @@ func (t *ProviderConfigTransformer) addProxyProviders(g *Graph, c *configs.Confi
// legacy-style providers, and will instead need to lookup fqns from the // legacy-style providers, and will instead need to lookup fqns from the
// config when that information is available. // config when that information is available.
//fullAddr := pair.InChild.Addr().Absolute(instPath) //fullAddr := pair.InChild.Addr().Absolute(instPath)
fqn := c.Module.ProviderForLocalConfig(pair.InChild.Addr())
fullAddr := addrs.AbsProviderConfig{ fullAddr := addrs.AbsProviderConfig{
Provider: addrs.NewLegacyProvider(pair.InChild.Addr().LocalName), Provider: fqn,
Module: instPath, Module: instPath,
Alias: pair.InChild.Addr().Alias, Alias: pair.InChild.Addr().Alias,
} }
fullParentAddr := addrs.AbsProviderConfig{ fullParentAddr := addrs.AbsProviderConfig{
Provider: addrs.NewLegacyProvider(pair.InParent.Addr().LocalName), Provider: fqn,
Module: parentInstPath, Module: parentInstPath,
Alias: pair.InParent.Addr().Alias, Alias: pair.InParent.Addr().Alias,
} }