-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathprovider.go
93 lines (80 loc) · 2.64 KB
/
provider.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package main
import (
"fmt"
"github.com/hashicorp/terraform/helper/mutexkv"
"github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform/terraform"
)
// Provider is a basic structure that describes a provider: the configuration
// keys it takes, the resources it supports, a callback to configure, etc.
func Provider() terraform.ResourceProvider {
// The actual provider
return &schema.Provider{
Schema: map[string]*schema.Schema{
"debug": &schema.Schema{
Type: schema.TypeBool,
Optional: true,
Default: false,
},
"insecure": &schema.Schema{
Type: schema.TypeBool,
Optional: true,
DefaultFunc: schema.EnvDefaultFunc("NSX_ALLOW_UNVERIFIED_SSL", false),
},
"nsxusername": &schema.Schema{
Type: schema.TypeString,
Optional: true,
DefaultFunc: schema.EnvDefaultFunc("NSXUSERNAME", nil),
},
"nsxpassword": &schema.Schema{
Type: schema.TypeString,
Optional: true,
DefaultFunc: schema.EnvDefaultFunc("NSXPASSWORD", nil),
},
"nsxserver": &schema.Schema{
Type: schema.TypeString,
Optional: true,
DefaultFunc: schema.EnvDefaultFunc("NSXSERVER", nil),
},
},
ResourcesMap: map[string]*schema.Resource{
"nsx_logical_switch": resourceLogicalSwitch(),
"nsx_edge_interface": resourceEdgeInterface(),
"nsx_dhcp_relay": resourceDHCPRelay(),
"nsx_service": resourceService(),
"nsx_security_group": resourceSecurityGroup(),
"nsx_security_tag": resourceSecurityTag(),
"nsx_security_tag_attachment": resourceSecurityTagAttachment(),
"nsx_security_policy": resourceSecurityPolicy(),
"nsx_security_policy_rule": resourceSecurityPolicyRule(),
"nsx_firewall_exclusion": resourceFirewallExclusion(),
},
ConfigureFunc: providerConfigure,
}
}
func providerConfigure(d *schema.ResourceData) (interface{}, error) {
debug := d.Get("debug").(bool)
insecure := d.Get("insecure").(bool)
nsxusername := d.Get("nsxusername").(string)
if nsxusername == "" {
return nil, fmt.Errorf("nsxusername must be provided")
}
nsxpassword := d.Get("nsxpassword").(string)
if nsxpassword == "" {
return nil, fmt.Errorf("nsxpassword must be provided")
}
nsxserver := d.Get("nsxserver").(string)
if nsxserver == "" {
return nil, fmt.Errorf("nsxserver must be provided")
}
config := Config{
Debug: debug,
Insecure: insecure,
NSXUserName: nsxusername,
NSXPassword: nsxpassword,
NSXServer: nsxserver,
}
return config.Client()
}
// This is a global MutexKV for use within this plugin.
var nsxMutexKV = mutexkv.NewMutexKV()