]> git.immae.eu Git - github/fretlink/terraform-provider-statuscake.git/blame - vendor/github.com/hashicorp/terraform/terraform/context_components.go
Merge branch 'fix_read_test' of github.com:alexandreFre/terraform-provider-statuscake
[github/fretlink/terraform-provider-statuscake.git] / vendor / github.com / hashicorp / terraform / terraform / context_components.go
CommitLineData
bae9f6d2
JC
1package terraform
2
3import (
4 "fmt"
107c1cdb
ND
5
6 "github.com/hashicorp/terraform/providers"
7 "github.com/hashicorp/terraform/provisioners"
bae9f6d2
JC
8)
9
10// contextComponentFactory is the interface that Context uses
11// to initialize various components such as providers and provisioners.
12// This factory gets more information than the raw maps using to initialize
13// a Context. This information is used for debugging.
14type contextComponentFactory interface {
15 // ResourceProvider creates a new ResourceProvider with the given
16 // type. The "uid" is a unique identifier for this provider being
17 // initialized that can be used for internal tracking.
107c1cdb 18 ResourceProvider(typ, uid string) (providers.Interface, error)
bae9f6d2
JC
19 ResourceProviders() []string
20
21 // ResourceProvisioner creates a new ResourceProvisioner with the
22 // given type. The "uid" is a unique identifier for this provisioner
23 // being initialized that can be used for internal tracking.
107c1cdb 24 ResourceProvisioner(typ, uid string) (provisioners.Interface, error)
bae9f6d2
JC
25 ResourceProvisioners() []string
26}
27
28// basicComponentFactory just calls a factory from a map directly.
29type basicComponentFactory struct {
107c1cdb
ND
30 providers map[string]providers.Factory
31 provisioners map[string]ProvisionerFactory
bae9f6d2
JC
32}
33
34func (c *basicComponentFactory) ResourceProviders() []string {
35 result := make([]string, len(c.providers))
107c1cdb 36 for k := range c.providers {
bae9f6d2
JC
37 result = append(result, k)
38 }
39
40 return result
41}
42
43func (c *basicComponentFactory) ResourceProvisioners() []string {
44 result := make([]string, len(c.provisioners))
107c1cdb 45 for k := range c.provisioners {
bae9f6d2
JC
46 result = append(result, k)
47 }
48
49 return result
50}
51
107c1cdb 52func (c *basicComponentFactory) ResourceProvider(typ, uid string) (providers.Interface, error) {
bae9f6d2
JC
53 f, ok := c.providers[typ]
54 if !ok {
55 return nil, fmt.Errorf("unknown provider %q", typ)
56 }
57
58 return f()
59}
60
107c1cdb 61func (c *basicComponentFactory) ResourceProvisioner(typ, uid string) (provisioners.Interface, error) {
bae9f6d2
JC
62 f, ok := c.provisioners[typ]
63 if !ok {
64 return nil, fmt.Errorf("unknown provisioner %q", typ)
65 }
66
67 return f()
68}