Skip to content
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ module "compute" {
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
volumes = lookup(each.value, "volumes", {})

environment_root = var.environment_root
k3s_token = var.k3s_token
control_address = [for n in openstack_compute_instance_v2.control["control"].network: n.fixed_ip_v4 if n.access_network][0]
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.volumes)): "${v[0]}-${v[1]}" => {"node" = v[0], "volume" = v[1]}}
# e.g. with
# var.nodes = ["compute-0", "compute-1"]
# var.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.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 Expand Up @@ -26,18 +56,6 @@ resource "openstack_compute_instance_v2" "compute" {
image_id = var.image_id
flavor_name = var.flavor
key_pair = var.key_pair

dynamic "block_device" {
for_each = var.volume_backed_instances ? [1]: []
content {
uuid = var.image_id
source_type = "image"
destination_type = "volume"
volume_size = var.root_volume_size
boot_index = 0
delete_on_termination = true
}
}

network {
port = openstack_networking_port_v2.compute[each.key].id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,17 @@ variable "root_volume_size" {
default = 40
}

variable "volumes" {
description = <<-EOF
Mapping defining volumes to create and attach.
Keys are unique volume name.
Values are a mapping with:
size: Size of volume in GB
EOF
type = any
default = {}
}

variable "security_group_ids" {
type = list
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ variable "compute" {
image_id: Overrides variable cluster_image_id
vnic_type: Overrides variable vnic_type
vnic_profile: Overrides variable vnic_profile
volumes: Mapping defining volumes to create and attach to compute nodes.
Keys are a unique volume name.
Values are a mapping containing:
size: Size of volume in GB
EOF
}

Expand Down
Loading