Skip to content

Commit 1afc5ea

Browse files
committed
support ip_addresses fo all nodes
1 parent c97615f commit 1afc5ea

File tree

5 files changed

+83
-42
lines changed

5 files changed

+83
-42
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ module "compute" {
3030
ignore_image_changes = lookup(each.value, "ignore_image_changes", null)
3131
match_ironic_node = lookup(each.value, "match_ironic_node", null)
3232
availability_zone = lookup(each.value, "availability_zone", null)
33+
ip_addresses = lookup(each.value, "ip_addresses", null)
3334

3435
# computed
3536
# not using openstack_compute_instance_v2.control.access_ip_v4 to avoid
@@ -55,6 +56,7 @@ module "compute" {
5556
"extra_volumes",
5657
"match_ironic_node",
5758
"availability_zone",
59+
"ip_addresses",
5860
"gateway_ip",
5961
"nodename_template",
6062
]

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ module "login" {
3030
fip_network = lookup(each.value, "fip_network", null)
3131
match_ironic_node = lookup(each.value, "match_ironic_node", null)
3232
availability_zone = lookup(each.value, "availability_zone", null)
33+
ip_addresses = lookup(each.value, "ip_addresses", null)
3334

3435
# can't be set for login
3536
compute_init_enable = []
@@ -59,6 +60,7 @@ module "login" {
5960
"fip_network",
6061
"match_ironic_node",
6162
"availability_zone",
63+
"ip_addresses",
6264
"gateway_ip",
6365
"nodename_template",
6466
]

environments/skeleton/{{cookiecutter.environment}}/tofu/node_group/nodes.tf

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,22 +47,26 @@ resource "openstack_compute_volume_attach_v2" "compute" {
4747
resource "openstack_networking_port_v2" "compute" {
4848

4949
for_each = {for item in setproduct(var.nodes, var.networks):
50-
"${item[0]}-${item[1].network}" => item[1]
50+
"${item[0]}-${item[1].network}" => {
51+
node_idx = index(var.nodes, item[0])
52+
net = item[1]
53+
}
5154
}
5255

5356
name = "${var.cluster_name}-${each.key}"
54-
network_id = data.openstack_networking_network_v2.network[each.value.network].id
57+
network_id = data.openstack_networking_network_v2.network[each.value.net.network].id
5558
admin_state_up = "true"
5659

5760
fixed_ip {
58-
subnet_id = data.openstack_networking_subnet_v2.subnet[each.value.network].id
61+
subnet_id = data.openstack_networking_subnet_v2.subnet[each.value.net.network].id
62+
ip_address = try(var.ip_addresses[each.value.net.network][each.value.node_idx], null)
5963
}
6064

61-
no_security_groups = lookup(each.value, "no_security_groups", false)
62-
security_group_ids = lookup(each.value, "no_security_groups", false) ? [] : var.security_group_ids
65+
no_security_groups = lookup(each.value.net, "no_security_groups", false)
66+
security_group_ids = lookup(each.value.net, "no_security_groups", false) ? [] : var.security_group_ids
6367

6468
binding {
65-
vnic_type = lookup(var.vnic_types, each.value.network, "normal")
69+
vnic_type = lookup(var.vnic_types, each.value.net.network, "normal")
6670
}
6771
}
6872

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,27 @@ variable "fip_network" {
119119
nullable = false
120120
}
121121

122+
variable "ip_addresses" {
123+
type = map(list(string))
124+
description = <<-EOT
125+
Mapping of list of fixed IP addresses for nodes, keyed by network name,
126+
in same order as nodes parameter. For any networks not specified here
127+
the cloud will select addresses.
128+
129+
NB: Changing IP addresses after deployment may hit terraform provider bugs.
130+
EOT
131+
default = {}
132+
nullable = false
133+
validation {
134+
condition = length(setsubtract(keys(var.ip_addresses), var.networks[*].network)) == 0
135+
error_message = "Keys in ip_addresses for nodegroup \"${var.group_name}\" must match network names in var.cluster_networks"
136+
}
137+
validation {
138+
condition = alltrue([for v in values(var.ip_addresses): length(v) == length(var.nodes)])
139+
error_message = "Values in ip_addresses for nodegroup \"${var.group_name}\" must be a list of the same length as var.nodes"
140+
}
141+
}
142+
122143
variable "match_ironic_node" {
123144
type = bool
124145
description = "Whether to launch instances on the Ironic node of the same name as each cluster node"

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

Lines changed: 48 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,15 @@ variable "control_ip_addresses" {
2828
type = map(string)
2929
description = <<-EOT
3030
Mapping of fixed IP addresses for control node, keyed by network name.
31-
The default means the cloud will select an address.
31+
For any networks not specified here the cloud will select an address.
32+
33+
NB: Changing IP addresses after deployment may hit terraform provider bugs.
3234
EOT
3335
default = {}
3436
validation {
3537
# check all keys are network names in cluster_networks
36-
condition = length(setsubtract(keys(var.control_ip_addresses), [for n in var.cluster_networks: n.network])) == 0
37-
error_message = "keys in var.control_ip_addresses must match network names in var.cluster_networks"
38+
condition = length(setsubtract(keys(var.control_ip_addresses), var.cluster_networks[*].network)) == 0
39+
error_message = "Keys in var.control_ip_addresses must match network names in var.cluster_networks"
3840
}
3941
}
4042

@@ -44,39 +46,45 @@ variable "control_node_flavor" {
4446
}
4547

4648
variable "login" {
47-
type = any
48-
description = <<-EOF
49-
Mapping defining homogenous groups of login nodes. Multiple groups may
50-
be useful for e.g. separating nodes for ssh and Open Ondemand usage, or
51-
to define login nodes with different capabilities such as high-memory.
49+
default = {}
50+
description = <<-EOF
51+
Mapping defining homogenous groups of login nodes. Multiple groups may
52+
be useful for e.g. separating nodes for ssh and Open Ondemand usage, or
53+
to define login nodes with different capabilities such as high-memory.
5254
53-
Keys are names of groups.
54-
Values are a mapping as follows:
55+
Keys are names of groups.
56+
Values are a mapping as follows:
57+
58+
Required:
59+
nodes: List of node names
60+
flavor: String flavor name
61+
Optional:
62+
image_id: Overrides variable cluster_image_id
63+
extra_networks: List of mappings in same format as cluster_networks
64+
vnic_types: Overrides variable vnic_types
65+
volume_backed_instances: Overrides variable volume_backed_instances
66+
root_volume_size: Overrides variable root_volume_size
67+
extra_volumes: Mapping defining additional volumes to create and attach
68+
Keys are unique volume name.
69+
Values are a mapping with:
70+
size: Size of volume in GB
71+
**NB**: The order in /dev is not guaranteed to match the mapping
72+
fip_addresses: List of addresses of floating IPs to associate with
73+
nodes, in the same order as nodes parameter. The
74+
floating IPs must already be allocated to the project.
75+
fip_network: Name of network containing ports to attach FIPs to. Only
76+
required if multiple networks are defined.
77+
ip_addresses: Mapping of list of fixed IP addresses for nodes, keyed
78+
by network name, in same order as nodes parameter.
79+
For any networks not specified here the cloud will
80+
select addresses.
81+
match_ironic_node: Set true to launch instances on the Ironic node of the same name as each cluster node
82+
availability_zone: Name of availability zone - ignored unless match_ironic_node is true (default: "nova")
83+
gateway_ip: Address to add default route via
84+
nodename_template: Overrides variable cluster_nodename_template
85+
EOF
5586

56-
Required:
57-
nodes: List of node names
58-
flavor: String flavor name
59-
Optional:
60-
image_id: Overrides variable cluster_image_id
61-
extra_networks: List of mappings in same format as cluster_networks
62-
vnic_types: Overrides variable vnic_types
63-
volume_backed_instances: Overrides variable volume_backed_instances
64-
root_volume_size: Overrides variable root_volume_size
65-
extra_volumes: Mapping defining additional volumes to create and attach
66-
Keys are unique volume name.
67-
Values are a mapping with:
68-
size: Size of volume in GB
69-
**NB**: The order in /dev is not guaranteed to match the mapping
70-
fip_addresses: List of addresses of floating IPs to associate with nodes,
71-
in the same order as nodes parameter. The floating IPs
72-
must already be allocated to the project.
73-
fip_network: Name of network containing ports to attach FIPs to. Only
74-
required if multiple networks are defined.
75-
match_ironic_node: Set true to launch instances on the Ironic node of the same name as each cluster node
76-
availability_zone: Name of availability zone - ignored unless match_ironic_node is true (default: "nova")
77-
gateway_ip: Address to add default route via
78-
nodename_template: Overrides variable cluster_nodename_template
79-
EOF
87+
type = any
8088
}
8189

8290
variable "cluster_image_id" {
@@ -85,7 +93,7 @@ variable "cluster_image_id" {
8593
}
8694

8795
variable "compute" {
88-
96+
default = {}
8997
description = <<-EOF
9098
Mapping defining homogenous groups of compute nodes. Groups are used
9199
in Slurm partition definitions.
@@ -109,12 +117,16 @@ variable "compute" {
109117
Values are a mapping with:
110118
size: Size of volume in GB
111119
**NB**: The order in /dev is not guaranteed to match the mapping
120+
ip_addresses: Mapping of list of fixed IP addresses for nodes, keyed
121+
by network name, in same order as nodes parameter.
122+
For any networks not specified here the cloud will
123+
select addresses.
112124
match_ironic_node: Set true to launch instances on the Ironic node of the same name as each cluster node
113125
availability_zone: Name of availability zone - ignored unless match_ironic_node is true (default: "nova")
114126
gateway_ip: Address to add default route via
115127
nodename_template: Overrides variable cluster_nodename_template
116128
EOF
117-
default = {}
129+
118130
type = any # can't do any better; TF type constraints can't cope with heterogeneous inner mappings
119131
}
120132

0 commit comments

Comments
 (0)