mirror of
https://github.com/opentffoundation/opentf.git
synced 2025-12-25 01:00:16 -05:00
lang/eval: Deciding a provider instance for each resource instance
This introduces the machinery for representing provider configs, provider instances, and the relationships between resource instances and provider instances. Unfortunately there's a lot of accumulated complexity in the rules for how OpenTofu currently decides which provider configs are available for use in a module, including lots of implicit behavior for backward-compatibility, so right now that is stubbed out with just a hard-coded implementation that puts a "test/foo" provider with local name "foo" in every module instance. We'll deal with a real implementation of all that in later commits. Signed-off-by: Martin Atkins <mart@degeneration.co.uk>
This commit is contained in:
@@ -5,6 +5,11 @@
|
||||
|
||||
package addrs
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// This file contains some provider address types that are arguably more
|
||||
// "correct" than the ones used in most of the system due to following the
|
||||
// same naming conventions used elsewhere in package addrs.
|
||||
@@ -33,6 +38,20 @@ func (pc AbsProviderConfigCorrect) Instance(key InstanceKey) AbsProviderInstance
|
||||
}
|
||||
}
|
||||
|
||||
func (pc AbsProviderConfigCorrect) String() string {
|
||||
var buf strings.Builder
|
||||
if !pc.Module.IsRoot() {
|
||||
buf.WriteString(pc.Module.String())
|
||||
buf.WriteByte('.')
|
||||
}
|
||||
fmt.Fprintf(&buf, "provider[%q]", pc.Provider)
|
||||
if pc.Alias != "" {
|
||||
buf.WriteByte('.')
|
||||
buf.WriteString(pc.Alias)
|
||||
}
|
||||
return buf.String()
|
||||
}
|
||||
|
||||
// AbsProviderInstanceCorrect is an experimental "correct" representation of
|
||||
// the absolute address of an instance of an [AbsProviderConfigCorrect].
|
||||
//
|
||||
@@ -43,6 +62,25 @@ type AbsProviderInstanceCorrect struct {
|
||||
Key InstanceKey
|
||||
}
|
||||
|
||||
var _ UniqueKeyer = AbsProviderInstanceCorrect{}
|
||||
|
||||
func (a AbsProviderInstanceCorrect) String() string {
|
||||
if a.Key == nil {
|
||||
return a.Config.String()
|
||||
}
|
||||
return a.Config.String() + a.Key.String()
|
||||
}
|
||||
|
||||
// UniqueKey implements UniqueKeyer.
|
||||
func (a AbsProviderInstanceCorrect) UniqueKey() UniqueKey {
|
||||
return absProviderInstanceCorrectKey(a.String())
|
||||
}
|
||||
|
||||
type absProviderInstanceCorrectKey string
|
||||
|
||||
// uniqueKeySigil implements UniqueKey.
|
||||
func (a absProviderInstanceCorrectKey) uniqueKeySigil() {}
|
||||
|
||||
// The [LocalProviderConfig] type is still reasonable to use to represent
|
||||
// the special expression syntax we use for referring to provider configs
|
||||
// in locations like the "provider" meta-argument in a resource configuration.
|
||||
|
||||
Reference in New Issue
Block a user