github.com/trawler/terraform@v0.10.8-0.20171106022149-4b1c7a1d9b48/terraform/node_provider_abstract.go (about)

     1  package terraform
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/hashicorp/terraform/config"
     7  	"github.com/hashicorp/terraform/dag"
     8  )
     9  
    10  // ConcreteProviderNodeFunc is a callback type used to convert an
    11  // abstract provider to a concrete one of some type.
    12  type ConcreteProviderNodeFunc func(*NodeAbstractProvider) dag.Vertex
    13  
    14  // NodeAbstractProvider represents a provider that has no associated operations.
    15  // It registers all the common interfaces across operations for providers.
    16  type NodeAbstractProvider struct {
    17  	NameValue string
    18  	PathValue []string
    19  
    20  	// The fields below will be automatically set using the Attach
    21  	// interfaces if you're running those transforms, but also be explicitly
    22  	// set if you already have that information.
    23  
    24  	Config *config.ProviderConfig
    25  }
    26  
    27  func ResolveProviderName(name string, path []string) string {
    28  	name = fmt.Sprintf("provider.%s", name)
    29  	if len(path) > 1 {
    30  		name = fmt.Sprintf("%s.%s", modulePrefixStr(path), name)
    31  	}
    32  
    33  	return name
    34  }
    35  
    36  func (n *NodeAbstractProvider) Name() string {
    37  	return ResolveProviderName(n.NameValue, n.PathValue)
    38  }
    39  
    40  // GraphNodeSubPath
    41  func (n *NodeAbstractProvider) Path() []string {
    42  	return n.PathValue
    43  }
    44  
    45  // RemovableIfNotTargeted
    46  func (n *NodeAbstractProvider) RemoveIfNotTargeted() bool {
    47  	// We need to add this so that this node will be removed if
    48  	// it isn't targeted or a dependency of a target.
    49  	return true
    50  }
    51  
    52  // GraphNodeReferencer
    53  func (n *NodeAbstractProvider) References() []string {
    54  	if n.Config == nil {
    55  		return nil
    56  	}
    57  
    58  	return ReferencesFromConfig(n.Config.RawConfig)
    59  }
    60  
    61  // GraphNodeProvider
    62  func (n *NodeAbstractProvider) ProviderName() string {
    63  	return n.NameValue
    64  }
    65  
    66  // GraphNodeProvider
    67  func (n *NodeAbstractProvider) ProviderConfig() *config.ProviderConfig {
    68  	if n.Config == nil {
    69  		return nil
    70  	}
    71  
    72  	return n.Config
    73  }
    74  
    75  // GraphNodeAttachProvider
    76  func (n *NodeAbstractProvider) AttachProvider(c *config.ProviderConfig) {
    77  	n.Config = c
    78  }
    79  
    80  // GraphNodeDotter impl.
    81  func (n *NodeAbstractProvider) DotNode(name string, opts *dag.DotOpts) *dag.DotNode {
    82  	return &dag.DotNode{
    83  		Name: name,
    84  		Attrs: map[string]string{
    85  			"label": n.Name(),
    86  			"shape": "diamond",
    87  		},
    88  	}
    89  }