opentofu/internal/terraform/node_provider_abstract.go
Martin Atkins 36d0a50427 Move terraform/ to internal/terraform/
This is part of a general effort to move all of Terraform's non-library
package surface under internal in order to reinforce that these are for
internal use within Terraform only.

If you were previously importing packages under this prefix into an
external codebase, you could pin to an earlier release tag as an interim
solution until you've make a plan to achieve the same functionality some
other way.
2021-05-17 14:09:07 -07:00

96 lines
2.7 KiB
Go

package terraform
import (
"github.com/hashicorp/terraform/internal/addrs"
"github.com/hashicorp/terraform/internal/configs"
"github.com/hashicorp/terraform/internal/configs/configschema"
"github.com/hashicorp/terraform/internal/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 {
Addr addrs.AbsProviderConfig
// 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 *configs.Provider
Schema *configschema.Block
}
var (
_ GraphNodeModulePath = (*NodeAbstractProvider)(nil)
_ GraphNodeReferencer = (*NodeAbstractProvider)(nil)
_ GraphNodeProvider = (*NodeAbstractProvider)(nil)
_ GraphNodeAttachProvider = (*NodeAbstractProvider)(nil)
_ GraphNodeAttachProviderConfigSchema = (*NodeAbstractProvider)(nil)
_ dag.GraphNodeDotter = (*NodeAbstractProvider)(nil)
)
func (n *NodeAbstractProvider) Name() string {
return n.Addr.String()
}
// GraphNodeModuleInstance
func (n *NodeAbstractProvider) Path() addrs.ModuleInstance {
// Providers cannot be contained inside an expanded module, so this shim
// converts our module path to the correct ModuleInstance.
return n.Addr.Module.UnkeyedInstanceShim()
}
// GraphNodeModulePath
func (n *NodeAbstractProvider) ModulePath() addrs.Module {
return n.Addr.Module
}
// GraphNodeReferencer
func (n *NodeAbstractProvider) References() []*addrs.Reference {
if n.Config == nil || n.Schema == nil {
return nil
}
return ReferencesFromConfig(n.Config.Config, n.Schema)
}
// GraphNodeProvider
func (n *NodeAbstractProvider) ProviderAddr() addrs.AbsProviderConfig {
return n.Addr
}
// GraphNodeProvider
func (n *NodeAbstractProvider) ProviderConfig() *configs.Provider {
if n.Config == nil {
return nil
}
return n.Config
}
// GraphNodeAttachProvider
func (n *NodeAbstractProvider) AttachProvider(c *configs.Provider) {
n.Config = c
}
// GraphNodeAttachProviderConfigSchema impl.
func (n *NodeAbstractProvider) AttachProviderConfigSchema(schema *configschema.Block) {
n.Schema = schema
}
// 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",
},
}
}