terraform: ProviderTransform gets provider fqn from module

Added configs.Module.ProviderForLocalProviderConfig which allows
terraform.ProviderTransformer to get the provider FQN from the module,
instead of assuming NewLegacyProvider.
This commit is contained in:
Kristin Laemmert 2020-02-14 09:35:23 -05:00 committed by Martin Atkins
parent c02a898994
commit 6e2618d9be
2 changed files with 9 additions and 6 deletions

View File

@ -457,3 +457,11 @@ func (m *Module) LocalNameForProvider(p addrs.Provider) string {
return p.Type
}
}
// ProviderForLocalConfig returns the provider FQN for a given LocalProviderConfig
func (m *Module) ProviderForLocalConfig(pc addrs.LocalProviderConfig) addrs.Provider {
if provider, exists := m.ProviderRequirements[pc.String()]; exists {
return provider.Type
}
return addrs.NewLegacyProvider(pc.LocalName)
}

View File

@ -587,12 +587,7 @@ func (t *ProviderConfigTransformer) transformSingle(g *Graph, c *configs.Config)
// add all providers from the configuration
for _, p := range mod.ProviderConfigs {
relAddr := p.Addr()
// FIXME: This relies on the assumption that all providers are
// LegacyProviders, and will instead need to lookup the FQN in the
// config from the provider local name when that is supported.
fqn := addrs.NewLegacyProvider(relAddr.LocalName)
fqn := mod.ProviderForLocalConfig(p.Addr())
addr := addrs.AbsProviderConfig{
Provider: fqn,
Alias: p.Alias,