2016-10-19 23:54:00 +02:00
|
|
|
package terraform
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/hashicorp/terraform/config"
|
2016-12-03 04:26:40 +01:00
|
|
|
"github.com/hashicorp/terraform/dag"
|
2016-10-19 23:54:00 +02:00
|
|
|
)
|
|
|
|
|
2016-12-04 00:27:38 +01:00
|
|
|
// ConcreteProviderNodeFunc is a callback type used to convert an
|
|
|
|
// abstract provider to a concrete one of some type.
|
|
|
|
type ConcreteProviderNodeFunc func(*NodeAbstractProvider) dag.Vertex
|
|
|
|
|
2016-10-19 23:54:00 +02:00
|
|
|
// 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 (n *NodeAbstractProvider) Name() string {
|
|
|
|
result := fmt.Sprintf("provider.%s", n.NameValue)
|
|
|
|
if len(n.PathValue) > 1 {
|
|
|
|
result = fmt.Sprintf("%s.%s", modulePrefixStr(n.PathValue), result)
|
|
|
|
}
|
|
|
|
|
|
|
|
return result
|
|
|
|
}
|
|
|
|
|
|
|
|
// GraphNodeSubPath
|
|
|
|
func (n *NodeAbstractProvider) Path() []string {
|
|
|
|
return n.PathValue
|
|
|
|
}
|
|
|
|
|
2017-02-17 18:21:29 +01:00
|
|
|
// 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
|
|
|
|
}
|
|
|
|
|
2016-10-19 23:54:00 +02:00
|
|
|
// 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.RawConfig {
|
|
|
|
if n.Config == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return n.Config.RawConfig
|
|
|
|
}
|
|
|
|
|
|
|
|
// GraphNodeAttachProvider
|
|
|
|
func (n *NodeAbstractProvider) AttachProvider(c *config.ProviderConfig) {
|
|
|
|
n.Config = c
|
|
|
|
}
|
2016-12-03 04:26:40 +01:00
|
|
|
|
|
|
|
// 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",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|