github.com/pbthorste/terraform@v0.8.6-0.20170127005045-deb56bd93da2/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 (n *NodeAbstractProvider) Name() string { 28 result := fmt.Sprintf("provider.%s", n.NameValue) 29 if len(n.PathValue) > 1 { 30 result = fmt.Sprintf("%s.%s", modulePrefixStr(n.PathValue), result) 31 } 32 33 return result 34 } 35 36 // GraphNodeSubPath 37 func (n *NodeAbstractProvider) Path() []string { 38 return n.PathValue 39 } 40 41 // GraphNodeReferencer 42 func (n *NodeAbstractProvider) References() []string { 43 if n.Config == nil { 44 return nil 45 } 46 47 return ReferencesFromConfig(n.Config.RawConfig) 48 } 49 50 // GraphNodeProvider 51 func (n *NodeAbstractProvider) ProviderName() string { 52 return n.NameValue 53 } 54 55 // GraphNodeProvider 56 func (n *NodeAbstractProvider) ProviderConfig() *config.RawConfig { 57 if n.Config == nil { 58 return nil 59 } 60 61 return n.Config.RawConfig 62 } 63 64 // GraphNodeAttachProvider 65 func (n *NodeAbstractProvider) AttachProvider(c *config.ProviderConfig) { 66 n.Config = c 67 } 68 69 // GraphNodeDotter impl. 70 func (n *NodeAbstractProvider) DotNode(name string, opts *dag.DotOpts) *dag.DotNode { 71 return &dag.DotNode{ 72 Name: name, 73 Attrs: map[string]string{ 74 "label": n.Name(), 75 "shape": "diamond", 76 }, 77 } 78 }