2015-01-28 06:48:46 +01:00
|
|
|
package terraform
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2016-04-19 01:19:43 +02:00
|
|
|
"log"
|
2015-06-25 05:58:52 +02:00
|
|
|
"strings"
|
2015-01-28 06:48:46 +01:00
|
|
|
|
|
|
|
"github.com/hashicorp/go-multierror"
|
2015-04-09 17:48:08 +02:00
|
|
|
"github.com/hashicorp/terraform/config"
|
2015-01-28 06:48:46 +01:00
|
|
|
"github.com/hashicorp/terraform/dag"
|
2015-04-23 20:24:26 +02:00
|
|
|
"github.com/hashicorp/terraform/dot"
|
2015-01-28 06:48:46 +01:00
|
|
|
)
|
|
|
|
|
2015-01-28 07:14:01 +01:00
|
|
|
// GraphNodeProvider is an interface that nodes that can be a provider
|
|
|
|
// must implement. The ProviderName returned is the name of the provider
|
|
|
|
// they satisfy.
|
|
|
|
type GraphNodeProvider interface {
|
|
|
|
ProviderName() string
|
2015-04-09 17:48:08 +02:00
|
|
|
ProviderConfig() *config.RawConfig
|
2015-01-28 07:14:01 +01:00
|
|
|
}
|
|
|
|
|
2015-06-19 21:52:50 +02:00
|
|
|
// GraphNodeCloseProvider is an interface that nodes that can be a close
|
|
|
|
// provider must implement. The CloseProviderName returned is the name of
|
|
|
|
// the provider they satisfy.
|
|
|
|
type GraphNodeCloseProvider interface {
|
|
|
|
CloseProviderName() string
|
|
|
|
}
|
|
|
|
|
2015-01-28 07:14:01 +01:00
|
|
|
// GraphNodeProviderConsumer is an interface that nodes that require
|
|
|
|
// a provider must implement. ProvidedBy must return the name of the provider
|
|
|
|
// to use.
|
|
|
|
type GraphNodeProviderConsumer interface {
|
2015-02-10 08:32:28 +01:00
|
|
|
ProvidedBy() []string
|
2015-01-28 07:14:01 +01:00
|
|
|
}
|
|
|
|
|
2015-04-09 06:14:19 +02:00
|
|
|
// DisableProviderTransformer "disables" any providers that are only
|
|
|
|
// depended on by modules.
|
|
|
|
type DisableProviderTransformer struct{}
|
|
|
|
|
|
|
|
func (t *DisableProviderTransformer) Transform(g *Graph) error {
|
|
|
|
for _, v := range g.Vertices() {
|
|
|
|
// We only care about providers
|
2015-04-09 17:48:08 +02:00
|
|
|
pn, ok := v.(GraphNodeProvider)
|
2015-05-02 00:18:40 +02:00
|
|
|
if !ok || pn.ProviderName() == "" {
|
2015-04-09 06:14:19 +02:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
// Go through all the up-edges (things that depend on this
|
|
|
|
// provider) and if any is not a module, then ignore this node.
|
|
|
|
nonModule := false
|
|
|
|
for _, sourceRaw := range g.UpEdges(v).List() {
|
|
|
|
source := sourceRaw.(dag.Vertex)
|
|
|
|
cn, ok := source.(graphNodeConfig)
|
|
|
|
if !ok {
|
|
|
|
nonModule = true
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
|
|
|
if cn.ConfigType() != GraphNodeConfigTypeModule {
|
|
|
|
nonModule = true
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if nonModule {
|
|
|
|
// We found something that depends on this provider that
|
|
|
|
// isn't a module, so skip it.
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2015-04-09 17:48:08 +02:00
|
|
|
// Disable the provider by replacing it with a "disabled" provider
|
|
|
|
disabled := &graphNodeDisabledProvider{GraphNodeProvider: pn}
|
|
|
|
if !g.Replace(v, disabled) {
|
|
|
|
panic(fmt.Sprintf(
|
|
|
|
"vertex disappeared from under us: %s",
|
|
|
|
dag.VertexName(v)))
|
|
|
|
}
|
2015-04-09 06:14:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2015-01-28 06:48:46 +01:00
|
|
|
// ProviderTransformer is a GraphTransformer that maps resources to
|
|
|
|
// providers within the graph. This will error if there are any resources
|
|
|
|
// that don't map to proper resources.
|
|
|
|
type ProviderTransformer struct{}
|
|
|
|
|
|
|
|
func (t *ProviderTransformer) Transform(g *Graph) error {
|
|
|
|
// Go through the other nodes and match them to providers they need
|
|
|
|
var err error
|
2015-01-28 07:14:01 +01:00
|
|
|
m := providerVertexMap(g)
|
2015-01-28 06:48:46 +01:00
|
|
|
for _, v := range g.Vertices() {
|
|
|
|
if pv, ok := v.(GraphNodeProviderConsumer); ok {
|
2015-02-10 08:32:28 +01:00
|
|
|
for _, p := range pv.ProvidedBy() {
|
|
|
|
target := m[p]
|
|
|
|
if target == nil {
|
|
|
|
err = multierror.Append(err, fmt.Errorf(
|
|
|
|
"%s: provider %s couldn't be found",
|
|
|
|
dag.VertexName(v), p))
|
|
|
|
continue
|
|
|
|
}
|
2015-01-28 06:48:46 +01:00
|
|
|
|
2015-02-10 08:32:28 +01:00
|
|
|
g.Connect(dag.BasicEdge(v, target))
|
|
|
|
}
|
2015-01-28 06:48:46 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2015-06-19 21:52:50 +02:00
|
|
|
// CloseProviderTransformer is a GraphTransformer that adds nodes to the
|
|
|
|
// graph that will close open provider connections that aren't needed anymore.
|
|
|
|
// A provider connection is not needed anymore once all depended resources
|
|
|
|
// in the graph are evaluated.
|
|
|
|
type CloseProviderTransformer struct{}
|
|
|
|
|
|
|
|
func (t *CloseProviderTransformer) Transform(g *Graph) error {
|
2015-06-26 21:21:03 +02:00
|
|
|
pm := providerVertexMap(g)
|
|
|
|
cpm := closeProviderVertexMap(g)
|
|
|
|
var err error
|
2015-06-19 21:52:50 +02:00
|
|
|
for _, v := range g.Vertices() {
|
|
|
|
if pv, ok := v.(GraphNodeProviderConsumer); ok {
|
|
|
|
for _, p := range pv.ProvidedBy() {
|
2015-06-26 21:21:03 +02:00
|
|
|
source := cpm[p]
|
2015-06-19 21:52:50 +02:00
|
|
|
|
|
|
|
if source == nil {
|
|
|
|
// Create a new graphNodeCloseProvider and add it to the graph
|
|
|
|
source = &graphNodeCloseProvider{ProviderNameValue: p}
|
|
|
|
g.Add(source)
|
|
|
|
|
2015-06-26 21:21:03 +02:00
|
|
|
// Close node needs to depend on provider
|
|
|
|
provider, ok := pm[p]
|
|
|
|
if !ok {
|
|
|
|
err = multierror.Append(err, fmt.Errorf(
|
2015-07-16 18:56:58 +02:00
|
|
|
"%s: provider %s couldn't be found for closing",
|
2015-06-26 21:21:03 +02:00
|
|
|
dag.VertexName(v), p))
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
g.Connect(dag.BasicEdge(source, provider))
|
|
|
|
|
2015-06-19 21:52:50 +02:00
|
|
|
// Make sure we also add the new graphNodeCloseProvider to the map
|
|
|
|
// so we don't create and add any duplicate graphNodeCloseProviders.
|
2015-06-26 21:21:03 +02:00
|
|
|
cpm[p] = source
|
2015-06-19 21:52:50 +02:00
|
|
|
}
|
|
|
|
|
2015-06-26 21:21:03 +02:00
|
|
|
// Close node depends on all nodes provided by the provider
|
2015-06-19 21:52:50 +02:00
|
|
|
g.Connect(dag.BasicEdge(source, v))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-26 21:21:03 +02:00
|
|
|
return err
|
2015-06-19 21:52:50 +02:00
|
|
|
}
|
|
|
|
|
2015-01-28 07:14:01 +01:00
|
|
|
// MissingProviderTransformer is a GraphTransformer that adds nodes
|
|
|
|
// for missing providers into the graph. Specifically, it creates provider
|
|
|
|
// configuration nodes for all the providers that we support. These are
|
|
|
|
// pruned later during an optimization pass.
|
|
|
|
type MissingProviderTransformer struct {
|
|
|
|
// Providers is the list of providers we support.
|
|
|
|
Providers []string
|
2015-01-28 06:48:46 +01:00
|
|
|
}
|
|
|
|
|
2015-01-28 07:14:01 +01:00
|
|
|
func (t *MissingProviderTransformer) Transform(g *Graph) error {
|
2015-06-25 05:58:52 +02:00
|
|
|
// Create a set of our supported providers
|
|
|
|
supported := make(map[string]struct{}, len(t.Providers))
|
|
|
|
for _, v := range t.Providers {
|
|
|
|
supported[v] = struct{}{}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get the map of providers we already have in our graph
|
2015-01-28 07:14:01 +01:00
|
|
|
m := providerVertexMap(g)
|
2015-06-25 05:58:52 +02:00
|
|
|
|
|
|
|
// Go through all the provider consumers and make sure we add
|
|
|
|
// that provider if it is missing.
|
|
|
|
for _, v := range g.Vertices() {
|
|
|
|
pv, ok := v.(GraphNodeProviderConsumer)
|
|
|
|
if !ok {
|
2015-01-28 07:14:01 +01:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2015-06-25 05:58:52 +02:00
|
|
|
for _, p := range pv.ProvidedBy() {
|
|
|
|
if _, ok := m[p]; ok {
|
|
|
|
// This provider already exists as a configure node
|
2015-06-26 21:00:02 +02:00
|
|
|
continue
|
2015-06-25 05:58:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// If the provider has an alias in it, we just want the type
|
|
|
|
ptype := p
|
|
|
|
if idx := strings.IndexRune(p, '.'); idx != -1 {
|
|
|
|
ptype = p[:idx]
|
|
|
|
}
|
|
|
|
|
|
|
|
if _, ok := supported[ptype]; !ok {
|
|
|
|
// If we don't support the provider type, skip it.
|
|
|
|
// Validation later will catch this as an error.
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2016-02-04 21:41:04 +01:00
|
|
|
// Add the missing provider node to the graph
|
|
|
|
m[p] = g.Add(&graphNodeProvider{ProviderNameValue: p})
|
2015-06-25 05:58:52 +02:00
|
|
|
}
|
2015-01-28 07:14:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2015-01-30 22:03:12 +01:00
|
|
|
// PruneProviderTransformer is a GraphTransformer that prunes all the
|
|
|
|
// providers that aren't needed from the graph. A provider is unneeded if
|
|
|
|
// no resource or module is using that provider.
|
|
|
|
type PruneProviderTransformer struct{}
|
|
|
|
|
|
|
|
func (t *PruneProviderTransformer) Transform(g *Graph) error {
|
|
|
|
for _, v := range g.Vertices() {
|
|
|
|
// We only care about the providers
|
2015-05-02 00:18:40 +02:00
|
|
|
if pn, ok := v.(GraphNodeProvider); !ok || pn.ProviderName() == "" {
|
2015-01-30 22:03:12 +01:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
// Does anything depend on this? If not, then prune it.
|
|
|
|
if s := g.UpEdges(v); s.Len() == 0 {
|
2016-04-19 01:19:43 +02:00
|
|
|
if nv, ok := v.(dag.NamedVertex); ok {
|
|
|
|
log.Printf("[DEBUG] Pruning provider with no dependencies: %s", nv.Name())
|
|
|
|
}
|
2015-01-30 22:03:12 +01:00
|
|
|
g.Remove(v)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2015-06-19 21:52:50 +02:00
|
|
|
func providerVertexMap(g *Graph) map[string]dag.Vertex {
|
|
|
|
m := make(map[string]dag.Vertex)
|
|
|
|
for _, v := range g.Vertices() {
|
|
|
|
if pv, ok := v.(GraphNodeProvider); ok {
|
|
|
|
m[pv.ProviderName()] = v
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return m
|
|
|
|
}
|
|
|
|
|
|
|
|
func closeProviderVertexMap(g *Graph) map[string]dag.Vertex {
|
|
|
|
m := make(map[string]dag.Vertex)
|
|
|
|
for _, v := range g.Vertices() {
|
|
|
|
if pv, ok := v.(GraphNodeCloseProvider); ok {
|
|
|
|
m[pv.CloseProviderName()] = v
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return m
|
|
|
|
}
|
|
|
|
|
2015-04-09 17:48:08 +02:00
|
|
|
type graphNodeDisabledProvider struct {
|
|
|
|
GraphNodeProvider
|
|
|
|
}
|
|
|
|
|
|
|
|
// GraphNodeEvalable impl.
|
|
|
|
func (n *graphNodeDisabledProvider) EvalTree() EvalNode {
|
|
|
|
var resourceConfig *ResourceConfig
|
|
|
|
|
|
|
|
return &EvalOpFilter{
|
2015-10-02 20:18:33 +02:00
|
|
|
Ops: []walkOperation{walkInput, walkValidate, walkRefresh, walkPlan, walkApply, walkDestroy},
|
2015-04-09 17:48:08 +02:00
|
|
|
Node: &EvalSequence{
|
|
|
|
Nodes: []EvalNode{
|
|
|
|
&EvalInterpolate{
|
|
|
|
Config: n.ProviderConfig(),
|
|
|
|
Output: &resourceConfig,
|
|
|
|
},
|
|
|
|
&EvalBuildProviderConfig{
|
|
|
|
Provider: n.ProviderName(),
|
|
|
|
Config: &resourceConfig,
|
|
|
|
Output: &resourceConfig,
|
|
|
|
},
|
|
|
|
&EvalSetProviderConfig{
|
|
|
|
Provider: n.ProviderName(),
|
|
|
|
Config: &resourceConfig,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-13 18:50:11 +02:00
|
|
|
// GraphNodeFlattenable impl.
|
|
|
|
func (n *graphNodeDisabledProvider) Flatten(p []string) (dag.Vertex, error) {
|
|
|
|
return &graphNodeDisabledProviderFlat{
|
|
|
|
graphNodeDisabledProvider: n,
|
|
|
|
PathValue: p,
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2015-04-09 17:51:38 +02:00
|
|
|
func (n *graphNodeDisabledProvider) Name() string {
|
|
|
|
return fmt.Sprintf("%s (disabled)", dag.VertexName(n.GraphNodeProvider))
|
|
|
|
}
|
|
|
|
|
2015-04-23 20:24:26 +02:00
|
|
|
// GraphNodeDotter impl.
|
|
|
|
func (n *graphNodeDisabledProvider) DotNode(name string, opts *GraphDotOpts) *dot.Node {
|
|
|
|
return dot.NewNode(name, map[string]string{
|
|
|
|
"label": n.Name(),
|
|
|
|
"shape": "diamond",
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// GraphNodeDotterOrigin impl.
|
|
|
|
func (n *graphNodeDisabledProvider) DotOrigin() bool {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2015-05-02 03:08:06 +02:00
|
|
|
// GraphNodeDependable impl.
|
|
|
|
func (n *graphNodeDisabledProvider) DependableName() []string {
|
|
|
|
return []string{"provider." + n.ProviderName()}
|
|
|
|
}
|
|
|
|
|
|
|
|
// GraphNodeProvider impl.
|
|
|
|
func (n *graphNodeDisabledProvider) ProviderName() string {
|
|
|
|
return n.GraphNodeProvider.ProviderName()
|
|
|
|
}
|
|
|
|
|
|
|
|
// GraphNodeProvider impl.
|
|
|
|
func (n *graphNodeDisabledProvider) ProviderConfig() *config.RawConfig {
|
|
|
|
return n.GraphNodeProvider.ProviderConfig()
|
|
|
|
}
|
|
|
|
|
2015-05-13 18:50:11 +02:00
|
|
|
// Same as graphNodeDisabledProvider, but for flattening
|
|
|
|
type graphNodeDisabledProviderFlat struct {
|
|
|
|
*graphNodeDisabledProvider
|
|
|
|
|
|
|
|
PathValue []string
|
|
|
|
}
|
|
|
|
|
|
|
|
func (n *graphNodeDisabledProviderFlat) Name() string {
|
|
|
|
return fmt.Sprintf(
|
|
|
|
"%s.%s", modulePrefixStr(n.PathValue), n.graphNodeDisabledProvider.Name())
|
|
|
|
}
|
|
|
|
|
|
|
|
func (n *graphNodeDisabledProviderFlat) Path() []string {
|
|
|
|
return n.PathValue
|
|
|
|
}
|
|
|
|
|
|
|
|
func (n *graphNodeDisabledProviderFlat) ProviderName() string {
|
|
|
|
return fmt.Sprintf(
|
|
|
|
"%s.%s", modulePrefixStr(n.PathValue),
|
|
|
|
n.graphNodeDisabledProvider.ProviderName())
|
|
|
|
}
|
|
|
|
|
|
|
|
// GraphNodeDependable impl.
|
|
|
|
func (n *graphNodeDisabledProviderFlat) DependableName() []string {
|
2016-04-19 01:19:43 +02:00
|
|
|
return modulePrefixList(
|
|
|
|
n.graphNodeDisabledProvider.DependableName(),
|
|
|
|
modulePrefixStr(n.PathValue))
|
2015-05-13 18:50:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (n *graphNodeDisabledProviderFlat) DependentOn() []string {
|
|
|
|
var result []string
|
|
|
|
|
|
|
|
// If we're in a module, then depend on our parent's provider
|
|
|
|
if len(n.PathValue) > 1 {
|
|
|
|
prefix := modulePrefixStr(n.PathValue[:len(n.PathValue)-1])
|
2016-04-19 01:19:43 +02:00
|
|
|
result = modulePrefixList(
|
|
|
|
n.graphNodeDisabledProvider.DependableName(), prefix)
|
2015-05-13 18:50:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return result
|
|
|
|
}
|
|
|
|
|
2015-06-19 21:52:50 +02:00
|
|
|
type graphNodeCloseProvider struct {
|
|
|
|
ProviderNameValue string
|
|
|
|
}
|
|
|
|
|
|
|
|
func (n *graphNodeCloseProvider) Name() string {
|
|
|
|
return fmt.Sprintf("provider.%s (close)", n.ProviderNameValue)
|
|
|
|
}
|
|
|
|
|
|
|
|
// GraphNodeEvalable impl.
|
|
|
|
func (n *graphNodeCloseProvider) EvalTree() EvalNode {
|
|
|
|
return CloseProviderEvalTree(n.ProviderNameValue)
|
|
|
|
}
|
|
|
|
|
|
|
|
// GraphNodeDependable impl.
|
|
|
|
func (n *graphNodeCloseProvider) DependableName() []string {
|
|
|
|
return []string{n.Name()}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (n *graphNodeCloseProvider) CloseProviderName() string {
|
|
|
|
return n.ProviderNameValue
|
|
|
|
}
|
|
|
|
|
|
|
|
// GraphNodeDotter impl.
|
|
|
|
func (n *graphNodeCloseProvider) DotNode(name string, opts *GraphDotOpts) *dot.Node {
|
2015-06-25 00:36:45 +02:00
|
|
|
if !opts.Verbose {
|
|
|
|
return nil
|
|
|
|
}
|
2015-06-19 21:52:50 +02:00
|
|
|
return dot.NewNode(name, map[string]string{
|
|
|
|
"label": n.Name(),
|
|
|
|
"shape": "diamond",
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2016-02-04 21:41:04 +01:00
|
|
|
type graphNodeProvider struct {
|
2015-01-28 07:14:01 +01:00
|
|
|
ProviderNameValue string
|
|
|
|
}
|
|
|
|
|
2016-02-04 21:41:04 +01:00
|
|
|
func (n *graphNodeProvider) Name() string {
|
2015-01-28 07:14:01 +01:00
|
|
|
return fmt.Sprintf("provider.%s", n.ProviderNameValue)
|
|
|
|
}
|
|
|
|
|
2015-02-03 10:43:18 +01:00
|
|
|
// GraphNodeEvalable impl.
|
2016-02-04 21:41:04 +01:00
|
|
|
func (n *graphNodeProvider) EvalTree() EvalNode {
|
2015-02-05 23:32:36 +01:00
|
|
|
return ProviderEvalTree(n.ProviderNameValue, nil)
|
2015-02-03 10:43:18 +01:00
|
|
|
}
|
|
|
|
|
2015-05-02 03:39:24 +02:00
|
|
|
// GraphNodeDependable impl.
|
2016-02-04 21:41:04 +01:00
|
|
|
func (n *graphNodeProvider) DependableName() []string {
|
2015-05-02 03:39:24 +02:00
|
|
|
return []string{n.Name()}
|
|
|
|
}
|
|
|
|
|
2016-02-04 21:41:04 +01:00
|
|
|
func (n *graphNodeProvider) ProviderName() string {
|
2015-01-28 07:14:01 +01:00
|
|
|
return n.ProviderNameValue
|
|
|
|
}
|
|
|
|
|
2016-02-04 21:41:04 +01:00
|
|
|
func (n *graphNodeProvider) ProviderConfig() *config.RawConfig {
|
2015-04-09 17:48:08 +02:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2015-02-20 07:58:42 +01:00
|
|
|
// GraphNodeDotter impl.
|
2016-02-04 21:41:04 +01:00
|
|
|
func (n *graphNodeProvider) DotNode(name string, opts *GraphDotOpts) *dot.Node {
|
2015-04-23 20:24:26 +02:00
|
|
|
return dot.NewNode(name, map[string]string{
|
|
|
|
"label": n.Name(),
|
|
|
|
"shape": "diamond",
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// GraphNodeDotterOrigin impl.
|
2016-02-04 21:41:04 +01:00
|
|
|
func (n *graphNodeProvider) DotOrigin() bool {
|
2015-04-23 20:24:26 +02:00
|
|
|
return true
|
2015-02-20 07:58:42 +01:00
|
|
|
}
|
|
|
|
|
2015-05-02 00:23:37 +02:00
|
|
|
// GraphNodeFlattenable impl.
|
2016-02-04 21:41:04 +01:00
|
|
|
func (n *graphNodeProvider) Flatten(p []string) (dag.Vertex, error) {
|
|
|
|
return &graphNodeProviderFlat{
|
|
|
|
graphNodeProvider: n,
|
|
|
|
PathValue: p,
|
2015-05-02 00:23:37 +02:00
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Same as graphNodeMissingProvider, but for flattening
|
2016-02-04 21:41:04 +01:00
|
|
|
type graphNodeProviderFlat struct {
|
|
|
|
*graphNodeProvider
|
2015-05-02 00:23:37 +02:00
|
|
|
|
|
|
|
PathValue []string
|
|
|
|
}
|
|
|
|
|
2016-02-04 21:41:04 +01:00
|
|
|
func (n *graphNodeProviderFlat) Name() string {
|
2015-05-02 00:23:37 +02:00
|
|
|
return fmt.Sprintf(
|
2016-02-04 21:41:04 +01:00
|
|
|
"%s.%s", modulePrefixStr(n.PathValue), n.graphNodeProvider.Name())
|
2015-05-02 00:23:37 +02:00
|
|
|
}
|
|
|
|
|
2016-02-04 21:41:04 +01:00
|
|
|
func (n *graphNodeProviderFlat) Path() []string {
|
2015-05-02 00:23:37 +02:00
|
|
|
return n.PathValue
|
|
|
|
}
|
|
|
|
|
2016-02-04 21:41:04 +01:00
|
|
|
func (n *graphNodeProviderFlat) ProviderName() string {
|
2015-05-02 00:23:37 +02:00
|
|
|
return fmt.Sprintf(
|
|
|
|
"%s.%s", modulePrefixStr(n.PathValue),
|
2016-02-04 21:41:04 +01:00
|
|
|
n.graphNodeProvider.ProviderName())
|
2015-05-02 00:23:37 +02:00
|
|
|
}
|
2015-05-02 03:08:06 +02:00
|
|
|
|
2015-05-02 03:39:24 +02:00
|
|
|
// GraphNodeDependable impl.
|
2016-02-04 21:41:04 +01:00
|
|
|
func (n *graphNodeProviderFlat) DependableName() []string {
|
2015-05-02 03:39:24 +02:00
|
|
|
return []string{n.Name()}
|
|
|
|
}
|
|
|
|
|
2016-02-04 21:41:04 +01:00
|
|
|
func (n *graphNodeProviderFlat) DependentOn() []string {
|
2015-05-02 03:08:06 +02:00
|
|
|
var result []string
|
|
|
|
|
|
|
|
// If we're in a module, then depend on our parent's provider
|
|
|
|
if len(n.PathValue) > 1 {
|
|
|
|
prefix := modulePrefixStr(n.PathValue[:len(n.PathValue)-1])
|
2016-04-19 01:19:43 +02:00
|
|
|
result = modulePrefixList(n.graphNodeProvider.DependableName(), prefix)
|
2015-05-02 03:08:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return result
|
|
|
|
}
|