Skip to content

Commit c93d9be

Browse files
committed
support multiple networks for control node
1 parent 6569a37 commit c93d9be

File tree

7 files changed

+64
-44
lines changed

7 files changed

+64
-44
lines changed

environments/.stackhpc/tofu/LEAFCLOUD.tfvars

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1-
cluster_net = "slurmapp-ci"
2-
cluster_subnet = "slurmapp-ci"
1+
cluster_networks = [
2+
{
3+
network = "slurmapp-ci"
4+
subnet = "slurmapp-ci"
5+
}
6+
]
37
control_node_flavor = "ec1.medium" # small ran out of memory, medium gets down to ~100Mi mem free on deployment
48
other_node_flavor = "en1.xsmall"
59
state_volume_type = "unencrypted"

environments/.stackhpc/tofu/main.tf

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,10 @@ variable "cluster_image" {
3030
type = map(string)
3131
}
3232

33-
variable "cluster_net" {}
33+
variable "cluster_networks" {}
3434

35-
variable "cluster_subnet" {}
36-
37-
variable "vnic_type" {
38-
default = "normal"
35+
variable "vnic_types" {
36+
default = {}
3937
}
4038

4139
variable "state_volume_type"{
@@ -63,9 +61,8 @@ module "cluster" {
6361
source = "../../skeleton/{{cookiecutter.environment}}/tofu/"
6462

6563
cluster_name = var.cluster_name
66-
cluster_net = var.cluster_net
67-
cluster_subnet = var.cluster_subnet
68-
vnic_type = var.vnic_type
64+
cluster_networks = var.cluster_networks
65+
vnic_types = var.vnic_types
6966
key_pair = "slurm-app-ci"
7067
cluster_image_id = data.openstack_images_image_v2.cluster.id
7168
control_node_flavor = var.control_node_flavor

environments/skeleton/{{cookiecutter.environment}}/tofu/compute.tf

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ module "compute" {
99

1010
cluster_name = var.cluster_name
1111
cluster_domain_suffix = var.cluster_domain_suffix
12-
cluster_net_id = data.openstack_networking_network_v2.cluster_net.id
13-
cluster_subnet_id = data.openstack_networking_subnet_v2.cluster_subnet.id
12+
cluster_net_id = data.openstack_networking_network_v2.cluster_net[var.cluster_networks[0].network].id
13+
cluster_subnet_id = data.openstack_networking_subnet_v2.cluster_subnet[var.cluster_networks[0].network].id
1414

1515
# can be set for group, defaults to top-level value:
1616
image_id = lookup(each.value, "image_id", var.cluster_image_id)
17-
vnic_type = lookup(each.value, "vnic_type", var.vnic_type)
18-
vnic_profile = lookup(each.value, "vnic_profile", var.vnic_profile)
17+
#vnic_type = lookup(each.value, "vnic_type", var.vnic_type)
18+
#vnic_profile = lookup(each.value, "vnic_profile", var.vnic_profile)
1919
volume_backed_instances = lookup(each.value, "volume_backed_instances", var.volume_backed_instances)
2020
root_volume_size = lookup(each.value, "root_volume_size", var.root_volume_size)
2121
extra_volumes = lookup(each.value, "extra_volumes", {})

environments/skeleton/{{cookiecutter.environment}}/tofu/control.tf

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,21 @@ locals {
44

55
resource "openstack_networking_port_v2" "control" {
66

7-
name = "${var.cluster_name}-control"
8-
network_id = data.openstack_networking_network_v2.cluster_net.id
7+
for_each = {for net in var.cluster_networks: net.network => net}
8+
9+
name = "${var.cluster_name}-control-${each.key}"
10+
network_id = data.openstack_networking_network_v2.cluster_net[each.key].id
911
admin_state_up = "true"
1012

1113
fixed_ip {
12-
subnet_id = data.openstack_networking_subnet_v2.cluster_subnet.id
14+
subnet_id = data.openstack_networking_subnet_v2.cluster_subnet[each.key].id
1315
}
1416

1517
security_group_ids = [for o in data.openstack_networking_secgroup_v2.nonlogin: o.id]
1618

1719
binding {
18-
vnic_type = var.vnic_type
19-
profile = var.vnic_profile
20+
vnic_type = lookup(var.vnic_types, each.key, "normal")
21+
profile = lookup(var.vnic_profiles, each.key, "{}")
2022
}
2123
}
2224

@@ -49,9 +51,12 @@ resource "openstack_compute_instance_v2" "control" {
4951
}
5052
}
5153

52-
network {
53-
port = openstack_networking_port_v2.control.id
54-
access_network = true
54+
dynamic "network" {
55+
for_each = {for net in var.cluster_networks: net.network => net}
56+
content {
57+
port = openstack_networking_port_v2.control[network.key].id
58+
access_network = length(var.cluster_networks) == 1 ? true : lookup(each.value, "access_network", false)
59+
}
5560
}
5661

5762
metadata = {

environments/skeleton/{{cookiecutter.environment}}/tofu/login.tf

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ module "login" {
99

1010
cluster_name = var.cluster_name
1111
cluster_domain_suffix = var.cluster_domain_suffix
12-
cluster_net_id = data.openstack_networking_network_v2.cluster_net.id
13-
cluster_subnet_id = data.openstack_networking_subnet_v2.cluster_subnet.id
12+
cluster_net_id = data.openstack_networking_network_v2.cluster_net[var.cluster_networks[0].network].id
13+
cluster_subnet_id = data.openstack_networking_subnet_v2.cluster_subnet[var.cluster_networks[0].network].id
1414

1515
# can be set for group, defaults to top-level value:
1616
image_id = lookup(each.value, "image_id", var.cluster_image_id)
17-
vnic_type = lookup(each.value, "vnic_type", var.vnic_type)
18-
vnic_profile = lookup(each.value, "vnic_profile", var.vnic_profile)
17+
#vnic_type = lookup(each.value, "vnic_type", var.vnic_type)
18+
#vnic_profile = lookup(each.value, "vnic_profile", var.vnic_profile)
1919
volume_backed_instances = lookup(each.value, "volume_backed_instances", var.volume_backed_instances)
2020
root_volume_size = lookup(each.value, "root_volume_size", var.root_volume_size)
2121
extra_volumes = lookup(each.value, "extra_volumes", {})

environments/skeleton/{{cookiecutter.environment}}/tofu/network.tf

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11

22
data "openstack_networking_network_v2" "cluster_net" {
3-
name = var.cluster_net
3+
4+
for_each = {for net in var.cluster_networks: net.network => net}
5+
6+
name = each.value.network
47
}
58

69
data "openstack_networking_subnet_v2" "cluster_subnet" {
710

8-
name = var.cluster_subnet
11+
for_each = {for net in var.cluster_networks: net.network => net}
12+
13+
name = each.value.subnet
914
}
1015

1116
data "openstack_networking_secgroup_v2" "login" {

environments/skeleton/{{cookiecutter.environment}}/tofu/variables.tf

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,16 @@ variable "cluster_domain_suffix" {
99
default = "internal"
1010
}
1111

12-
variable "cluster_net" {
13-
type = string
14-
description = "Name of existing cluster network"
15-
}
16-
17-
variable "cluster_subnet" {
18-
type = string
19-
description = "Name of existing cluster subnet"
12+
variable "cluster_networks" {
13+
type = list(map(string))
14+
description = <<-EOT
15+
List of mappings defining networks. Mapping key/values:
16+
network: Name of existing network
17+
subnet: Name of existing subnet
18+
access_network: Bool defining whether to use network for Ansible and
19+
K3s. This network must be present on all nodes.
20+
Defaults to true if only one network is specified.
21+
EOT
2022
}
2123

2224
variable "key_pair" {
@@ -124,16 +126,23 @@ variable "home_volume_type" {
124126
description = "Type of home volume, if not default type"
125127
}
126128

127-
variable "vnic_type" {
128-
type = string
129-
description = "Default VNIC type, see https://registry.terraform.io/providers/terraform-provider-openstack/openstack/latest/docs/resources/networking_port_v2#vnic_type"
130-
default = "normal"
129+
variable "vnic_types" {
130+
type = map(string)
131+
description = <<-EOT
132+
Default VNIC types, keyed by network name. See https://registry.terraform.io/providers/terraform-provider-openstack/openstack/latest/docs/resources/networking_port_v2#vnic_type
133+
If not given this defaults to the "normal" type.
134+
EOT
135+
default = {}
131136
}
132137

133-
variable "vnic_profile" {
134-
type = string
135-
description = "Default VNIC binding profile as json string, see https://registry.terraform.io/providers/terraform-provider-openstack/openstack/latest/docs/resources/networking_port_v2#profile."
136-
default = "{}"
138+
variable "vnic_profiles" {
139+
type = map(string)
140+
description = <<-EOT
141+
Default VNIC binding profiles, keyed by network name. Values are json strings.
142+
See https://registry.terraform.io/providers/terraform-provider-openstack/openstack/latest/docs/resources/networking_port_v2#profile.
143+
If not given this defaults to "{}"
144+
EOT
145+
default = {}
137146
}
138147

139148
variable "login_security_groups" {

0 commit comments

Comments
 (0)