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
19 changes: 19 additions & 0 deletions docs/resources/cluster_maas.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.


<a id="nestedblock--machine_pool"></a>
### Nested Schema for `machine_pool`
Expand All @@ -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:
Expand All @@ -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`.

<a id="nestedblock--machine_pool--instance_type"></a>
### Nested Schema for `machine_pool.instance_type`
Expand All @@ -203,6 +209,19 @@ Required:
- `min_memory_mb` (Number) Minimum memory in MB required for the machine pool node.


<a id="nestedblock--machine_pool--network"></a>
### 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`.


<a id="nestedblock--machine_pool--placement"></a>
### Nested Schema for `machine_pool.placement`

Expand Down
67 changes: 65 additions & 2 deletions spectrocloud/resource_cluster_maas.go
Original file line number Diff line number Diff line change
Expand Up @@ -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`.",
},
},
},
},
Expand Down Expand Up @@ -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`.",
},
},
},
},
},
},
},
Expand Down Expand Up @@ -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}
}
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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),
},
},
}
Expand Down Expand Up @@ -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),
Expand All @@ -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))
Expand Down
24 changes: 20 additions & 4 deletions spectrocloud/resource_cluster_mass_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ func TestFlattenMachinePoolConfigsMaas(t *testing.T) {
Type: "RollingUpdateScaleOut",
},
UseControlPlaneAsWorker: true,
UseLxdVM: false,
}
mockMachinePools = append(mockMachinePools, mp)
config := &models.V1MaasClusterConfig{
Expand All @@ -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",
Expand Down Expand Up @@ -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)
Expand All @@ -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"},
Expand Down