Skip to content

Commit

Permalink
define cluster images in single variable
Browse files Browse the repository at this point in the history
  • Loading branch information
sjpb committed Jan 8, 2025
1 parent 5640792 commit fe9f83a
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 18 deletions.
10 changes: 7 additions & 3 deletions environments/.stackhpc/tofu/cluster_image.auto.tfvars.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
{
"cluster_image": {
"RL8": "openhpc-RL8-250102-1138-77cfc703",
"RL9": "openhpc-RL9-250102-1139-77cfc703"
"cluster_image_names": {
"RL8": {
"default": "openhpc-RL8-250102-1138-77cfc703"
},
"RL9": {
"default": "openhpc-RL9-250102-1139-77cfc703"
}
}
}
15 changes: 9 additions & 6 deletions environments/.stackhpc/tofu/main.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

# This terraform configuration uses the "skeleton" terraform, so that is checked by CI.

terraform {
Expand Down Expand Up @@ -25,9 +26,9 @@ variable "os_version" {
default = "RL9"
}

variable "cluster_image" {
description = "single image for all cluster nodes, keyed by os_version - a convenience for CI"
type = map(string)
variable "cluster_image_names" {
description = "image *names* keyed by os_version, for CI"
type = map(map(string))
}

variable "cluster_net" {}
Expand Down Expand Up @@ -58,8 +59,10 @@ variable "k3s_token" {
type = string
}

data "openstack_images_image_v2" "cluster" {
name = var.cluster_image[var.os_version]
data "openstack_images_image_v2" "cluster_images" {
for_each = var.cluster_image_names[var.os_version]

name = each.value
most_recent = true
}

Expand All @@ -71,7 +74,7 @@ module "cluster" {
cluster_subnet = var.cluster_subnet
vnic_type = var.vnic_type
key_pair = "slurm-app-ci"
cluster_image_id = data.openstack_images_image_v2.cluster.id
cluster_image_ids = {for key, img in data.openstack_images_image_v2.cluster_images: key => img.id}
control_node_flavor = var.control_node_flavor
k3s_token = var.k3s_token

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module "compute" {
cluster_subnet_id = data.openstack_networking_subnet_v2.cluster_subnet.id

flavor = each.value.flavor
image_id = lookup(each.value, "image_id", var.cluster_image_id)
image_id = lookup(var.cluster_image_ids, each.key, var.cluster_image_ids["default"])
vnic_type = lookup(each.value, "vnic_type", var.vnic_type)
vnic_profile = lookup(each.value, "vnic_profile", var.vnic_profile)
key_pair = var.key_pair
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ resource "openstack_compute_instance_v2" "control" {
for_each = toset(["control"])

name = "${var.cluster_name}-${each.key}"
image_id = var.cluster_image_id
image_id = var.cluster_image_ids["default"]
flavor_name = var.control_node_flavor
key_pair = var.key_pair

# root device:
block_device {
uuid = var.cluster_image_id
uuid = var.cluster_image_ids["default"]
source_type = "image"
destination_type = var.volume_backed_instances ? "volume" : "local"
volume_size = var.volume_backed_instances ? var.root_volume_size : null
Expand Down Expand Up @@ -102,14 +102,14 @@ resource "openstack_compute_instance_v2" "login" {
for_each = var.login_nodes

name = "${var.cluster_name}-${each.key}"
image_id = var.cluster_image_id
image_id = var.cluster_image_ids["default"]
flavor_name = each.value
key_pair = var.key_pair

dynamic "block_device" {
for_each = var.volume_backed_instances ? [1]: []
content {
uuid = var.cluster_image_id
uuid = var.cluster_image_ids["default"]
source_type = "image"
destination_type = "volume"
volume_size = var.root_volume_size
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,13 @@ variable "login_nodes" {
description = "Mapping defining login nodes: key -> (str) nodename suffix, value -> (str) flavor name"
}

variable "cluster_image_id" {
type = string
description = "ID of default image for the cluster"
variable "cluster_image_ids" {
type = map(string)
description = <<-EOF
Mapping of UUIDs defining images for the cluster. Valid keys are:
- "default": required, defines default image for cluster
- any key from "compute" variable, to define different images for compute node groups
EOF
}

variable "compute" {
Expand All @@ -49,7 +53,6 @@ variable "compute" {
nodes: List of node names
flavor: String flavor name
Optional:
image_id: Overrides variable cluster_image_id
vnic_type: Overrides variable vnic_type
vnic_profile: Overrides variable vnic_profile
EOF
Expand Down

0 comments on commit fe9f83a

Please sign in to comment.