diff --git a/docs/resources/cluster_maas.md b/docs/resources/cluster_maas.md index 45e097ad1..9b628f825 100644 --- a/docs/resources/cluster_maas.md +++ b/docs/resources/cluster_maas.md @@ -169,6 +169,10 @@ Required: - `domain` (String) Domain name in which the cluster to be provisioned. +Optional: + +- `enable_lxd_vm` (Boolean) Whether to enable LXD VM. Default is `false`. + ### Nested Schema for `machine_pool` @@ -179,6 +183,7 @@ Required: - `count` (Number) Number of nodes in the machine pool. - `instance_type` (Block List, Min: 1, Max: 1) (see [below for nested schema](#nestedblock--machine_pool--instance_type)) - `name` (String) Name of the machine pool. +- `network` (Block List, Min: 1, Max: 1) (see [below for nested schema](#nestedblock--machine_pool--network)) - `placement` (Block List, Min: 1, Max: 1) (see [below for nested schema](#nestedblock--machine_pool--placement)) Optional: @@ -193,6 +198,7 @@ Optional: - `node_tags` (Set of String) Node tags to dynamically place nodes in a pool by using MAAS automatic tags. Specify the tag values that you want to apply to all nodes in the node pool. - `taints` (Block List) (see [below for nested schema](#nestedblock--machine_pool--taints)) - `update_strategy` (String) Update strategy for the machine pool. Valid values are `RollingUpdateScaleOut` and `RollingUpdateScaleIn`. +- `use_lxd_vm` (Boolean) Whether to use LXD VM. Default is `false`. ### Nested Schema for `machine_pool.instance_type` @@ -203,6 +209,19 @@ Required: - `min_memory_mb` (Number) Minimum memory in MB required for the machine pool node. + +### Nested Schema for `machine_pool.network` + +Required: + +- `network_name` (String) The name of the network in which VMs are created/located. + +Optional: + +- `parent_pool_uid` (String) The UID of the parent pool which allocates IPs for this IPPool. +- `static_ip` (Boolean) Whether to use static IP. Default is `false`. + + ### Nested Schema for `machine_pool.placement` diff --git a/spectrocloud/resource_cluster_maas.go b/spectrocloud/resource_cluster_maas.go index f8bbce61b..b5e43c7f3 100644 --- a/spectrocloud/resource_cluster_maas.go +++ b/spectrocloud/resource_cluster_maas.go @@ -145,6 +145,12 @@ func resourceClusterMaas() *schema.Resource { Required: true, Description: "Domain name in which the cluster to be provisioned.", }, + "enable_lxd_vm": { + Type: schema.TypeBool, + Optional: true, + Default: false, + Description: "Whether to enable LXD VM. Default is `false`.", + }, }, }, }, @@ -268,6 +274,37 @@ func resourceClusterMaas() *schema.Resource { }, }, }, + "use_lxd_vm": { + Type: schema.TypeBool, + Optional: true, + Default: false, + Description: "Whether to use LXD VM. Default is `false`.", + }, + "network": { + Type: schema.TypeList, + Required: true, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "network_name": { + Type: schema.TypeString, + Required: true, + Description: "The name of the network in which VMs are created/located.", + }, + "parent_pool_uid": { + Type: schema.TypeString, + Optional: true, + Description: "The UID of the parent pool which allocates IPs for this IPPool.", + }, + "static_ip": { + Type: schema.TypeBool, + Optional: true, + Default: false, + Description: "Whether to use static IP. Default is `false`.", + }, + }, + }, + }, }, }, }, @@ -401,6 +438,9 @@ func flattenClusterConfigsMaas(config *models.V1MaasCloudConfig) []interface{} { if config.Spec.ClusterConfig.Domain != nil { m["domain"] = *config.Spec.ClusterConfig.Domain } + if config.Spec.ClusterConfig.EnableLxdVM { + m["enable_lxd_vm"] = true + } return []interface{}{m} } @@ -444,6 +484,16 @@ func flattenMachinePoolConfigsMaas(machinePools []*models.V1MaasMachinePoolConfi } } oi["node_tags"] = machinePool.Tags + oi["use_lxd_vm"] = machinePool.UseLxdVM + + if machinePool.Network != nil { + network := make(map[string]interface{}) + network["network_name"] = *machinePool.Network.NetworkName + network["parent_pool_uid"] = machinePool.Network.ParentPoolRef.UID + network["static_ip"] = machinePool.Network.StaticIP + oi["network"] = []interface{}{network} + } + ois[i] = oi } @@ -562,7 +612,8 @@ func toMaasCluster(c *client.V1Client, d *schema.ResourceData) (*models.V1Spectr Profiles: profiles, Policies: toPolicies(d), CloudConfig: &models.V1MaasClusterConfig{ - Domain: &DomainVal, + Domain: &DomainVal, + EnableLxdVM: d.Get("enable_lxd_vm").(bool), }, }, } @@ -625,7 +676,8 @@ func toMachinePoolMaas(machinePool interface{}) (*models.V1MaasMachinePoolConfig MinCPU: SafeInt32(InstanceType["min_cpu"].(int)), MinMemInMB: SafeInt32(InstanceType["min_memory_mb"].(int)), }, - Tags: nodePoolTags, + Tags: nodePoolTags, + UseLxdVM: m["use_lxd_vm"].(bool), }, PoolConfig: &models.V1MachinePoolConfigEntity{ AdditionalLabels: toAdditionalNodePoolLabels(m), @@ -642,6 +694,17 @@ func toMachinePoolMaas(machinePool interface{}) (*models.V1MaasMachinePoolConfig MaxSize: max, }, } + + if len(m["network"].([]interface{})) > 0 { + network := m["network"].([]interface{})[0].(map[string]interface{}) + net := &models.V1MaasNetworkConfigEntity{ + NetworkName: types.Ptr(network["network_name"].(string)), + StaticIP: network["static_ip"].(bool), + ParentPoolUID: network["parent_pool_uid"].(string), + } + mp.CloudConfig.Network = net + } + if len(m["placement"].([]interface{})) > 0 { Placement := m["placement"].([]interface{})[0].(map[string]interface{}) mp.CloudConfig.ResourcePool = types.Ptr(Placement["resource_pool"].(string)) diff --git a/spectrocloud/resource_cluster_mass_test.go b/spectrocloud/resource_cluster_mass_test.go index 654ab9a89..ad4003370 100644 --- a/spectrocloud/resource_cluster_mass_test.go +++ b/spectrocloud/resource_cluster_mass_test.go @@ -52,6 +52,7 @@ func TestFlattenMachinePoolConfigsMaas(t *testing.T) { Type: "RollingUpdateScaleOut", }, UseControlPlaneAsWorker: true, + UseLxdVM: false, } mockMachinePools = append(mockMachinePools, mp) config := &models.V1MaasClusterConfig{ @@ -77,8 +78,9 @@ func TestFlattenMachinePoolConfigsMaas(t *testing.T) { "min_cpu": 2, }, }, - "azs": []string{"zone1", "zone2"}, - "node_tags": []string{"test"}, + "azs": []string{"zone1", "zone2"}, + "node_tags": []string{"test"}, + "use_lxd_vm": false, "placement": []interface{}{ map[string]interface{}{ "resource_pool": "maas_resource_pool", @@ -121,8 +123,16 @@ func TestToMachinePoolMaas(t *testing.T) { "resource_pool": "test_resource_pool", }, }, - "azs": schema.NewSet(schema.HashString, []interface{}{"zone1", "zone2"}), - "node_tags": schema.NewSet(schema.HashString, []interface{}{"test"}), + "azs": schema.NewSet(schema.HashString, []interface{}{"zone1", "zone2"}), + "node_tags": schema.NewSet(schema.HashString, []interface{}{"test"}), + "use_lxd_vm": false, + "network": []interface{}{ + map[string]interface{}{ + "network_name": "test_network", + "parent_pool_uid": "test_pool_uid", + "static_ip": false, + }, + }, } rp := "test_resource_pool" size := int32(2) @@ -133,6 +143,12 @@ func TestToMachinePoolMaas(t *testing.T) { InstanceType: &models.V1MaasInstanceType{MinCPU: 2, MinMemInMB: 500}, ResourcePool: &rp, Tags: []string{"test"}, + UseLxdVM: false, + Network: &models.V1MaasNetworkConfigEntity{ + NetworkName: types.Ptr("test_network"), + ParentPoolUID: "test_pool_uid", + StaticIP: false, + }, }, PoolConfig: &models.V1MachinePoolConfigEntity{ AdditionalLabels: map[string]string{"TF": "test_label"},