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