forked from hashicorp/terraform-provider-vsphere
-
Notifications
You must be signed in to change notification settings - Fork 0
/
provider.go
129 lines (115 loc) · 4.81 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
package vsphere
import (
"fmt"
"time"
"github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform/terraform"
)
// defaultAPITimeout is a default timeout value that is passed to functions
// requiring contexts, and other various waiters.
const defaultAPITimeout = time.Minute * 5
// Provider returns a terraform.ResourceProvider.
func Provider() terraform.ResourceProvider {
return &schema.Provider{
Schema: map[string]*schema.Schema{
"user": &schema.Schema{
Type: schema.TypeString,
Required: true,
DefaultFunc: schema.EnvDefaultFunc("VSPHERE_USER", nil),
Description: "The user name for vSphere API operations.",
},
"password": &schema.Schema{
Type: schema.TypeString,
Required: true,
DefaultFunc: schema.EnvDefaultFunc("VSPHERE_PASSWORD", nil),
Description: "The user password for vSphere API operations.",
},
"vsphere_server": &schema.Schema{
Type: schema.TypeString,
Optional: true,
DefaultFunc: schema.EnvDefaultFunc("VSPHERE_SERVER", nil),
Description: "The vSphere Server name for vSphere API operations.",
},
"allow_unverified_ssl": &schema.Schema{
Type: schema.TypeBool,
Optional: true,
DefaultFunc: schema.EnvDefaultFunc("VSPHERE_ALLOW_UNVERIFIED_SSL", false),
Description: "If set, VMware vSphere client will permit unverifiable SSL certificates.",
},
"vcenter_server": &schema.Schema{
Type: schema.TypeString,
Optional: true,
DefaultFunc: schema.EnvDefaultFunc("VSPHERE_VCENTER", nil),
Deprecated: "This field has been renamed to vsphere_server.",
},
"client_debug": &schema.Schema{
Type: schema.TypeBool,
Optional: true,
DefaultFunc: schema.EnvDefaultFunc("VSPHERE_CLIENT_DEBUG", false),
Description: "govomomi debug",
},
"client_debug_path_run": &schema.Schema{
Type: schema.TypeString,
Optional: true,
DefaultFunc: schema.EnvDefaultFunc("VSPHERE_CLIENT_DEBUG_PATH_RUN", ""),
Description: "govomomi debug path for a single run",
},
"client_debug_path": &schema.Schema{
Type: schema.TypeString,
Optional: true,
DefaultFunc: schema.EnvDefaultFunc("VSPHERE_CLIENT_DEBUG_PATH", ""),
Description: "govomomi debug path for debug",
},
},
ResourcesMap: map[string]*schema.Resource{
"vsphere_datacenter": resourceVSphereDatacenter(),
"vsphere_distributed_port_group": resourceVSphereDistributedPortGroup(),
"vsphere_distributed_virtual_switch": resourceVSphereDistributedVirtualSwitch(),
"vsphere_file": resourceVSphereFile(),
"vsphere_folder": resourceVSphereFolder(),
"vsphere_host_port_group": resourceVSphereHostPortGroup(),
"vsphere_host_virtual_switch": resourceVSphereHostVirtualSwitch(),
"vsphere_license": resourceVSphereLicense(),
"vsphere_tag": resourceVSphereTag(),
"vsphere_tag_category": resourceVSphereTagCategory(),
"vsphere_virtual_disk": resourceVSphereVirtualDisk(),
"vsphere_virtual_machine": resourceVSphereVirtualMachine(),
"vsphere_nas_datastore": resourceVSphereNasDatastore(),
"vsphere_vmfs_datastore": resourceVSphereVmfsDatastore(),
"vsphere_virtual_machine_snapshot": resourceVSphereVirtualMachineSnapshot(),
},
DataSourcesMap: map[string]*schema.Resource{
"vsphere_datacenter": dataSourceVSphereDatacenter(),
"vsphere_distributed_virtual_switch": dataSourceVSphereDistributedVirtualSwitch(),
"vsphere_host": dataSourceVSphereHost(),
"vsphere_network": dataSourceVSphereNetwork(),
"vsphere_tag": dataSourceVSphereTag(),
"vsphere_tag_category": dataSourceVSphereTagCategory(),
"vsphere_vmfs_disks": dataSourceVSphereVmfsDisks(),
},
ConfigureFunc: providerConfigure,
}
}
func providerConfigure(d *schema.ResourceData) (interface{}, error) {
// Handle backcompat support for vcenter_server; once that is removed,
// vsphere_server can just become a Required field that is referenced inline
// in Config below.
server := d.Get("vsphere_server").(string)
if server == "" {
server = d.Get("vcenter_server").(string)
}
if server == "" {
return nil, fmt.Errorf(
"One of vsphere_server or [deprecated] vcenter_server must be provided.")
}
config := Config{
User: d.Get("user").(string),
Password: d.Get("password").(string),
InsecureFlag: d.Get("allow_unverified_ssl").(bool),
VSphereServer: server,
Debug: d.Get("client_debug").(bool),
DebugPathRun: d.Get("client_debug_path_run").(string),
DebugPath: d.Get("client_debug_path").(string),
}
return config.Client()
}