Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/stackhpc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ jobs:
run: dev/setup-env.sh

- name: Install OpenTofu
uses: opentofu/setup-opentofu@v1
uses: opentofu/setup-opentofu@v1.0.5
with:
tofu_version: 1.6.2
tofu_version: 1.9.0

- name: Initialise tofu
run: tofu init
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ module "compute" {
volume_backed_instances = lookup(each.value, "volume_backed_instances", var.volume_backed_instances)
root_volume_size = lookup(each.value, "root_volume_size", var.root_volume_size)
gateway_ip = lookup(each.value, "gateway_ip", var.gateway_ip)

nodename_template = lookup(each.value, "nodename_template", var.cluster_nodename_template)

# optionally set for group:
networks = concat(var.cluster_networks, lookup(each.value, "extra_networks", []))
extra_volumes = lookup(each.value, "extra_volumes", {})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
locals {
control_volumes = concat([openstack_blockstorage_volume_v3.state], var.home_volume_size > 0 ? [openstack_blockstorage_volume_v3.home][0] : [])
nodename = templatestring(
var.cluster_nodename_template,
{
node = "control",
cluster_name = var.cluster_name,
cluster_domain_suffix = var.cluster_domain_suffix,
environment_name = basename(var.environment_root)
}
)
}

resource "openstack_networking_port_v2" "control" {
Expand All @@ -24,7 +33,7 @@ resource "openstack_networking_port_v2" "control" {

resource "openstack_compute_instance_v2" "control" {

name = "${var.cluster_name}-control"
name = split(".", local.nodename)[0]
image_id = var.cluster_image_id
flavor_name = var.control_node_flavor
key_pair = var.key_pair
Expand Down Expand Up @@ -65,7 +74,7 @@ resource "openstack_compute_instance_v2" "control" {

user_data = <<-EOF
#cloud-config
fqdn: ${var.cluster_name}-control.${var.cluster_name}.${var.cluster_domain_suffix}
fqdn: ${local.nodename}

bootcmd:
%{for volume in local.control_volumes}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ module "login" {
volume_backed_instances = lookup(each.value, "volume_backed_instances", var.volume_backed_instances)
root_volume_size = lookup(each.value, "root_volume_size", var.root_volume_size)
gateway_ip = lookup(each.value, "gateway_ip", var.gateway_ip)
nodename_template = lookup(each.value, "nodename_template", var.cluster_nodename_template)

# optionally set for group
networks = concat(var.cluster_networks, lookup(each.value, "extra_networks", []))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
terraform {
required_version = ">= 0.14"
required_version = ">= 1.7" # templatestring() function
required_providers {
openstack = {
source = "terraform-provider-openstack/openstack"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,19 @@ locals {

# Workaround for lifecycle meta-argument only taking static values
compute_instances = var.ignore_image_changes ? openstack_compute_instance_v2.compute_fixed_image : openstack_compute_instance_v2.compute

# Define nodenames here to avoid repetition
nodenames = {
for n in var.nodes: n => templatestring(
var.nodename_template,
{
node = n,
cluster_name = var.cluster_name,
cluster_domain_suffix = var.cluster_domain_suffix,
environment_name = basename(var.environment_root)
}
)
}
}

resource "openstack_blockstorage_volume_v3" "compute" {
Expand Down Expand Up @@ -57,7 +70,7 @@ resource "openstack_compute_instance_v2" "compute_fixed_image" {

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

name = "${var.cluster_name}-${each.key}"
name = split(".", local.nodenames[each.key])[0]
image_id = var.image_id
flavor_name = var.flavor
key_pair = var.key_pair
Expand Down Expand Up @@ -94,7 +107,7 @@ resource "openstack_compute_instance_v2" "compute_fixed_image" {

user_data = <<-EOF
#cloud-config
fqdn: ${var.cluster_name}-${each.key}.${var.cluster_name}.${var.cluster_domain_suffix}
fqdn: ${local.nodenames[each.key]}
EOF

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

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

name = "${var.cluster_name}-${each.key}"
name = split(".", local.nodenames[each.key])[0]
image_id = var.image_id
flavor_name = var.flavor
key_pair = var.key_pair
Expand Down Expand Up @@ -148,7 +161,7 @@ resource "openstack_compute_instance_v2" "compute" {

user_data = <<-EOF
#cloud-config
fqdn: ${var.cluster_name}-${each.key}.${var.cluster_name}.${var.cluster_domain_suffix}
fqdn: ${local.nodenames[each.key]}
EOF

availability_zone = var.match_ironic_node ? "${var.availability_zone}::${var.baremetal_nodes[each.key]}" : null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,8 @@ variable "gateway_ip" {
type = string
default = ""
}

variable "nodename_template" {
type = string
default = ""
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ variable "login" {
match_ironic_node: Set true to launch instances on the Ironic node of the same name as each cluster node
availability_zone: Name of availability zone - ignored unless match_ironic_node is true (default: "nova")
gateway_ip: Address to add default route via
nodename_template: Overrides variable cluster_nodename_template
EOF
}

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

Expand Down Expand Up @@ -179,3 +181,18 @@ variable "gateway_ip" {
type = string
default = ""
}

variable "cluster_nodename_template" {
description = <<-EOT
Template for node fully-qualified names. The following interpolations
can be used:
$${cluster_name}: From var.cluster_name
$${cluster_domain_suffix}: From var.cluster_domain_suffix
$${node}: The current entry in the "nodes" parameter for nodes
defined by var.compute and var.login, or "control" for the control
node
$${environment_name}: The last element of the current environment's path
EOT
type = string
default = "$${cluster_name}-$${node}.$${cluster_name}.$${cluster_domain_suffix}"
}