Skip to content

Commit f71dcdb

Browse files
committed
add cluster_nodename_template and compute/login.nodename_template
1 parent 6bf1dbb commit f71dcdb

File tree

7 files changed

+30
-8
lines changed

7 files changed

+30
-8
lines changed

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

+2-1
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

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ resource "openstack_networking_port_v2" "control" {
2424

2525
resource "openstack_compute_instance_v2" "control" {
2626

27-
name = "${var.cluster_name}-control"
27+
name = split(".", templatestring(var.cluster_nodename_template, {node="control", cluster_name=var.cluster_name,cluster_domain_suffix=var.cluster_domain_suffix}))[0]
2828
image_id = var.cluster_image_id
2929
flavor_name = var.control_node_flavor
3030
key_pair = var.key_pair
@@ -65,7 +65,7 @@ resource "openstack_compute_instance_v2" "control" {
6565

6666
user_data = <<-EOF
6767
#cloud-config
68-
fqdn: ${var.cluster_name}-control.${var.cluster_name}.${var.cluster_domain_suffix}
68+
fqdn: ${templatestring(var.cluster_nodename_template, {node="control", cluster_name=var.cluster_name,cluster_domain_suffix=var.cluster_domain_suffix})}
6969
7070
bootcmd:
7171
%{for volume in local.control_volumes}

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

+1
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

+1-1
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

+4-4
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ resource "openstack_compute_instance_v2" "compute_fixed_image" {
5757

5858
for_each = var.ignore_image_changes ? toset(var.nodes) : []
5959

60-
name = "${var.cluster_name}-${each.key}"
60+
name = split(".", templatestring(var.nodename_template, {node=each.key, cluster_name=var.cluster_name,cluster_domain_suffix=var.cluster_domain_suffix}))[0]
6161
image_id = var.image_id
6262
flavor_name = var.flavor
6363
key_pair = var.key_pair
@@ -94,7 +94,7 @@ resource "openstack_compute_instance_v2" "compute_fixed_image" {
9494

9595
user_data = <<-EOF
9696
#cloud-config
97-
fqdn: ${var.cluster_name}-${each.key}.${var.cluster_name}.${var.cluster_domain_suffix}
97+
fqdn: ${templatestring(var.nodename_template, {node=each.key, cluster_name=var.cluster_name,cluster_domain_suffix=var.cluster_domain_suffix})}
9898
EOF
9999

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

112112
for_each = var.ignore_image_changes ? [] : toset(var.nodes)
113113

114-
name = "${var.cluster_name}-${each.key}"
114+
name = split(".", templatestring(var.nodename_template, {node=each.key, cluster_name=var.cluster_name,cluster_domain_suffix=var.cluster_domain_suffix}))[0]
115115
image_id = var.image_id
116116
flavor_name = var.flavor
117117
key_pair = var.key_pair
@@ -148,7 +148,7 @@ resource "openstack_compute_instance_v2" "compute" {
148148

149149
user_data = <<-EOF
150150
#cloud-config
151-
fqdn: ${var.cluster_name}-${each.key}.${var.cluster_name}.${var.cluster_domain_suffix}
151+
fqdn: ${templatestring(var.nodename_template, {node=each.key, cluster_name=var.cluster_name,cluster_domain_suffix=var.cluster_domain_suffix})}
152152
EOF
153153

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

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

+5
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

+15
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,16 @@ variable "gateway_ip" {
179181
type = string
180182
default = ""
181183
}
184+
185+
variable "cluster_nodename_template" {
186+
description = <<-EOT
187+
Template for node names. The following interpolations can be used
188+
$${cluster_name}: From var.cluster_name
189+
$${cluster_domain_suffix}: From var.cluster_domain_suffix
190+
$${node}: The current entry in the "nodes" parameter for nodes
191+
defined by var.compute and var.login, or "control" for the control
192+
node.
193+
EOT
194+
type = string
195+
default = "$${cluster_name}-$${node}.$${cluster_name}.$${cluster_domain_suffix}"
196+
}

0 commit comments

Comments
 (0)