Skip to content

Commit a7876a6

Browse files
authored
Support additional volumes on compute nodes (#528)
1 parent b93e3c7 commit a7876a6

File tree

4 files changed

+48
-0
lines changed

4 files changed

+48
-0
lines changed

environments/skeleton/{{cookiecutter.environment}}/terraform/compute.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ module "compute" {
1818
vnic_profile = lookup(each.value, "vnic_profile", var.vnic_profile)
1919
volume_backed_instances = lookup(each.value, "volume_backed_instances", var.volume_backed_instances)
2020
root_volume_size = lookup(each.value, "root_volume_size", var.root_volume_size)
21+
extra_volumes = lookup(each.value, "extra_volumes", {})
2122

2223
key_pair = var.key_pair
2324
environment_root = var.environment_root

environments/skeleton/{{cookiecutter.environment}}/terraform/compute/nodes.tf

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,33 @@
1+
locals {
2+
all_compute_volumes = {for v in setproduct(var.nodes, keys(var.extra_volumes)): "${v[0]}-${v[1]}" => {"node" = v[0], "volume" = v[1]}}
3+
# e.g. with
4+
# var.nodes = ["compute-0", "compute-1"]
5+
# var.extra_volumes = {
6+
# "vol-a" = {size = 10},
7+
# "vol-b" = {size = 20}
8+
# }
9+
# this is a mapping with
10+
# keys "compute-0-vol-a", "compute-0-vol-b" ...
11+
# values which are a mapping e.g. {"node"="compute-0", "volume"="vol-a"}
12+
}
13+
14+
resource "openstack_blockstorage_volume_v3" "compute" {
15+
16+
for_each = local.all_compute_volumes
17+
18+
name = "${var.cluster_name}-${each.key}"
19+
description = "Compute node ${each.value.node} volume ${each.value.volume}"
20+
size = var.extra_volumes[each.value.volume].size
21+
}
22+
23+
resource "openstack_compute_volume_attach_v2" "compute" {
24+
25+
for_each = local.all_compute_volumes
26+
27+
instance_id = openstack_compute_instance_v2.compute["${each.value.node}"].id
28+
volume_id = openstack_blockstorage_volume_v3.compute["${each.key}"].id
29+
}
30+
131
resource "openstack_networking_port_v2" "compute" {
232

333
for_each = toset(var.nodes)

environments/skeleton/{{cookiecutter.environment}}/terraform/compute/variables.tf

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,18 @@ variable "root_volume_size" {
6464
default = 40
6565
}
6666

67+
variable "extra_volumes" {
68+
description = <<-EOF
69+
Mapping defining additional volumes to create and attach.
70+
Keys are unique volume name.
71+
Values are a mapping with:
72+
size: Size of volume in GB
73+
**NB**: The order in /dev is not guaranteed to match the mapping
74+
EOF
75+
type = any
76+
default = {}
77+
}
78+
6779
variable "security_group_ids" {
6880
type = list
6981
}

environments/skeleton/{{cookiecutter.environment}}/terraform/variables.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ variable "compute" {
5454
vnic_profile: Overrides variable vnic_profile
5555
volume_backed_instances: Overrides variable volume_backed_instances
5656
root_volume_size: Overrides variable root_volume_size
57+
extra_volumes: Mapping defining additional volumes to create and attach
58+
Keys are unique volume name.
59+
Values are a mapping with:
60+
size: Size of volume in GB
61+
**NB**: The order in /dev is not guaranteed to match the mapping
5762
EOF
5863
}
5964

0 commit comments

Comments
 (0)