diff options
Diffstat (limited to 'vendor/github.com/hashicorp/terraform/terraform/node_provider_abstract.go')
-rw-r--r-- | vendor/github.com/hashicorp/terraform/terraform/node_provider_abstract.go | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/vendor/github.com/hashicorp/terraform/terraform/node_provider_abstract.go b/vendor/github.com/hashicorp/terraform/terraform/node_provider_abstract.go new file mode 100644 index 0000000..6cc8365 --- /dev/null +++ b/vendor/github.com/hashicorp/terraform/terraform/node_provider_abstract.go | |||
@@ -0,0 +1,85 @@ | |||
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 | // RemovableIfNotTargeted | ||
42 | func (n *NodeAbstractProvider) RemoveIfNotTargeted() bool { | ||
43 | // We need to add this so that this node will be removed if | ||
44 | // it isn't targeted or a dependency of a target. | ||
45 | return true | ||
46 | } | ||
47 | |||
48 | // GraphNodeReferencer | ||
49 | func (n *NodeAbstractProvider) References() []string { | ||
50 | if n.Config == nil { | ||
51 | return nil | ||
52 | } | ||
53 | |||
54 | return ReferencesFromConfig(n.Config.RawConfig) | ||
55 | } | ||
56 | |||
57 | // GraphNodeProvider | ||
58 | func (n *NodeAbstractProvider) ProviderName() string { | ||
59 | return n.NameValue | ||
60 | } | ||
61 | |||
62 | // GraphNodeProvider | ||
63 | func (n *NodeAbstractProvider) ProviderConfig() *config.RawConfig { | ||
64 | if n.Config == nil { | ||
65 | return nil | ||
66 | } | ||
67 | |||
68 | return n.Config.RawConfig | ||
69 | } | ||
70 | |||
71 | // GraphNodeAttachProvider | ||
72 | func (n *NodeAbstractProvider) AttachProvider(c *config.ProviderConfig) { | ||
73 | n.Config = c | ||
74 | } | ||
75 | |||
76 | // GraphNodeDotter impl. | ||
77 | func (n *NodeAbstractProvider) DotNode(name string, opts *dag.DotOpts) *dag.DotNode { | ||
78 | return &dag.DotNode{ | ||
79 | Name: name, | ||
80 | Attrs: map[string]string{ | ||
81 | "label": n.Name(), | ||
82 | "shape": "diamond", | ||
83 | }, | ||
84 | } | ||
85 | } | ||