mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-25 18:45:20 -06:00
This turned out to be a big messy commit, since the way providers are referenced is tightly coupled throughout the code. That starts to unify how providers are referenced, using the format output node Name method. Add a new field to the internal resource data types called ResolvedProvider. This is set by a new setter method SetProvider when a resource is connected to a provider during graph creation. This allows us to later lookup the provider instance a resource is connected to, without requiring it to have the same module path. The InitProvider context method now takes 2 arguments, one if the provider type and the second is the full name of the provider. While the provider type could still be parsed from the full name, this makes it more explicit and, and changes to the name format won't effect this code.
90 lines
2.1 KiB
Go
90 lines
2.1 KiB
Go
package terraform
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/hashicorp/terraform/config"
|
|
"github.com/hashicorp/terraform/dag"
|
|
)
|
|
|
|
// ConcreteProviderNodeFunc is a callback type used to convert an
|
|
// abstract provider to a concrete one of some type.
|
|
type ConcreteProviderNodeFunc func(*NodeAbstractProvider) dag.Vertex
|
|
|
|
// NodeAbstractProvider represents a provider that has no associated operations.
|
|
// It registers all the common interfaces across operations for providers.
|
|
type NodeAbstractProvider struct {
|
|
NameValue string
|
|
PathValue []string
|
|
|
|
// The fields below will be automatically set using the Attach
|
|
// interfaces if you're running those transforms, but also be explicitly
|
|
// set if you already have that information.
|
|
|
|
Config *config.ProviderConfig
|
|
}
|
|
|
|
func ResolveProviderName(name string, path []string) string {
|
|
name = fmt.Sprintf("provider.%s", name)
|
|
if len(path) > 1 {
|
|
name = fmt.Sprintf("%s.%s", modulePrefixStr(path), name)
|
|
}
|
|
|
|
return name
|
|
}
|
|
|
|
func (n *NodeAbstractProvider) Name() string {
|
|
return ResolveProviderName(n.NameValue, n.PathValue)
|
|
}
|
|
|
|
// GraphNodeSubPath
|
|
func (n *NodeAbstractProvider) Path() []string {
|
|
return n.PathValue
|
|
}
|
|
|
|
// RemovableIfNotTargeted
|
|
func (n *NodeAbstractProvider) RemoveIfNotTargeted() bool {
|
|
// We need to add this so that this node will be removed if
|
|
// it isn't targeted or a dependency of a target.
|
|
return true
|
|
}
|
|
|
|
// GraphNodeReferencer
|
|
func (n *NodeAbstractProvider) References() []string {
|
|
if n.Config == nil {
|
|
return nil
|
|
}
|
|
|
|
return ReferencesFromConfig(n.Config.RawConfig)
|
|
}
|
|
|
|
// GraphNodeProvider
|
|
func (n *NodeAbstractProvider) ProviderName() string {
|
|
return n.NameValue
|
|
}
|
|
|
|
// GraphNodeProvider
|
|
func (n *NodeAbstractProvider) ProviderConfig() *config.ProviderConfig {
|
|
if n.Config == nil {
|
|
return nil
|
|
}
|
|
|
|
return n.Config
|
|
}
|
|
|
|
// GraphNodeAttachProvider
|
|
func (n *NodeAbstractProvider) AttachProvider(c *config.ProviderConfig) {
|
|
n.Config = c
|
|
}
|
|
|
|
// GraphNodeDotter impl.
|
|
func (n *NodeAbstractProvider) DotNode(name string, opts *dag.DotOpts) *dag.DotNode {
|
|
return &dag.DotNode{
|
|
Name: name,
|
|
Attrs: map[string]string{
|
|
"label": n.Name(),
|
|
"shape": "diamond",
|
|
},
|
|
}
|
|
}
|