Skip to content

Commit 611513c

Browse files
authored
Allow modifying nodes fully-qualified name (#651)
* add cluster_nodename_template and compute/login.nodename_template * refactor nodename templating for DRY * add environment_name to nodename template * bump opentofu version in CI
1 parent 6c8bf78 commit 611513c

File tree

8 files changed

+56
-10
lines changed

8 files changed

+56
-10
lines changed

.github/workflows/stackhpc.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,9 @@ jobs:
9191
run: dev/setup-env.sh
9292

9393
- name: Install OpenTofu
94-
uses: opentofu/setup-opentofu@v1
94+
uses: opentofu/setup-opentofu@v1.0.5
9595
with:
96-
tofu_version: 1.6.2
96+
tofu_version: 1.9.0
9797

9898
- name: Initialise tofu
9999
run: tofu init

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ module "compute" {
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
gateway_ip = lookup(each.value, "gateway_ip", var.gateway_ip)
22-
22+
nodename_template = lookup(each.value, "nodename_template", var.cluster_nodename_template)
23+
2324
# optionally set for group:
2425
networks = concat(var.cluster_networks, lookup(each.value, "extra_networks", []))
2526
extra_volumes = lookup(each.value, "extra_volumes", {})

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
locals {
22
control_volumes = concat([openstack_blockstorage_volume_v3.state], var.home_volume_size > 0 ? [openstack_blockstorage_volume_v3.home][0] : [])
3+
nodename = templatestring(
4+
var.cluster_nodename_template,
5+
{
6+
node = "control",
7+
cluster_name = var.cluster_name,
8+
cluster_domain_suffix = var.cluster_domain_suffix,
9+
environment_name = basename(var.environment_root)
10+
}
11+
)
312
}
413

514
resource "openstack_networking_port_v2" "control" {
@@ -24,7 +33,7 @@ resource "openstack_networking_port_v2" "control" {
2433

2534
resource "openstack_compute_instance_v2" "control" {
2635

27-
name = "${var.cluster_name}-control"
36+
name = split(".", local.nodename)[0]
2837
image_id = var.cluster_image_id
2938
flavor_name = var.control_node_flavor
3039
key_pair = var.key_pair
@@ -65,7 +74,7 @@ resource "openstack_compute_instance_v2" "control" {
6574

6675
user_data = <<-EOF
6776
#cloud-config
68-
fqdn: ${var.cluster_name}-control.${var.cluster_name}.${var.cluster_domain_suffix}
77+
fqdn: ${local.nodename}
6978
7079
bootcmd:
7180
%{for volume in local.control_volumes}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ module "login" {
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
gateway_ip = lookup(each.value, "gateway_ip", var.gateway_ip)
22+
nodename_template = lookup(each.value, "nodename_template", var.cluster_nodename_template)
2223

2324
# optionally set for group
2425
networks = concat(var.cluster_networks, lookup(each.value, "extra_networks", []))

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
terraform {
2-
required_version = ">= 0.14"
2+
required_version = ">= 1.7" # templatestring() function
33
required_providers {
44
openstack = {
55
source = "terraform-provider-openstack/openstack"

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

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,19 @@ locals {
1212

1313
# Workaround for lifecycle meta-argument only taking static values
1414
compute_instances = var.ignore_image_changes ? openstack_compute_instance_v2.compute_fixed_image : openstack_compute_instance_v2.compute
15+
16+
# Define nodenames here to avoid repetition
17+
nodenames = {
18+
for n in var.nodes: n => templatestring(
19+
var.nodename_template,
20+
{
21+
node = n,
22+
cluster_name = var.cluster_name,
23+
cluster_domain_suffix = var.cluster_domain_suffix,
24+
environment_name = basename(var.environment_root)
25+
}
26+
)
27+
}
1528
}
1629

1730
resource "openstack_blockstorage_volume_v3" "compute" {
@@ -57,7 +70,7 @@ resource "openstack_compute_instance_v2" "compute_fixed_image" {
5770

5871
for_each = var.ignore_image_changes ? toset(var.nodes) : []
5972

60-
name = "${var.cluster_name}-${each.key}"
73+
name = split(".", local.nodenames[each.key])[0]
6174
image_id = var.image_id
6275
flavor_name = var.flavor
6376
key_pair = var.key_pair
@@ -94,7 +107,7 @@ resource "openstack_compute_instance_v2" "compute_fixed_image" {
94107

95108
user_data = <<-EOF
96109
#cloud-config
97-
fqdn: ${var.cluster_name}-${each.key}.${var.cluster_name}.${var.cluster_domain_suffix}
110+
fqdn: ${local.nodenames[each.key]}
98111
EOF
99112

100113
availability_zone = var.match_ironic_node ? "${var.availability_zone}::${var.baremetal_nodes[each.key]}" : null
@@ -111,7 +124,7 @@ resource "openstack_compute_instance_v2" "compute" {
111124

112125
for_each = var.ignore_image_changes ? [] : toset(var.nodes)
113126

114-
name = "${var.cluster_name}-${each.key}"
127+
name = split(".", local.nodenames[each.key])[0]
115128
image_id = var.image_id
116129
flavor_name = var.flavor
117130
key_pair = var.key_pair
@@ -148,7 +161,7 @@ resource "openstack_compute_instance_v2" "compute" {
148161

149162
user_data = <<-EOF
150163
#cloud-config
151-
fqdn: ${var.cluster_name}-${each.key}.${var.cluster_name}.${var.cluster_domain_suffix}
164+
fqdn: ${local.nodenames[each.key]}
152165
EOF
153166

154167
availability_zone = var.match_ironic_node ? "${var.availability_zone}::${var.baremetal_nodes[each.key]}" : null

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,3 +127,8 @@ variable "gateway_ip" {
127127
type = string
128128
default = ""
129129
}
130+
131+
variable "nodename_template" {
132+
type = string
133+
default = ""
134+
}

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ variable "login" {
6161
match_ironic_node: Set true to launch instances on the Ironic node of the same name as each cluster node
6262
availability_zone: Name of availability zone - ignored unless match_ironic_node is true (default: "nova")
6363
gateway_ip: Address to add default route via
64+
nodename_template: Overrides variable cluster_nodename_template
6465
EOF
6566
}
6667

@@ -97,6 +98,7 @@ variable "compute" {
9798
match_ironic_node: Set true to launch instances on the Ironic node of the same name as each cluster node
9899
availability_zone: Name of availability zone - ignored unless match_ironic_node is true (default: "nova")
99100
gateway_ip: Address to add default route via
101+
nodename_template: Overrides variable cluster_nodename_template
100102
EOF
101103
}
102104

@@ -179,3 +181,18 @@ variable "gateway_ip" {
179181
type = string
180182
default = ""
181183
}
184+
185+
variable "cluster_nodename_template" {
186+
description = <<-EOT
187+
Template for node fully-qualified names. The following interpolations
188+
can be used:
189+
$${cluster_name}: From var.cluster_name
190+
$${cluster_domain_suffix}: From var.cluster_domain_suffix
191+
$${node}: The current entry in the "nodes" parameter for nodes
192+
defined by var.compute and var.login, or "control" for the control
193+
node
194+
$${environment_name}: The last element of the current environment's path
195+
EOT
196+
type = string
197+
default = "$${cluster_name}-$${node}.$${cluster_name}.$${cluster_domain_suffix}"
198+
}

0 commit comments

Comments
 (0)