From f3013f00a07b85e2644b148faa48c0bfa4da6eac Mon Sep 17 00:00:00 2001 From: Steve Brasier Date: Thu, 7 Aug 2025 12:12:26 +0000 Subject: [PATCH 1/5] allow setting volume type for extra_volumes --- environments/site/tofu/node_group/nodes.tf | 1 + environments/site/tofu/node_group/variables.tf | 2 ++ environments/site/tofu/variables.tf | 8 +++++--- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/environments/site/tofu/node_group/nodes.tf b/environments/site/tofu/node_group/nodes.tf index f3f9ab91f..340a6c952 100644 --- a/environments/site/tofu/node_group/nodes.tf +++ b/environments/site/tofu/node_group/nodes.tf @@ -36,6 +36,7 @@ resource "openstack_blockstorage_volume_v3" "compute" { name = "${var.cluster_name}-${each.key}" description = "Compute node ${each.value.node} volume ${each.value.volume}" size = var.extra_volumes[each.value.volume].size + volume_type = var.extra_volumes[each.value.volume].volume_type } resource "openstack_compute_volume_attach_v2" "compute" { diff --git a/environments/site/tofu/node_group/variables.tf b/environments/site/tofu/node_group/variables.tf index deb174b91..110ba8115 100644 --- a/environments/site/tofu/node_group/variables.tf +++ b/environments/site/tofu/node_group/variables.tf @@ -60,11 +60,13 @@ variable "extra_volumes" { Keys are unique volume name. Values are a mapping with: size: Size of volume in GB + volume_type: Optional. Type of volume, or cloud default **NB**: The order in /dev is not guaranteed to match the mapping EOF type = map( object({ size = number + volume_type = optional(string) }) ) default = {} diff --git a/environments/site/tofu/variables.tf b/environments/site/tofu/variables.tf index a6626ab6e..a6a78bcb1 100644 --- a/environments/site/tofu/variables.tf +++ b/environments/site/tofu/variables.tf @@ -65,10 +65,11 @@ variable "login" { volume_backed_instances: Overrides variable volume_backed_instances root_volume_size: Overrides variable root_volume_size extra_volumes: Mapping defining additional volumes to create and attach - Keys are unique volume name. - Values are a mapping with: + Keys are unique volume name. + Values are a mapping with: size: Size of volume in GB - **NB**: The order in /dev is not guaranteed to match the mapping + volume_type: Optional. Type of volume, or cloud default + **NB**: The order in /dev is not guaranteed to match the mapping fip_addresses: List of addresses of floating IPs to associate with nodes, in the same order as nodes parameter. The floating IPs must already be allocated to the project. @@ -117,6 +118,7 @@ variable "compute" { Keys are unique volume name. Values are a mapping with: size: Size of volume in GB + volume_type: Optional. Type of volume, or cloud default **NB**: The order in /dev is not guaranteed to match the mapping ip_addresses: Mapping of list of fixed IP addresses for nodes, keyed by network name, in same order as nodes parameter. From f095b502263d953a5f2faea22cc5ae126dc891b0 Mon Sep 17 00:00:00 2001 From: wtripp180901 Date: Thu, 7 Aug 2025 15:13:33 +0100 Subject: [PATCH 2/5] Added config drive option to tofu --- environments/site/tofu/compute.tf | 3 +++ environments/site/tofu/control.tf | 2 ++ environments/site/tofu/login.tf | 3 +++ environments/site/tofu/node_group/nodes.tf | 4 ++++ environments/site/tofu/node_group/variables.tf | 9 +++++++++ environments/site/tofu/variables.tf | 9 +++++++++ 6 files changed, 30 insertions(+) diff --git a/environments/site/tofu/compute.tf b/environments/site/tofu/compute.tf index 4e6186e35..d73c8ee12 100644 --- a/environments/site/tofu/compute.tf +++ b/environments/site/tofu/compute.tf @@ -60,4 +60,7 @@ module "compute" { "gateway_ip", "nodename_template", ] + + config_drive = var.config_drive + } diff --git a/environments/site/tofu/control.tf b/environments/site/tofu/control.tf index 2c7174452..811e781b7 100644 --- a/environments/site/tofu/control.tf +++ b/environments/site/tofu/control.tf @@ -94,4 +94,6 @@ resource "openstack_compute_instance_v2" "control" { %{endif} EOF + config_drive = var.config_drive + } diff --git a/environments/site/tofu/login.tf b/environments/site/tofu/login.tf index b8abe4ea3..b3aa382e8 100644 --- a/environments/site/tofu/login.tf +++ b/environments/site/tofu/login.tf @@ -64,4 +64,7 @@ module "login" { "gateway_ip", "nodename_template", ] + + config_drive = var.config_drive + } diff --git a/environments/site/tofu/node_group/nodes.tf b/environments/site/tofu/node_group/nodes.tf index 340a6c952..062d979c9 100644 --- a/environments/site/tofu/node_group/nodes.tf +++ b/environments/site/tofu/node_group/nodes.tf @@ -120,6 +120,8 @@ resource "openstack_compute_instance_v2" "compute_fixed_image" { availability_zone = var.match_ironic_node ? "${local.baremetal_az}::${var.baremetal_nodes[each.key]}" : var.availability_zone + config_drive = var.config_drive + lifecycle { ignore_changes = [ image_id, @@ -175,6 +177,8 @@ resource "openstack_compute_instance_v2" "compute" { availability_zone = var.match_ironic_node ? "${local.baremetal_az}::${var.baremetal_nodes[each.key]}" : var.availability_zone + config_drive = var.config_drive + } resource "openstack_networking_floatingip_associate_v2" "fip" { diff --git a/environments/site/tofu/node_group/variables.tf b/environments/site/tofu/node_group/variables.tf index 110ba8115..8ce104e8f 100644 --- a/environments/site/tofu/node_group/variables.tf +++ b/environments/site/tofu/node_group/variables.tf @@ -192,3 +192,12 @@ variable "allowed_keys" { type = list # don't provide a default here as allowed keys may depend on module use } + +variable "config_drive" { + description = <<-EOT + Whether to enable Nova config drives on all nodes, which will mount a drive containing + information that would usually be available through the metadata service. + EOT + type = bool + default = false +} diff --git a/environments/site/tofu/variables.tf b/environments/site/tofu/variables.tf index a6a78bcb1..09698e585 100644 --- a/environments/site/tofu/variables.tf +++ b/environments/site/tofu/variables.tf @@ -313,3 +313,12 @@ variable "cluster_nodename_template" { type = string default = "$${cluster_name}-$${node}.$${cluster_name}.$${cluster_domain_suffix}" } + +variable "config_drive" { + description = <<-EOT + Whether to enable Nova config drives on all nodes, which will mount a drive containing + information that would usually be available through the metadata service. + EOT + type = bool + default = false +} From b46a565036a7fb34cfb3c302c41129b82783b7ec Mon Sep 17 00:00:00 2001 From: wtripp180901 Date: Fri, 8 Aug 2025 16:39:11 +0100 Subject: [PATCH 3/5] add option for additional user data --- environments/site/tofu/additional.tf | 4 ++++ environments/site/tofu/compute.tf | 4 ++++ environments/site/tofu/control.tf | 4 ++++ environments/site/tofu/login.tf | 5 ++++- environments/site/tofu/node_group/nodes.tf | 8 ++++++++ .../site/tofu/node_group/variables.tf | 17 +++++++++++++++++ environments/site/tofu/variables.tf | 19 +++++++++++++++++++ 7 files changed, 60 insertions(+), 1 deletion(-) diff --git a/environments/site/tofu/additional.tf b/environments/site/tofu/additional.tf index 1f7c48ce5..2d6fba402 100644 --- a/environments/site/tofu/additional.tf +++ b/environments/site/tofu/additional.tf @@ -32,6 +32,8 @@ module "additional" { availability_zone = lookup(each.value, "availability_zone", null) ip_addresses = lookup(each.value, "ip_addresses", null) security_group_ids = lookup(each.value, "security_group_ids", [for o in data.openstack_networking_secgroup_v2.nonlogin: o.id]) + additional_cloud_config = lookup(each.value, "additional_cloud_config", var.additional_cloud_config) + additional_cloud_config_vars = lookup(each.value, "additional_cloud_config_vars", var.additional_cloud_config_vars) # can't be set for additional nodes compute_init_enable = [] @@ -64,5 +66,7 @@ module "additional" { "gateway_ip", "nodename_template", "security_group_ids", + "additional_cloud_config", + "additional_cloud_config_vars" ] } diff --git a/environments/site/tofu/compute.tf b/environments/site/tofu/compute.tf index d73c8ee12..bd0d22a04 100644 --- a/environments/site/tofu/compute.tf +++ b/environments/site/tofu/compute.tf @@ -21,6 +21,8 @@ module "compute" { root_volume_type = lookup(each.value, "root_volume_type", var.root_volume_type) gateway_ip = lookup(each.value, "gateway_ip", var.gateway_ip) nodename_template = lookup(each.value, "nodename_template", var.cluster_nodename_template) + additional_cloud_config = lookup(each.value, "additional_cloud_config", var.additional_cloud_config) + additional_cloud_config_vars = lookup(each.value, "additional_cloud_config_vars", var.additional_cloud_config_vars) # optionally set for group: networks = concat(var.cluster_networks, lookup(each.value, "extra_networks", [])) @@ -59,6 +61,8 @@ module "compute" { "ip_addresses", "gateway_ip", "nodename_template", + "additional_cloud_config", + "additional_cloud_config_vars" ] config_drive = var.config_drive diff --git a/environments/site/tofu/control.tf b/environments/site/tofu/control.tf index 811e781b7..722e89d8b 100644 --- a/environments/site/tofu/control.tf +++ b/environments/site/tofu/control.tf @@ -92,6 +92,10 @@ resource "openstack_compute_instance_v2" "control" { %{if var.home_volume_provisioning != "none"} - [LABEL=home, /exports/home] %{endif} + + %{if var.additional_cloud_config != ""} + ${templatestring(var.additional_cloud_config, var.additional_cloud_config_vars)} + %{endif} EOF config_drive = var.config_drive diff --git a/environments/site/tofu/login.tf b/environments/site/tofu/login.tf index b3aa382e8..e8b55c25c 100644 --- a/environments/site/tofu/login.tf +++ b/environments/site/tofu/login.tf @@ -21,6 +21,8 @@ module "login" { root_volume_type = lookup(each.value, "root_volume_type", var.root_volume_type) gateway_ip = lookup(each.value, "gateway_ip", var.gateway_ip) nodename_template = lookup(each.value, "nodename_template", var.cluster_nodename_template) + additional_cloud_config = lookup(each.value, "additional_cloud_config", var.additional_cloud_config) + additional_cloud_config_vars = lookup(each.value, "additional_cloud_config_vars", var.additional_cloud_config_vars) # optionally set for group: networks = concat(var.cluster_networks, lookup(each.value, "extra_networks", [])) @@ -63,8 +65,9 @@ module "login" { "ip_addresses", "gateway_ip", "nodename_template", + "additional_cloud_config", + "additional_cloud_config_vars" ] config_drive = var.config_drive - } diff --git a/environments/site/tofu/node_group/nodes.tf b/environments/site/tofu/node_group/nodes.tf index 062d979c9..7c3fe218a 100644 --- a/environments/site/tofu/node_group/nodes.tf +++ b/environments/site/tofu/node_group/nodes.tf @@ -116,6 +116,10 @@ resource "openstack_compute_instance_v2" "compute_fixed_image" { user_data = <<-EOF #cloud-config fqdn: ${local.fqdns[each.key]} + + %{if var.additional_cloud_config != ""} + ${templatestring(var.additional_cloud_config, var.additional_cloud_config_vars)} + %{endif} EOF availability_zone = var.match_ironic_node ? "${local.baremetal_az}::${var.baremetal_nodes[each.key]}" : var.availability_zone @@ -173,6 +177,10 @@ resource "openstack_compute_instance_v2" "compute" { user_data = <<-EOF #cloud-config fqdn: ${local.fqdns[each.key]} + + %{if var.additional_cloud_config != ""} + ${templatestring(var.additional_cloud_config, var.additional_cloud_config_vars)} + %{endif} EOF availability_zone = var.match_ironic_node ? "${local.baremetal_az}::${var.baremetal_nodes[each.key]}" : var.availability_zone diff --git a/environments/site/tofu/node_group/variables.tf b/environments/site/tofu/node_group/variables.tf index 8ce104e8f..1b50debce 100644 --- a/environments/site/tofu/node_group/variables.tf +++ b/environments/site/tofu/node_group/variables.tf @@ -201,3 +201,20 @@ variable "config_drive" { type = bool default = false } + +variable "additional_cloud_config" { + description = <<-EOT + Multiline string to be appended to the node's cloud-init cloud-config user-data. + Must be in yaml format and not include the #cloud-config or any other user-data headers. + See https://cloudinit.readthedocs.io/en/latest/explanation/format.html#cloud-config-data. + Can be a templatestring parameterised by `additional_cloud_config_vars` + EOT + type = string + default = "" +} + +variable "additional_cloud_config_vars" { + description = "Map of values passed to the `additional_cloud_config` templatestring" + type = map(any) + default = {} +} diff --git a/environments/site/tofu/variables.tf b/environments/site/tofu/variables.tf index 09698e585..27ba43c05 100644 --- a/environments/site/tofu/variables.tf +++ b/environments/site/tofu/variables.tf @@ -322,3 +322,22 @@ variable "config_drive" { type = bool default = false } + +variable "additional_cloud_config" { + description = <<-EOT + Multiline string to be appended to the node's cloud-init cloud-config user-data. + Must be in yaml format and not include the #cloud-config or any other user-data headers. + See https://cloudinit.readthedocs.io/en/latest/explanation/format.html#cloud-config-data. + Can be a templatestring parameterised by `additional_cloud_config_vars` + Can't set the `boot-cmd`, `fqdn` or `mounts` variables here + EOT + type = string + default = "" +} + +variable "additional_cloud_config_vars" { + description = "Map of values passed to the `additional_cloud_config` templatestring" + type = map(any) + default = {} +} + From 530856d9b4ac9bf8157a8490216619b570891cda Mon Sep 17 00:00:00 2001 From: wtripp180901 <78219569+wtripp180901@users.noreply.github.com> Date: Tue, 12 Aug 2025 11:52:04 +0100 Subject: [PATCH 4/5] docs suggestions Co-authored-by: Steve Brasier <33413598+sjpb@users.noreply.github.com> --- environments/site/tofu/variables.tf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/environments/site/tofu/variables.tf b/environments/site/tofu/variables.tf index 27ba43c05..1ef33b161 100644 --- a/environments/site/tofu/variables.tf +++ b/environments/site/tofu/variables.tf @@ -328,8 +328,8 @@ variable "additional_cloud_config" { Multiline string to be appended to the node's cloud-init cloud-config user-data. Must be in yaml format and not include the #cloud-config or any other user-data headers. See https://cloudinit.readthedocs.io/en/latest/explanation/format.html#cloud-config-data. - Can be a templatestring parameterised by `additional_cloud_config_vars` - Can't set the `boot-cmd`, `fqdn` or `mounts` variables here + Can be a templatestring parameterised by `additional_cloud_config_vars`. + The `boot-cmd`, `fqdn` and `mounts` modules must not be specified. EOT type = string default = "" From fed43095979a822d441fa07a4b9b9818d9f3e7dc Mon Sep 17 00:00:00 2001 From: wtripp180901 Date: Tue, 12 Aug 2025 11:56:39 +0100 Subject: [PATCH 5/5] made user_data node variables non-nullable --- environments/site/tofu/node_group/variables.tf | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/environments/site/tofu/node_group/variables.tf b/environments/site/tofu/node_group/variables.tf index 1b50debce..fab21d6dc 100644 --- a/environments/site/tofu/node_group/variables.tf +++ b/environments/site/tofu/node_group/variables.tf @@ -203,18 +203,13 @@ variable "config_drive" { } variable "additional_cloud_config" { - description = <<-EOT - Multiline string to be appended to the node's cloud-init cloud-config user-data. - Must be in yaml format and not include the #cloud-config or any other user-data headers. - See https://cloudinit.readthedocs.io/en/latest/explanation/format.html#cloud-config-data. - Can be a templatestring parameterised by `additional_cloud_config_vars` - EOT type = string default = "" + nullable = false } variable "additional_cloud_config_vars" { - description = "Map of values passed to the `additional_cloud_config` templatestring" type = map(any) default = {} + nullable = false }