Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 4 additions & 1 deletion environments/.stackhpc/terraform/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,16 @@ module "cluster" {
k3s_token = var.k3s_token

login_nodes = {
login-0: var.other_node_flavor
login-0 = {
flavor: var.other_node_flavor
}
}
compute = {
standard: { # NB: can't call this default!
nodes: ["compute-0", "compute-1"]
flavor: var.other_node_flavor
}

# Example of how to add another partition:
# extra: {
# nodes: ["compute-2", "compute-3"]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
data "external" "nodes" {
program = ["bash", "-c", <<-EOT
openstack baremetal node list --limit 0 -f json 2>/dev/null | \
jq -r 'try map( { (.Name|tostring): .UUID } ) | add catch {}' || echo '{}'
EOT
]
}

resource "openstack_networking_port_v2" "compute" {

for_each = toset(var.nodes)
Expand Down Expand Up @@ -50,6 +58,8 @@ resource "openstack_compute_instance_v2" "compute" {
k3s_server = var.k3s_server
}

availability_zone = var.match_ironic_node ? "${var.availability_zone}::${data.external.nodes.result[each.key]}" : var.availability_zone

user_data = <<-EOF
#cloud-config
fqdn: ${var.cluster_name}-${each.key}.${var.cluster_name}.${var.cluster_domain_suffix}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,16 @@ variable "k3s_server" {
description = "Name/address of k3s server"
type = string
}

variable "match_ironic_node" {
description = "Whether to launch instances on the Ironic node of the same name as this cluster node"
type = bool
default = false

}

variable availability_zone {
description = "Name of availability zone. NB using ZONE:HOST or ZONE::NODE is not supported if setting match_ironic_node"
type = string
default = "nova"
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
locals {
control_volumes = concat([openstack_blockstorage_volume_v3.state], var.home_volume_size > 0 ? [openstack_blockstorage_volume_v3.home][0] : [])

login_node_defaults = {
availability_zone = "nova"
match_ironic_node = false
}

login_nodes = {
for nodename, cfg in var.login_nodes:
nodename => merge(local.login_node_defaults, cfg)
}
}

data "external" "nodes" {
# returns an empty map if cannot list baremetal nodes
program = ["bash", "-c", <<-EOT
openstack baremetal node list --limit 0 -f json 2>/dev/null | \
jq -r 'try map( { (.Name|tostring): .UUID } ) | add catch {}' || echo '{}'
EOT
]
}

resource "openstack_networking_port_v2" "login" {
Expand Down Expand Up @@ -99,11 +118,11 @@ resource "openstack_compute_instance_v2" "control" {

resource "openstack_compute_instance_v2" "login" {

for_each = var.login_nodes
for_each = local.login_nodes

name = "${var.cluster_name}-${each.key}"
image_id = var.cluster_image_id
flavor_name = each.value
flavor_name = each.value.flavor
key_pair = var.key_pair

dynamic "block_device" {
Expand All @@ -129,6 +148,8 @@ resource "openstack_compute_instance_v2" "login" {
k3s_server = [for n in openstack_compute_instance_v2.control["control"].network: n.fixed_ip_v4 if n.access_network][0]
}

availability_zone = each.value.match_ironic_node ? "${each.value.availability_zone}::${data.external.nodes.result[each.key]}" : each.value.availability_zone

user_data = <<-EOF
#cloud-config
fqdn: ${var.cluster_name}-${each.key}.${var.cluster_name}.${var.cluster_domain_suffix}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,14 @@ variable "control_node_flavor" {

variable "login_nodes" {
type = map
description = "Mapping defining login nodes: key -> (str) nodename suffix, value -> (str) flavor name"
description = <<-EOF
Mapping defining login nodes. Keys are the node name suffix. Values are a mapping as follows:
Required:
flavor: String flavor name
Optional:
availability_zone: String, name of availability zone. NB using ZONE:HOST or ZONE::NODE is not supported if setting match_ironic_node
match_ironic_node: Bool, whether to launch instances on the Ironic node of the same name as this cluster node
EOF
}

variable "cluster_image_id" {
Expand Down
Loading