Skip to content

Commit 6ff92e1

Browse files
authored
Merge pull request #197 from rawmind0/vsphere
Updated vsphere_config argument schema on rancher2_node_template resource
2 parents cfc6d45 + 951be94 commit 6ff92e1

6 files changed

Lines changed: 227 additions & 35 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,13 @@ FEATURES:
77
ENHANCEMENTS:
88

99
* Added GetRancherVersion function to provider config
10+
* Updated `vsphere_config` argument schema on `rancher2_node_template` resource to support Rancher v2.3.3 features
11+
* Updated rancher to v2.3.3 and k3s to v0.10.2 on acceptance tests
1012

1113
BUG FIXES:
1214

13-
15+
* Set `annotations` argument as computed on `rancher2_node_template` resource
16+
* Added `rancher2_node_template` resource workaround on docs when upgrade Rancher to v2.3.3
1417

1518
## 1.7.0 (November 20, 2019)
1619

rancher2/schema_node_template.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ func nodeTemplateFields() map[string]*schema.Schema {
134134
"annotations": &schema.Schema{
135135
Type: schema.TypeMap,
136136
Optional: true,
137+
Computed: true,
137138
},
138139
"labels": &schema.Schema{
139140
Type: schema.TypeMap,

rancher2/schema_node_template_vsphere.go

Lines changed: 128 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@ import (
66
)
77

88
const (
9-
vmwarevsphereConfigDriver = "vmwarevsphere"
9+
vmwarevsphereConfigDriver = "vmwarevsphere"
10+
vmwarevsphereConfigCreationTypeDefault = "legacy"
1011
)
1112

1213
var (
14+
vmwarevsphereConfigCreationType = []string{"vm", "template", "library", "legacy"}
1315
vmwarevsphereConfigVappIpallocationpolicies = []string{"dhcp", "fixed", "transient", "fixedAllocated"}
1416
vmwarevsphereConfigVappIpprotocols = []string{"IPv4", "IPv6"}
1517
vmwarevsphereConfigVappTransports = []string{"iso", "com.vmware.guestInfo"}
@@ -20,17 +22,28 @@ var (
2022
type vmwarevsphereConfig struct {
2123
Boot2dockerURL string `json:"boot2dockerUrl,omitempty" yaml:"boot2dockerUrl,omitempty"`
2224
Cfgparam []string `json:"cfgparam,omitempty" yaml:"cfgparam,omitempty"`
25+
CloneFrom string `json:"cloneFrom,omitempty" yaml:"cloneFrom,omitempty"`
26+
CloudConfig string `json:"cloudConfig,omitempty" yaml:"cloudConfig,omitempty"`
2327
Cloudinit string `json:"cloudinit,omitempty" yaml:"cloudinit,omitempty"`
28+
ContentLibrary string `json:"contentLibrary,omitempty" yaml:"contentLibrary,omitempty"`
2429
CPUCount string `json:"cpuCount,omitempty" yaml:"cpuCount,omitempty"`
30+
CreationType string `json:"creationType,omitempty" yaml:"creationType,omitempty"`
31+
CustomAttributes []string `json:"customAttribute,omitempty" yaml:"customAttribute,omitempty"`
2532
Datacenter string `json:"datacenter,omitempty" yaml:"datacenter,omitempty"`
2633
Datastore string `json:"datastore,omitempty" yaml:"datastore,omitempty"`
34+
DatastoreCluster string `json:"datastoreCluster,omitempty" yaml:"datastoreCluster,omitempty"`
2735
DiskSize string `json:"diskSize,omitempty" yaml:"diskSize,omitempty"`
2836
Folder string `json:"folder,omitempty" yaml:"folder,omitempty"`
2937
Hostsystem string `json:"hostsystem,omitempty" yaml:"hostsystem,omitempty"`
3038
MemorySize string `json:"memorySize,omitempty" yaml:"memorySize,omitempty"`
3139
Network []string `json:"network,omitempty" yaml:"network,omitempty"`
3240
Password string `json:"password,omitempty" yaml:"password,omitempty"`
3341
Pool string `json:"pool,omitempty" yaml:"pool,omitempty"`
42+
SshPassword string `json:"sshPassword,omitempty" yaml:"sshPassword,omitempty"`
43+
SshPort string `json:"sshPort,omitempty" yaml:"sshPort,omitempty"`
44+
SshUser string `json:"sshUser,omitempty" yaml:"sshUser,omitempty"`
45+
SshUserGroup string `json:"sshUserGroup,omitempty" yaml:"sshUserGroup,omitempty"`
46+
Tags []string `json:"tag,omitempty" yaml:"tag,omitempty"`
3447
Username string `json:"username,omitempty" yaml:"username,omitempty"`
3548
VappIpallocationpolicy string `json:"vappIpallocationpolicy,omitempty" yaml:"vappIpallocationpolicy,omitempty"`
3649
VappIpprotocol string `json:"vappIpprotocol,omitempty" yaml:"vappIpprotocol,omitempty"`
@@ -45,55 +58,101 @@ type vmwarevsphereConfig struct {
4558
func vsphereConfigFields() map[string]*schema.Schema {
4659
s := map[string]*schema.Schema{
4760
"boot2docker_url": &schema.Schema{
48-
Type: schema.TypeString,
49-
Optional: true,
50-
Default: "https://releases.rancher.com/os/latest/rancheros-vmware.iso",
61+
Type: schema.TypeString,
62+
Optional: true,
63+
Default: "https://releases.rancher.com/os/latest/rancheros-vmware.iso",
64+
Description: "vSphere URL for boot2docker image",
5165
},
5266
"cfgparam": &schema.Schema{
53-
Type: schema.TypeList,
54-
Optional: true,
67+
Type: schema.TypeList,
68+
Optional: true,
69+
Description: "vSphere vm configuration parameters (used for guestinfo)",
5570
Elem: &schema.Schema{
5671
Type: schema.TypeString,
5772
},
5873
},
74+
"clone_from": &schema.Schema{
75+
Type: schema.TypeString,
76+
Optional: true,
77+
Description: "If you choose creation type clone a name of what you want to clone is required",
78+
},
79+
"cloud_config": &schema.Schema{
80+
Type: schema.TypeString,
81+
Optional: true,
82+
Description: "Filepath to a cloud-config yaml file to put into the ISO user-data",
83+
},
5984
"cloudinit": &schema.Schema{
60-
Type: schema.TypeString,
61-
Optional: true,
85+
Type: schema.TypeString,
86+
Optional: true,
87+
Description: "vSphere cloud-init filepath or url to add to guestinfo",
88+
},
89+
"content_library": &schema.Schema{
90+
Type: schema.TypeString,
91+
Optional: true,
92+
Description: "If you choose to clone from a content library template specify the name of the library",
6293
},
6394
"cpu_count": &schema.Schema{
64-
Type: schema.TypeString,
65-
Optional: true,
66-
Default: "2",
95+
Type: schema.TypeString,
96+
Optional: true,
97+
Default: "2",
98+
Description: "vSphere CPU number for docker VM",
99+
},
100+
"creation_type": &schema.Schema{
101+
Type: schema.TypeString,
102+
Optional: true,
103+
Default: vmwarevsphereConfigCreationTypeDefault,
104+
ValidateFunc: validation.StringInSlice(vmwarevsphereConfigCreationType, true),
105+
Description: "Creation type when creating a new virtual machine. Supported values: vm, template, library, legacy",
106+
},
107+
"custom_attributes": &schema.Schema{
108+
Type: schema.TypeList,
109+
Optional: true,
110+
Description: "vSphere custom attributes, format key/value e.g. '200=my custom value'",
111+
Elem: &schema.Schema{
112+
Type: schema.TypeString,
113+
},
67114
},
68115
"datacenter": &schema.Schema{
69-
Type: schema.TypeString,
70-
Optional: true,
116+
Type: schema.TypeString,
117+
Optional: true,
118+
Description: "vSphere datacenter for virtual machine",
71119
},
72120
"datastore": &schema.Schema{
73-
Type: schema.TypeString,
74-
Optional: true,
121+
Type: schema.TypeString,
122+
Optional: true,
123+
Description: "vSphere datastore for virtual machine",
124+
},
125+
"datastore_cluster": &schema.Schema{
126+
Type: schema.TypeString,
127+
Optional: true,
128+
Description: "vSphere datastore cluster for virtual machine",
75129
},
76130
"disk_size": &schema.Schema{
77-
Type: schema.TypeString,
78-
Optional: true,
79-
Default: "20480",
131+
Type: schema.TypeString,
132+
Optional: true,
133+
Default: "20480",
134+
Description: "vSphere size of disk for docker VM (in MB)",
80135
},
81136
"folder": &schema.Schema{
82-
Type: schema.TypeString,
83-
Optional: true,
137+
Type: schema.TypeString,
138+
Optional: true,
139+
Description: "vSphere folder for the docker VM. This folder must already exist in the datacenter",
84140
},
85141
"hostsystem": &schema.Schema{
86-
Type: schema.TypeString,
87-
Optional: true,
142+
Type: schema.TypeString,
143+
Optional: true,
144+
Description: "vSphere compute resource where the docker VM will be instantiated. This can be omitted if using a cluster with DRS",
88145
},
89146
"memory_size": &schema.Schema{
90-
Type: schema.TypeString,
91-
Optional: true,
92-
Default: "2048",
147+
Type: schema.TypeString,
148+
Optional: true,
149+
Default: "2048",
150+
Description: "vSphere size of memory for docker VM (in MB)",
93151
},
94152
"network": &schema.Schema{
95-
Type: schema.TypeList,
96-
Optional: true,
153+
Type: schema.TypeList,
154+
Optional: true,
155+
Description: "vSphere network where the virtual machine will be attached",
97156
Elem: &schema.Schema{
98157
Type: schema.TypeString,
99158
},
@@ -105,8 +164,42 @@ func vsphereConfigFields() map[string]*schema.Schema {
105164
Description: "vSphere password",
106165
},
107166
"pool": &schema.Schema{
108-
Type: schema.TypeString,
109-
Optional: true,
167+
Type: schema.TypeString,
168+
Optional: true,
169+
Description: "vSphere resource pool for docker VM",
170+
},
171+
"ssh_password": {
172+
Type: schema.TypeString,
173+
Optional: true,
174+
Sensitive: true,
175+
Default: "tcuser",
176+
Description: "If using a non-B2D image you can specify the ssh password",
177+
},
178+
"ssh_port": {
179+
Type: schema.TypeString,
180+
Optional: true,
181+
Default: "22",
182+
Description: "If using a non-B2D image you can specify the ssh port",
183+
},
184+
"ssh_user": {
185+
Type: schema.TypeString,
186+
Optional: true,
187+
Default: "docker",
188+
Description: "If using a non-B2D image you can specify the ssh user",
189+
},
190+
"ssh_user_group": {
191+
Type: schema.TypeString,
192+
Optional: true,
193+
Default: "staff",
194+
Description: "If using a non-B2D image the uploaded keys will need chown'ed, defaults to staff e.g. docker:staff",
195+
},
196+
"tags": &schema.Schema{
197+
Type: schema.TypeList,
198+
Optional: true,
199+
Description: "vSphere tags id e.g. urn:xxx",
200+
Elem: &schema.Schema{
201+
Type: schema.TypeString,
202+
},
110203
},
111204
"username": {
112205
Type: schema.TypeString,
@@ -116,23 +209,27 @@ func vsphereConfigFields() map[string]*schema.Schema {
116209
"vapp_ip_allocation_policy": &schema.Schema{
117210
Type: schema.TypeString,
118211
Optional: true,
212+
Description: "vSphere vApp IP allocation policy. Supported values are: dhcp, fixed, transient and fixedAllocated",
119213
ValidateFunc: validation.StringInSlice(vmwarevsphereConfigVappIpallocationpolicies, true),
120214
},
121215
"vapp_ip_protocol": &schema.Schema{
122216
Type: schema.TypeString,
123217
Optional: true,
218+
Description: "vSphere vApp IP protocol for this deployment. Supported values are: IPv4 and IPv6",
124219
ValidateFunc: validation.StringInSlice(vmwarevsphereConfigVappIpprotocols, true),
125220
},
126221
"vapp_property": &schema.Schema{
127-
Type: schema.TypeList,
128-
Optional: true,
222+
Type: schema.TypeList,
223+
Optional: true,
224+
Description: "vSphere vApp properties",
129225
Elem: &schema.Schema{
130226
Type: schema.TypeString,
131227
},
132228
},
133229
"vapp_transport": &schema.Schema{
134230
Type: schema.TypeString,
135231
Optional: true,
232+
Description: "vSphere OVF environment transports to use for properties. Supported values are: iso and com.vmware.guestInfo",
136233
ValidateFunc: validation.StringInSlice(vmwarevsphereConfigVappTransports, true),
137234
},
138235
"vcenter": {

rancher2/structure_node_template_vsphere.go

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,36 @@ func flattenVsphereConfig(in *vmwarevsphereConfig) []interface{} {
1414
if len(in.Cfgparam) > 0 {
1515
obj["cfgparam"] = toArrayInterface(in.Cfgparam)
1616
}
17+
if len(in.CloneFrom) > 0 {
18+
obj["clone_from"] = in.CloneFrom
19+
}
20+
if len(in.CloudConfig) > 0 {
21+
obj["cloud_config"] = in.CloudConfig
22+
}
1723
if len(in.Cloudinit) > 0 {
1824
obj["cloudinit"] = in.Cloudinit
1925
}
26+
if len(in.ContentLibrary) > 0 {
27+
obj["content_library"] = in.ContentLibrary
28+
}
2029
if len(in.CPUCount) > 0 {
2130
obj["cpu_count"] = in.CPUCount
2231
}
32+
if len(in.CreationType) > 0 {
33+
obj["creation_type"] = in.CreationType
34+
}
35+
if len(in.CustomAttributes) > 0 {
36+
obj["custom_attributes"] = toArrayInterface(in.CustomAttributes)
37+
}
2338
if len(in.Datacenter) > 0 {
24-
obj["datacenter"] = in.Datastore
39+
obj["datacenter"] = in.Datacenter
2540
}
2641
if len(in.Datastore) > 0 {
2742
obj["datastore"] = in.Datastore
2843
}
44+
if len(in.DatastoreCluster) > 0 {
45+
obj["datastore_cluster"] = in.DatastoreCluster
46+
}
2947
if len(in.DiskSize) > 0 {
3048
obj["disk_size"] = in.DiskSize
3149
}
@@ -47,6 +65,21 @@ func flattenVsphereConfig(in *vmwarevsphereConfig) []interface{} {
4765
if len(in.Pool) > 0 {
4866
obj["pool"] = in.Pool
4967
}
68+
if len(in.SshPassword) > 0 {
69+
obj["ssh_password"] = in.SshPassword
70+
}
71+
if len(in.SshPort) > 0 {
72+
obj["ssh_port"] = in.SshPort
73+
}
74+
if len(in.SshUser) > 0 {
75+
obj["ssh_user"] = in.SshUser
76+
}
77+
if len(in.SshUserGroup) > 0 {
78+
obj["ssh_user_group"] = in.SshUserGroup
79+
}
80+
if len(in.Tags) > 0 {
81+
obj["tags"] = toArrayInterface(in.Tags)
82+
}
5083
if len(in.Username) > 0 {
5184
obj["username"] = in.Username
5285
}
@@ -87,18 +120,36 @@ func expandVsphereConfig(p []interface{}) *vmwarevsphereConfig {
87120
if v, ok := in["cfgparam"].([]interface{}); ok && len(v) > 0 {
88121
obj.Cfgparam = toArrayString(v)
89122
}
123+
if v, ok := in["clone_from"].(string); ok && len(v) > 0 {
124+
obj.CloneFrom = v
125+
}
126+
if v, ok := in["cloud_config"].(string); ok && len(v) > 0 {
127+
obj.CloudConfig = v
128+
}
90129
if v, ok := in["cloudinit"].(string); ok && len(v) > 0 {
91130
obj.Cloudinit = v
92131
}
132+
if v, ok := in["content_library"].(string); ok && len(v) > 0 {
133+
obj.ContentLibrary = v
134+
}
93135
if v, ok := in["cpu_count"].(string); ok && len(v) > 0 {
94136
obj.CPUCount = v
95137
}
138+
if v, ok := in["creation_type"].(string); ok && len(v) > 0 {
139+
obj.CreationType = v
140+
}
141+
if v, ok := in["custom_attributes"].([]interface{}); ok && len(v) > 0 {
142+
obj.CustomAttributes = toArrayString(v)
143+
}
96144
if v, ok := in["datacenter"].(string); ok && len(v) > 0 {
97145
obj.Datacenter = v
98146
}
99147
if v, ok := in["datastore"].(string); ok && len(v) > 0 {
100148
obj.Datastore = v
101149
}
150+
if v, ok := in["datastore_cluster"].(string); ok && len(v) > 0 {
151+
obj.DatastoreCluster = v
152+
}
102153
if v, ok := in["disk_size"].(string); ok && len(v) > 0 {
103154
obj.DiskSize = v
104155
}
@@ -120,6 +171,21 @@ func expandVsphereConfig(p []interface{}) *vmwarevsphereConfig {
120171
if v, ok := in["pool"].(string); ok && len(v) > 0 {
121172
obj.Pool = v
122173
}
174+
if v, ok := in["ssh_password"].(string); ok && len(v) > 0 {
175+
obj.SshPassword = v
176+
}
177+
if v, ok := in["ssh_port"].(string); ok && len(v) > 0 {
178+
obj.SshPort = v
179+
}
180+
if v, ok := in["ssh_user"].(string); ok && len(v) > 0 {
181+
obj.SshUser = v
182+
}
183+
if v, ok := in["ssh_user_group"].(string); ok && len(v) > 0 {
184+
obj.SshUserGroup = v
185+
}
186+
if v, ok := in["tags"].([]interface{}); ok && len(v) > 0 {
187+
obj.Tags = toArrayString(v)
188+
}
123189
if v, ok := in["username"].(string); ok && len(v) > 0 {
124190
obj.Username = v
125191
}

0 commit comments

Comments
 (0)