Skip to content

Commit

Permalink
Merge branch 'main' into feat/compute-init-cookiecutter
Browse files Browse the repository at this point in the history
  • Loading branch information
bertiethorpe authored Jan 9, 2025
2 parents bc16dba + a7876a6 commit 68561b4
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ module "compute" {
vnic_profile = lookup(each.value, "vnic_profile", var.vnic_profile)
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)
extra_volumes = lookup(each.value, "extra_volumes", {})

key_pair = var.key_pair
environment_root = var.environment_root
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,33 @@
locals {
all_compute_volumes = {for v in setproduct(var.nodes, keys(var.extra_volumes)): "${v[0]}-${v[1]}" => {"node" = v[0], "volume" = v[1]}}
# e.g. with
# var.nodes = ["compute-0", "compute-1"]
# var.extra_volumes = {
# "vol-a" = {size = 10},
# "vol-b" = {size = 20}
# }
# this is a mapping with
# keys "compute-0-vol-a", "compute-0-vol-b" ...
# values which are a mapping e.g. {"node"="compute-0", "volume"="vol-a"}
}

resource "openstack_blockstorage_volume_v3" "compute" {

for_each = local.all_compute_volumes

name = "${var.cluster_name}-${each.key}"
description = "Compute node ${each.value.node} volume ${each.value.volume}"
size = var.extra_volumes[each.value.volume].size
}

resource "openstack_compute_volume_attach_v2" "compute" {

for_each = local.all_compute_volumes

instance_id = openstack_compute_instance_v2.compute["${each.value.node}"].id
volume_id = openstack_blockstorage_volume_v3.compute["${each.key}"].id
}

resource "openstack_networking_port_v2" "compute" {

for_each = toset(var.nodes)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,18 @@ variable "root_volume_size" {
default = 40
}

variable "extra_volumes" {
description = <<-EOF
Mapping defining additional volumes to create and attach.
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
EOF
type = any
default = {}
}

variable "security_group_ids" {
type = list
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ variable "compute" {
compute_init_enable: Toggles compute-init rebuild (see compute-init role docs)
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:
size: Size of volume in GB
**NB**: The order in /dev is not guaranteed to match the mapping
EOF
}

Expand Down

0 comments on commit 68561b4

Please sign in to comment.