-
Notifications
You must be signed in to change notification settings - Fork 9.6k
/
context_components.go
65 lines (53 loc) · 1.76 KB
/
context_components.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package terraform
import (
"fmt"
"github.com/hashicorp/terraform/addrs"
"github.com/hashicorp/terraform/providers"
"github.com/hashicorp/terraform/provisioners"
)
// contextComponentFactory is the interface that Context uses
// to initialize various components such as providers and provisioners.
// This factory gets more information than the raw maps using to initialize
// a Context. This information is used for debugging.
type contextComponentFactory interface {
// ResourceProvider creates a new ResourceProvider with the given type.
ResourceProvider(typ addrs.Provider) (providers.Interface, error)
ResourceProviders() []string
// ResourceProvisioner creates a new ResourceProvisioner with the given
// type.
ResourceProvisioner(typ string) (provisioners.Interface, error)
ResourceProvisioners() []string
}
// basicComponentFactory just calls a factory from a map directly.
type basicComponentFactory struct {
providers map[addrs.Provider]providers.Factory
provisioners map[string]provisioners.Factory
}
func (c *basicComponentFactory) ResourceProviders() []string {
var result []string
for k := range c.providers {
result = append(result, k.String())
}
return result
}
func (c *basicComponentFactory) ResourceProvisioners() []string {
var result []string
for k := range c.provisioners {
result = append(result, k)
}
return result
}
func (c *basicComponentFactory) ResourceProvider(typ addrs.Provider) (providers.Interface, error) {
f, ok := c.providers[typ]
if !ok {
return nil, fmt.Errorf("unknown provider %q", typ.String())
}
return f()
}
func (c *basicComponentFactory) ResourceProvisioner(typ string) (provisioners.Interface, error) {
f, ok := c.provisioners[typ]
if !ok {
return nil, fmt.Errorf("unknown provisioner %q", typ)
}
return f()
}