diff --git a/.changes/v1.13/BUG FIXES-20250526-222007.yaml b/.changes/v1.13/BUG FIXES-20250526-222007.yaml new file mode 100644 index 000000000000..2e63d9964552 --- /dev/null +++ b/.changes/v1.13/BUG FIXES-20250526-222007.yaml @@ -0,0 +1,5 @@ +kind: BUG FIXES +body: Add required providers aliases in graph to allow validation on standalone modules using aliases +time: 2025-05-26T22:20:07.711709913+02:00 +custom: + Issue: "28490" diff --git a/internal/terraform/transform_provider.go b/internal/terraform/transform_provider.go index a34b51ca6fd7..516119a692ca 100644 --- a/internal/terraform/transform_provider.go +++ b/internal/terraform/transform_provider.go @@ -564,35 +564,38 @@ func (t *ProviderConfigTransformer) transformSingle(g *Graph, c *configs.Config) // access when passing around configuration and inheritance. if path.IsRoot() && c.Module.ProviderRequirements != nil { for name, p := range c.Module.ProviderRequirements.RequiredProviders { - if _, configured := mod.ProviderConfigs[name]; configured { - continue - } + for _, alias := range p.Aliases { + if _, configured := mod.ProviderConfigs[name]; configured { + continue + } - addr := addrs.AbsProviderConfig{ - Provider: p.Type, - Module: path, - } + addr := addrs.AbsProviderConfig{ + Provider: p.Type, + Module: path, + Alias: alias.Alias, + } - if _, ok := t.providers[addr.String()]; ok { - // The config validation warns about this too, but we can't - // completely prevent it in v1. - log.Printf("[WARN] ProviderConfigTransformer: duplicate required_providers entry for %s", addr) - continue - } + if _, ok := t.providers[addr.String()]; ok { + // The config validation warns about this too, but we can't + // completely prevent it in v1. + log.Printf("[WARN] ProviderConfigTransformer: duplicate required_providers entry for %s", addr) + continue + } - abstract := &NodeAbstractProvider{ - Addr: addr, - } + abstract := &NodeAbstractProvider{ + Addr: addr, + } - var v dag.Vertex - if t.Concrete != nil { - v = t.Concrete(abstract) - } else { - v = abstract - } + var v dag.Vertex + if t.Concrete != nil { + v = t.Concrete(abstract) + } else { + v = abstract + } - g.Add(v) - t.providers[addr.String()] = v.(GraphNodeProvider) + g.Add(v) + t.providers[addr.String()] = v.(GraphNodeProvider) + } } }