Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 39 additions & 7 deletions docs/resources/machine_config_v2.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ Provides a Rancher v2 Machine config v2 resource. This can be used to create Mac

The supported cloud providers includes `amazonec2`, `azure`, `digitalocean`, `harvester`, `linode`, `openstack`, and `vsphere`.


Starting with Rancher v2.12.0 and above, `google` is also offered as a supported cloud provider.

## Example Usage

```hcl
Expand Down Expand Up @@ -87,13 +90,14 @@ The following arguments are supported:

* `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)
* `fleet_namespace` - (Optional/ForceNew) Cluster V2 fleet namespace
* `amazonec2_config` - (Optional) AWS config for the Machine Config V2. Conflicts with `azure_config`, `digitalocean_config`, `harvester_config`, `linode_config`, `openstack_config` and `vsphere_config` (list maxitems:1)
* `azure_config` - (Optional) Azure config for the Machine Config V2. Conflicts with `amazonec2_config`, `digitalocean_config`, `harvester_config`, `linode_config`, `openstack_config` and `vsphere_config` (list maxitems:1)
* `digitalocean_config` - (Optional) Digitalocean config for the Machine Config V2. Conflicts with `amazonec2_config`, `azure_config`, `harvester_config`, `linode_config`, `openstack_config` and `vsphere_config` (list maxitems:1)
* `harvester_config` - (Optional) Harvester config for the Machine Config V2. Conflicts with `amazonec2_config`, `azure_config`, `digitalocean_config`, `linode_config`, `openstack_config` and `vsphere_config` (list maxitems:1)
* `linode_config` - (Optional) Linode config for the Machine Config V2. Conflicts with `amazonec2_config`, `azure_config`, `digitalocean_config`, `harvester_config`, `openstack_config` and `vsphere_config` (list maxitems:1)
* `openstack_config` - (Optional) Openstack config for the Machine Config V2. Conflicts with `amazonec2_config`, `azure_config`, `digitalocean_config`, `harvester_config`, `linode_config` and `vsphere_config` (list maxitems:1)
* `vsphere_config` - (Optional) vSphere config for the Machine Config V2. Conflicts with `amazonec2_config`, `azure_config`, `digitalocean_config`, `harvester_config`, `linode_config` and `openstack_config` (list maxitems:1)
* `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)
* `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)
* `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)
* `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)
* `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)
* `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)
* `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)
* `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)
* `annotations` - (Optional) Annotations for Machine Config V2 object (map)
* `labels` - (Optional/Computed) Labels for Machine Config V2 object (map)

Expand Down Expand Up @@ -328,6 +332,34 @@ The following attributes are exported:
* `vcenter` - (Optional/Sensitive) vSphere IP/hostname for vCenter (string)
* `vcenter_port` - (Optional/Sensitive) vSphere Port for vCenter Default `443` (string)


### `google_config`

#### Arguments

* `address` - (Optional) GCE Instance External IP (string)
* `auth_encoded_json` - (Optional/Sensitive) GCE service account auth json file path. Use `rancher2_cloud_credential` from Rancher v2.2.x. (string)
* `disk_size` - (Required) GCE Instance Disk Size (in GB) (string)
* `disk_type` - (Required) GCE Instance Disk Type (string)
* `external_firewall_rule_prefix` - (Optional) A prefix to be added to firewall rules created when exposing ports publicly. Required if exposing ports publicly via the `open_port` field. (string)
* `internal_firewall_rule_prefix` - (Optional) A prefix to be added to an internal firewall rule created to ensure virtual machines can communicate with one another. Omitting this field will result in an internal firewall rule not being created. (string)
* `labels` - (Optional) A set of labels to be added to each VM, in the format of 'key1,value1,key2,value2' (string)
* `machine_image` - (Required) GCE instance image absolute URL (string)
* `machine_type` - (Required) GCE instance type (string)
* `network` - (Required) The network to provision virtual machines within (string)
* `open_port` - (Optional) A list of ports to be opened publicly (e.g. `123/tcp` or `456/udp`). The `external_firewall_rule_prefix` must also be set for ports to be exposed automatically. (list)
* `preemptable` - (Optional) Indicates if the virtual machine can be preempted (bool)
* `project` - (Required) The GCP project to create virtual machines within (string)
* `scopes` - (Optional) Access scopes to be set on the virtual machine (string)
* `sub_network` - (Optional) The subnetwork to provision virtual machines within (string)
* `tags` - (Optional) A set of network tags to be added to each VM, in the format of 'tag1,tag2' (string)
* `use_existing` - (Optional) Indicates if an existing VM should be used. This is not currently support in Rancher Node Drivers. (bool)
* `use_internal_ip` - (Optional) Indicates if the virtual machines should use an internal IP (bool)
* `use_internal_ip_only` - (Optional) Indicates if the virtual machines should use an internal IP only and not be assigned a public IP (bool)
* `user_data` - (Optional) GCE user-data file path (string)
* `username` - (Optional) The username to be set when logging into the virtual machines (string)
* `zone` - (Required) The region and zone to create virtual machines within (e.g. us-east1-b) (string)

## Timeouts

`rancher2_machine_config_v2` provides the following
Expand Down
24 changes: 24 additions & 0 deletions rancher2/resource_rancher2_machine_config_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,13 @@ func createMachineConfigV2(c *Config, obj *MachineConfigV2) (*MachineConfigV2, e
out.ID = resp.ID
out.TypeMeta = resp.TypeMeta
out.ObjectMeta = resp.ObjectMeta
case machineConfigV2GoogleGCEKind:
resp := &MachineConfigV2GoogleGCE{}
err = c.createObjectV2(rancher2DefaultLocalClusterID, machineConfigV2GoogleGCEAPIType, obj.GoogleGCEConfig, resp)
out.GoogleGCEConfig = resp
out.ID = resp.ID
out.TypeMeta = resp.TypeMeta
out.ObjectMeta = resp.ObjectMeta
default:
return nil, fmt.Errorf("[ERROR] Unsupported driver on node template: %s", kind)
}
Expand Down Expand Up @@ -332,6 +339,16 @@ func getMachineConfigV2ByID(c *Config, id, kind string) (*MachineConfigV2, error
out.Type = resp.Type
out.TypeMeta = resp.TypeMeta
out.ObjectMeta = resp.ObjectMeta
case machineConfigV2GoogleGCEKind:
resp := &MachineConfigV2GoogleGCE{}
err = c.getObjectV2ByID(rancher2DefaultLocalClusterID, id, machineConfigV2GoogleGCEAPIType, resp)
out.GoogleGCEConfig = resp
out.ID = resp.ID
out.Links = resp.Links
out.Actions = resp.Actions
out.Type = resp.Type
out.TypeMeta = resp.TypeMeta
out.ObjectMeta = resp.ObjectMeta
default:
return nil, fmt.Errorf("[ERROR] Unsupported driver on node template: %s", kind)
}
Expand Down Expand Up @@ -404,6 +421,13 @@ func updateMachineConfigV2(c *Config, obj *MachineConfigV2) (*MachineConfigV2, e
out.ID = resp.ID
out.TypeMeta = resp.TypeMeta
out.ObjectMeta = resp.ObjectMeta
case machineConfigV2GoogleGCEKind:
resp := &MachineConfigV2GoogleGCE{}
err = c.updateObjectV2(rancher2DefaultLocalClusterID, obj.ID, machineConfigV2GoogleGCEAPIType, obj.GoogleGCEConfig, resp)
out.GoogleGCEConfig = resp
out.ID = resp.ID
out.TypeMeta = resp.TypeMeta
out.ObjectMeta = resp.ObjectMeta
default:
return nil, fmt.Errorf("[ERROR] Unsupported driver on node template: %s", kind)
}
Expand Down
10 changes: 10 additions & 0 deletions rancher2/schema_machine_config_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ var allMachineDriverConfigFields = []string{
"linode_config",
"openstack_config",
"vsphere_config",
"google_config",
}

//Schemas
Expand Down Expand Up @@ -101,6 +102,15 @@ func machineConfigV2Fields() map[string]*schema.Schema {
Schema: machineConfigV2VmwarevsphereFields(),
},
},
"google_config": {
Type: schema.TypeList,
MaxItems: 1,
Optional: true,
ConflictsWith: getConflicts(allMachineDriverConfigFields, "google_config"),
Elem: &schema.Resource{
Schema: machineConfigV2GoogleGCEFields(),
},
},
"resource_version": {
Type: schema.TypeString,
Computed: true,
Expand Down
122 changes: 122 additions & 0 deletions rancher2/schema_machine_config_v2_googlegce.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
package rancher2

import "github.com/hashicorp/terraform-plugin-sdk/helper/schema"

func machineConfigV2GoogleGCEFields() map[string]*schema.Schema {
return map[string]*schema.Schema{
"address": {
Type: schema.TypeString,
Optional: true,
Description: "GCE Instance External IP",
},
"auth_encoded_json": {
Type: schema.TypeString,
Optional: true,
Sensitive: true,
Description: "GCE service account auth json file path",
},
"disk_size": {
Type: schema.TypeString,
Required: true,
Description: "GCE Instance Disk Size (in GB)",
},
"disk_type": {
Type: schema.TypeString,
Required: true,
Description: "GCE Instance Disk Type",
},
"external_firewall_rule_prefix": {
Type: schema.TypeString,
Optional: true,
Description: "A prefix to be added to firewall rules created when exposing ports publicly. Required if exposing ports publicly.",
},
"internal_firewall_rule_prefix": {
Type: schema.TypeString,
Optional: true,
Description: "A prefix to be added to an internal firewall rule created to ensure virtual machines can communicate with one another.",
},
"labels": {
Type: schema.TypeString,
Optional: true,
Description: "A set of labels to be added to each VM, in the format of 'key1,value1,key2,value2'",
},
"machine_image": {
Type: schema.TypeString,
Required: true,
Description: "GCE instance image absolute URL",
},
"machine_type": {
Type: schema.TypeString,
Required: true,
Description: "GCE instance type",
},
"network": {
Type: schema.TypeString,
Required: true,
Description: "The network to provision virtual machines within",
},
"open_port": {
Type: schema.TypeList,
Optional: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
Description: "A list of ports to be opened publicly. 'external_firewall_rule_prefix' must also be set",
},
"preemptable": {
Type: schema.TypeBool,
Optional: true,
Description: "Indicates if the virtual machine can be preempted",
},
"project": {
Type: schema.TypeString,
Required: true,
Description: "The GCP project to create virtual machines within",
},
"scopes": {
Type: schema.TypeString,
Optional: true,
Description: "Access scopes to be set on the virtual machine",
},
"sub_network": {
Type: schema.TypeString,
Optional: true,
Description: "The subnetwork to provision virtual machines within",
},
"tags": {
Type: schema.TypeString,
Optional: true,
Description: "A set of network tags to be added to each VM, in the format of 'tag1,tag2'",
},
"use_existing": {
Type: schema.TypeBool,
Optional: true,
Description: "Indicates if an existing VM should be used. This is not currently support in Rancher.",
},
"use_internal_ip": {
Type: schema.TypeBool,
Optional: true,
Description: "Indicates if the virtual machines should use an internal IP",
},
"use_internal_ip_only": {
Type: schema.TypeBool,
Optional: true,
Description: "Indicates if the virtual machines should use an internal IP only and not be assigned a public IP",
},
"user_data": {
Type: schema.TypeString,
Optional: true,
Description: "GCE user-data file path",
},
"username": {
Type: schema.TypeString,
Optional: true,
Description: "The username to be set when logging into the virtual machines",
},
"zone": {
Type: schema.TypeString,
Required: true,
Description: "The region and zone to create virtual machines within (e.g. us-east1-b)",
},
}
}
9 changes: 9 additions & 0 deletions rancher2/structure_machine_config_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ type machineConfigV2 struct {
LinodeConfig *MachineConfigV2Linode `json:"linodeConfig,omitempty" yaml:"linodeConfig,omitempty"`
OpenstackConfig *MachineConfigV2Openstack `json:"openstackConfig,omitempty" yaml:"openstackConfig,omitempty"`
VmwarevsphereConfig *MachineConfigV2Vmwarevsphere `json:"vmwarevsphereConfig,omitempty" yaml:"vmwarevsphereConfig,omitempty"`
GoogleGCEConfig *MachineConfigV2GoogleGCE `json:"googleConfig,omitempty" yaml:"googleConfig,omitempty"`
}

type MachineConfigV2 struct {
Expand Down Expand Up @@ -77,6 +78,11 @@ func flattenMachineConfigV2(d *schema.ResourceData, in *MachineConfigV2) error {
if err != nil {
return err
}
case machineConfigV2GoogleGCEKind:
err := d.Set("google_config", flattenMachineConfigV2GoogleGCE(in.GoogleGCEConfig))
if err != nil {
return err
}
default:
return fmt.Errorf("[ERROR] Unsupported driver on node template: %s", kind)
}
Expand Down Expand Up @@ -143,6 +149,9 @@ func expandMachineConfigV2(in *schema.ResourceData) *MachineConfigV2 {
if v, ok := in.Get("vsphere_config").([]interface{}); ok && len(v) > 0 {
obj.VmwarevsphereConfig = expandMachineConfigV2Vmwarevsphere(v, obj)
}
if v, ok := in.Get("google_config").([]interface{}); ok && len(v) > 0 {
obj.GoogleGCEConfig = expandMachineConfigV2GoogleGCE(v, obj)
}

return obj
}
Loading
Loading