Skip to content

Commit 9cc9864

Browse files
feat: implement support to nutanix machine config (#2092)
Co-authored-by: Joao Ferraz <joao.ferraz@suse.com>
1 parent 1893586 commit 9cc9864

16 files changed

Lines changed: 801 additions & 10 deletions

aspell_custom.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,6 @@ json
3131
backport
3232
PDB
3333
PC
34+
AuthConfig
35+
Cognito
36+
nutanix

docs/resources/cloud_credential.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ page_title: "rancher2_cloud_credential Resource"
66

77
Provides a Rancher v2 Cloud Credential resource. This can be used to create Cloud Credential for Rancher v2.2.x and retrieve their information.
88

9-
amazonec2, azure, digitalocean, harvester, linode, openstack and vsphere credentials config are supported for Cloud Credential.
9+
amazonec2, azure, digitalocean, harvester, linode, nutanix, openstack and vsphere credentials config are supported for Cloud Credential.
1010

1111
## Example Usage
1212

@@ -51,6 +51,7 @@ The following arguments are supported:
5151
* `google_credential_config` - (Optional) Google config for the Cloud Credential (list maxitems:1)
5252
* `harvester_credential_config` - (Optional) Harvester config for the Cloud Credential (list maxitems:1)
5353
* `linode_credential_config` - (Optional) Linode config for the Cloud Credential (list maxitems:1)
54+
* `nutanix_credential_config` - (Optional) Nutanix config for the Cloud Credential (list maxitems:1)
5455
* `openstack_credential_config` - (Optional) OpenStack config for the Cloud Credential (list maxitems:1)
5556
* `s3_credential_config` - (Optional) S3 config for the Cloud Credential. For Rancher 2.6.0 and above (list maxitems:1)
5657
* `vsphere_credential_config` - (Optional) vSphere config for the Cloud Credential (list maxitems:1)
@@ -110,6 +111,15 @@ The following attributes are exported:
110111

111112
* `token` - (Required/Sensitive) Linode API token (string)
112113

114+
### `nutanix_credential_config`
115+
116+
#### Arguments
117+
118+
* `endpoint` - (Required) Nutanix management endpoint IP address/FQDN (string)
119+
* `username` - (Required) Nutanix management username (string)
120+
* `password` - (Required/Sensitive) Nutanix management password (string)
121+
* `port` - (Optional) Nutanix management endpoint port. Default `9440` (string)
122+
113123
### `openstack_credential_config`
114124

115125
#### Arguments
@@ -162,6 +172,7 @@ The following drivers are supported:
162172
* digitalocean
163173
* googlekubernetesengine
164174
* linode
175+
* nutanix
165176
* openstack
166177
* s3
167178
* vmwarevsphere

docs/resources/cluster_v2.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,53 @@ resource "rancher2_cluster_v2" "foo-k3s" {
136136
}
137137
```
138138

139+
### Create a node-driver cluster with Nutanix as the infrastructure provider
140+
141+
```hcl
142+
# Create Nutanix cloud credential
143+
resource "rancher2_cloud_credential" "foo_nutanix" {
144+
name = "foo-nutanix"
145+
nutanix_credential_config {
146+
endpoint = "<PRISM_ENDPOINT>"
147+
username = "X-ntnx-api-key"
148+
password = "<NUTANIX_API_KEY_OR_PASSWORD>"
149+
port = "9440"
150+
}
151+
}
152+
153+
# Create Nutanix machine config v2
154+
resource "rancher2_machine_config_v2" "foo_nutanix" {
155+
generate_name = "foo-nutanix"
156+
nutanix_config {
157+
cluster = "<NUTANIX_CLUSTER_NAME>"
158+
vm_network = ["<NETWORK_NAME_OR_UUID>"]
159+
vm_image = "<IMAGE_NAME>"
160+
}
161+
}
162+
163+
# Create a cluster using Nutanix machine config and cloud credential
164+
resource "rancher2_cluster_v2" "foo_nutanix" {
165+
name = "foo-nutanix"
166+
kubernetes_version = "<rke2/k3s-version>"
167+
168+
rke_config {
169+
machine_pools {
170+
name = "pool1"
171+
cloud_credential_secret_name = rancher2_cloud_credential.foo_nutanix.id
172+
control_plane_role = true
173+
etcd_role = true
174+
worker_role = true
175+
quantity = 1
176+
177+
machine_config {
178+
kind = rancher2_machine_config_v2.foo_nutanix.kind
179+
name = rancher2_machine_config_v2.foo_nutanix.name
180+
}
181+
}
182+
}
183+
}
184+
```
185+
139186
### Create a node-driver cluster with Harvester as the infrastructure provider
140187

141188
```hcl

docs/resources/machine_config_v2.md

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ page_title: "rancher2_machine_config_v2 Resource"
66

77
Provides a Rancher v2 Machine config v2 resource. This can be used to create Machine Config v2 for Rancher v2 and retrieve their information. This resource is available from Rancher v2.6.0 and above.
88

9-
The supported cloud providers includes `amazonec2`, `azure`, `digitalocean`, `harvester`, `linode`, `openstack`, and `vsphere`.
9+
The supported cloud providers includes `amazonec2`, `azure`, `digitalocean`, `harvester`, `linode`, `nutanix`, `openstack`, and `vsphere`.
1010

1111

1212
Starting with Rancher v2.12.0 and above, `google` is also offered as a supported cloud provider.
@@ -90,14 +90,15 @@ The following arguments are supported:
9090

9191
* `generate_name` - (Required/ForceNew) Cluster V2 generate name. The pattern to generate machine config name. e.g generate_name=\"prod-pool1\" will generate \"nc-prod-pool1-?????\" name computed at `name` attribute (string)
9292
* `fleet_namespace` - (Optional/ForceNew) Cluster V2 fleet namespace
93-
* `amazonec2_config` - (Optional) AWS config for the Machine Config V2. Conflicts with `azure_config`, `digitalocean_config`, `harvester_config`, `linode_config`, `openstack_config`, `google_config` and `vsphere_config` (list maxitems:1)
94-
* `azure_config` - (Optional) Azure config for the Machine Config V2. Conflicts with `amazonec2_config`, `digitalocean_config`, `harvester_config`, `linode_config`, `openstack_config`, `google_config` and `vsphere_config` (list maxitems:1)
95-
* `digitalocean_config` - (Optional) Digitalocean config for the Machine Config V2. Conflicts with `amazonec2_config`, `azure_config`, `harvester_config`, `linode_config`, `openstack_config`, `google_config` and `vsphere_config` (list maxitems:1)
96-
* `harvester_config` - (Optional) Harvester config for the Machine Config V2. Conflicts with `amazonec2_config`, `azure_config`, `digitalocean_config`, `linode_config`, `openstack_config`, `google_config` and `vsphere_config` (list maxitems:1)
97-
* `linode_config` - (Optional) Linode config for the Machine Config V2. Conflicts with `amazonec2_config`, `azure_config`, `digitalocean_config`, `harvester_config`, `openstack_config`, `google_config` and `vsphere_config` (list maxitems:1)
98-
* `openstack_config` - (Optional) Openstack config for the Machine Config V2. Conflicts with `amazonec2_config`, `azure_config`, `digitalocean_config`, `harvester_config`, `linode_config`, `google_config` and `vsphere_config` (list maxitems:1)
99-
* `vsphere_config` - (Optional) vSphere config for the Machine Config V2. Conflicts with `amazonec2_config`, `azure_config`, `digitalocean_config`, `harvester_config`, `linode_config`, `google_config` and `openstack_config` (list maxitems:1)
100-
* `google_config` - (Optional) Google config for the Machine Config V2. Conflicts with `amazonec2_config`, `azure_config`, `digitalocean_config`, `harvester_config`, `linode_config`, `openstack_config` and `vsphere_config` (list maxitems:1)
93+
* `amazonec2_config` - (Optional) AWS config for the Machine Config V2. Conflicts with `azure_config`, `digitalocean_config`, `harvester_config`, `linode_config`, `nutanix_config`, `openstack_config`, `google_config` and `vsphere_config` (list maxitems:1)
94+
* `azure_config` - (Optional) Azure config for the Machine Config V2. Conflicts with `amazonec2_config`, `digitalocean_config`, `harvester_config`, `linode_config`, `nutanix_config`, `openstack_config`, `google_config` and `vsphere_config` (list maxitems:1)
95+
* `digitalocean_config` - (Optional) Digitalocean config for the Machine Config V2. Conflicts with `amazonec2_config`, `azure_config`, `harvester_config`, `linode_config`, `nutanix_config`, `openstack_config`, `google_config` and `vsphere_config` (list maxitems:1)
96+
* `harvester_config` - (Optional) Harvester config for the Machine Config V2. Conflicts with `amazonec2_config`, `azure_config`, `digitalocean_config`, `linode_config`, `nutanix_config`, `openstack_config`, `google_config` and `vsphere_config` (list maxitems:1)
97+
* `linode_config` - (Optional) Linode config for the Machine Config V2. Conflicts with `amazonec2_config`, `azure_config`, `digitalocean_config`, `harvester_config`, `nutanix_config`, `openstack_config`, `google_config` and `vsphere_config` (list maxitems:1)
98+
* `nutanix_config` - (Optional) Nutanix config for the Machine Config V2. Conflicts with `amazonec2_config`, `azure_config`, `digitalocean_config`, `harvester_config`, `linode_config`, `openstack_config`, `google_config` and `vsphere_config` (list maxitems:1)
99+
* `openstack_config` - (Optional) Openstack config for the Machine Config V2. Conflicts with `amazonec2_config`, `azure_config`, `digitalocean_config`, `harvester_config`, `linode_config`, `nutanix_config`, `google_config` and `vsphere_config` (list maxitems:1)
100+
* `vsphere_config` - (Optional) vSphere config for the Machine Config V2. Conflicts with `amazonec2_config`, `azure_config`, `digitalocean_config`, `harvester_config`, `linode_config`, `nutanix_config`, `google_config` and `openstack_config` (list maxitems:1)
101+
* `google_config` - (Optional) Google config for the Machine Config V2. Conflicts with `amazonec2_config`, `azure_config`, `digitalocean_config`, `harvester_config`, `linode_config`, `nutanix_config`, `openstack_config` and `vsphere_config` (list maxitems:1)
101102
* `annotations` - (Optional) Annotations for Machine Config V2 object (map)
102103
* `labels` - (Optional/Computed) Labels for Machine Config V2 object (map)
103104

@@ -364,6 +365,33 @@ The following attributes are exported:
364365
* `username` - (Optional) The username to be set when logging into the virtual machines (string)
365366
* `zone` - (Required) The region and zone to create virtual machines within (e.g. us-east1-b) (string)
366367

368+
### `nutanix_config`
369+
370+
#### Arguments
371+
372+
* `endpoint` - (Optional) Nutanix management endpoint IP address/FQDN. Mandatory if `rancher2_cloud_credential.nutanix_credential_config` is not used (string)
373+
* `username` - (Optional) Nutanix management username. Use `X-ntnx-api-key` when using Prism Central service accounts. Mandatory if `rancher2_cloud_credential.nutanix_credential_config` is not used (string)
374+
* `password` - (Optional/Sensitive) Nutanix management password or API key for service account mode. Mandatory if `rancher2_cloud_credential.nutanix_credential_config` is not used (string)
375+
* `cluster` - (Required) Nutanix cluster where the VM is deployed (string)
376+
* `vm_network` - (Required) Network names or UUIDs to attach to the VM (list)
377+
* `vm_image` - (Required) Name of the VM disk image/template to clone from (string)
378+
* `port` - (Optional) Nutanix management endpoint port. Default `9440` (string)
379+
* `insecure` - (Optional) Allow insecure SSL requests. Default `false` (bool)
380+
* `vm_mem` - (Optional) Memory in MB of the VM to be created. Default `2048` (string)
381+
* `vm_cpus` - (Optional) Number of VCPUs of the VM to be created. Default `2` (string)
382+
* `vm_cores` - (Optional) Number of cores per VCPU of the VM to be created. Default `1` (string)
383+
* `vm_cpu_passthrough` - (Optional) Enable passthrough of host CPU features to the VM. Default `false` (bool)
384+
* `vm_image_size` - (Optional) Increase the size of the template image in GiB. Default `0` (string)
385+
* `vm_categories` - (Optional) Categories to apply to the VM (list)
386+
* `storage_container` - (Optional) UUID of the storage container for additional disk (string)
387+
* `disk_size` - (Optional) Size of the additional disk in GiB. Default `0` (string)
388+
* `cloud_init` - (Optional) Cloud-init configuration (string)
389+
* `vm_serial_port` - (Optional) Attach a serial port to the VM. Default `false` (bool)
390+
* `project` - (Optional) Name of the project to assign the VM (string)
391+
* `boot_type` - (Optional) Boot type of the VM. Supported values are `legacy` and `uefi`. Default `legacy` (string)
392+
* `timeout` - (Optional) Timeout for Nutanix operations in seconds. Default `300` (string)
393+
* `vm_gpu` - (Optional) GPU devices to attach to the VM (list)
394+
367395
## Timeouts
368396

369397
`rancher2_machine_config_v2` provides the following

rancher2/resource_rancher2_cloud_credential.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const (
1717
digitaloceanConfigDriver = "digitalocean"
1818
harvesterConfigDriver = "harvester"
1919
linodeConfigDriver = "linode"
20+
nutanixConfigDriver = "nutanix"
2021
openstackConfigDriver = "openstack"
2122
vmwarevsphereConfigDriver = "vmwarevsphere"
2223
)
@@ -140,6 +141,8 @@ func resourceRancher2CloudCredentialUpdate(d *schema.ResourceData, meta interfac
140141
update["harvestercredentialConfig"] = expandCloudCredentialHarvester(d.Get("harvester_credential_config").([]interface{}))
141142
case linodeConfigDriver:
142143
update["linodecredentialConfig"] = expandCloudCredentialLinode(d.Get("linode_credential_config").([]interface{}))
144+
case nutanixConfigDriver:
145+
update["nutanixcredentialConfig"] = expandCloudCredentialNutanix(d.Get("nutanix_credential_config").([]interface{}))
143146
case openstackConfigDriver:
144147
update["openstackcredentialConfig"] = expandCloudCredentialOpenstack(d.Get("openstack_credential_config").([]interface{}))
145148
case s3ConfigDriver:

rancher2/resource_rancher2_machine_config_v2.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,13 @@ func createMachineConfigV2(c *Config, obj *MachineConfigV2) (*MachineConfigV2, e
234234
out.ID = resp.ID
235235
out.TypeMeta = resp.TypeMeta
236236
out.ObjectMeta = resp.ObjectMeta
237+
case machineConfigV2NutanixKind:
238+
resp := &MachineConfigV2Nutanix{}
239+
err = c.createObjectV2(rancher2DefaultLocalClusterID, machineConfigV2NutanixAPIType, obj.NutanixConfig, resp)
240+
out.NutanixConfig = resp
241+
out.ID = resp.ID
242+
out.TypeMeta = resp.TypeMeta
243+
out.ObjectMeta = resp.ObjectMeta
237244
default:
238245
return nil, fmt.Errorf("[ERROR] Unsupported driver on node template: %s", kind)
239246
}
@@ -349,6 +356,16 @@ func getMachineConfigV2ByID(c *Config, id, kind string) (*MachineConfigV2, error
349356
out.Type = resp.Type
350357
out.TypeMeta = resp.TypeMeta
351358
out.ObjectMeta = resp.ObjectMeta
359+
case machineConfigV2NutanixKind:
360+
resp := &MachineConfigV2Nutanix{}
361+
err = c.getObjectV2ByID(rancher2DefaultLocalClusterID, id, machineConfigV2NutanixAPIType, resp)
362+
out.NutanixConfig = resp
363+
out.ID = resp.ID
364+
out.Links = resp.Links
365+
out.Actions = resp.Actions
366+
out.Type = resp.Type
367+
out.TypeMeta = resp.TypeMeta
368+
out.ObjectMeta = resp.ObjectMeta
352369
default:
353370
return nil, fmt.Errorf("[ERROR] Unsupported driver on node template: %s", kind)
354371
}
@@ -428,6 +445,13 @@ func updateMachineConfigV2(c *Config, obj *MachineConfigV2) (*MachineConfigV2, e
428445
out.ID = resp.ID
429446
out.TypeMeta = resp.TypeMeta
430447
out.ObjectMeta = resp.ObjectMeta
448+
case machineConfigV2NutanixKind:
449+
resp := &MachineConfigV2Nutanix{}
450+
err = c.updateObjectV2(rancher2DefaultLocalClusterID, obj.ID, machineConfigV2NutanixAPIType, obj.NutanixConfig, resp)
451+
out.NutanixConfig = resp
452+
out.ID = resp.ID
453+
out.TypeMeta = resp.TypeMeta
454+
out.ObjectMeta = resp.ObjectMeta
431455
default:
432456
return nil, fmt.Errorf("[ERROR] Unsupported driver on node template: %s", kind)
433457
}

rancher2/schema_cloud_credential.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ type CloudCredential struct {
1515
GoogleCredentialConfig *googleCredentialConfig `json:"googlecredentialConfig,omitempty" yaml:"googlecredentialConfig,omitempty"`
1616
HarvesterCredentialConfig *harvesterCredentialConfig `json:"harvestercredentialConfig,omitempty" yaml:"harvestercredentialConfig,omitempty"`
1717
LinodeCredentialConfig *linodeCredentialConfig `json:"linodecredentialConfig,omitempty" yaml:"linodecredentialConfig,omitempty"`
18+
NutanixCredentialConfig *nutanixCredentialConfig `json:"nutanixcredentialConfig,omitempty" yaml:"nutanixcredentialConfig,omitempty"`
1819
OpenstackCredentialConfig *openstackCredentialConfig `json:"openstackcredentialConfig,omitempty" yaml:"openstackcredentialConfig,omitempty"`
1920
VmwarevsphereCredentialConfig *vmwarevsphereCredentialConfig `json:"vmwarevspherecredentialConfig,omitempty" yaml:"vmwarevspherecredentialConfig,omitempty"`
2021
}
@@ -26,6 +27,7 @@ var allCloudCredentialDriverConfigFields = []string{
2627
"google_credential_config",
2728
"harvester_credential_config",
2829
"linode_credential_config",
30+
"nutanix_credential_config",
2931
"openstack_credential_config",
3032
"s3_credential_config",
3133
"vsphere_credential_config"}
@@ -100,6 +102,15 @@ func cloudCredentialFields() map[string]*schema.Schema {
100102
Schema: cloudCredentialLinodeFields(),
101103
},
102104
},
105+
"nutanix_credential_config": {
106+
Type: schema.TypeList,
107+
MaxItems: 1,
108+
Optional: true,
109+
ConflictsWith: getConflicts(allCloudCredentialDriverConfigFields, "nutanix_credential_config"),
110+
Elem: &schema.Resource{
111+
Schema: cloudCredentialNutanixFields(),
112+
},
113+
},
103114
"openstack_credential_config": {
104115
Type: schema.TypeList,
105116
MaxItems: 1,
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package rancher2
2+
3+
import "github.com/hashicorp/terraform-plugin-sdk/helper/schema"
4+
5+
// Types
6+
7+
type nutanixCredentialConfig struct {
8+
Endpoint string `json:"endpoint,omitempty" yaml:"endpoint,omitempty"`
9+
Username string `json:"username,omitempty" yaml:"username,omitempty"`
10+
Password string `json:"password,omitempty" yaml:"password,omitempty"`
11+
Port string `json:"port,omitempty" yaml:"port,omitempty"`
12+
}
13+
14+
// Schemas
15+
16+
func cloudCredentialNutanixFields() map[string]*schema.Schema {
17+
s := map[string]*schema.Schema{
18+
"endpoint": {
19+
Type: schema.TypeString,
20+
Required: true,
21+
Description: "Nutanix management endpoint IP address/FQDN",
22+
},
23+
"username": {
24+
Type: schema.TypeString,
25+
Required: true,
26+
Description: "Nutanix management username",
27+
},
28+
"password": {
29+
Type: schema.TypeString,
30+
Required: true,
31+
Sensitive: true,
32+
Description: "Nutanix management password",
33+
},
34+
"port": {
35+
Type: schema.TypeString,
36+
Optional: true,
37+
Default: "9440",
38+
Description: "Nutanix management endpoint port",
39+
},
40+
}
41+
42+
return s
43+
}

rancher2/schema_machine_config_v2.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ var allMachineDriverConfigFields = []string{
1313
"openstack_config",
1414
"vsphere_config",
1515
"google_config",
16+
"nutanix_config",
1617
}
1718

1819
// Schemas
@@ -111,6 +112,15 @@ func machineConfigV2Fields() map[string]*schema.Schema {
111112
Schema: machineConfigV2GoogleGCEFields(),
112113
},
113114
},
115+
"nutanix_config": {
116+
Type: schema.TypeList,
117+
MaxItems: 1,
118+
Optional: true,
119+
ConflictsWith: getConflicts(allMachineDriverConfigFields, "nutanix_config"),
120+
Elem: &schema.Resource{
121+
Schema: machineConfigV2NutanixFields(),
122+
},
123+
},
114124
"resource_version": {
115125
Type: schema.TypeString,
116126
Computed: true,

0 commit comments

Comments
 (0)