Skip to content

Commit 5528646

Browse files
committed
allow for volume-backed instances and use for CI on SMS
1 parent ed34c06 commit 5528646

File tree

5 files changed

+56
-15
lines changed

5 files changed

+56
-15
lines changed

environments/.stackhpc/terraform/ARCUS.tfvars

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ cluster_subnet = "WCDC-iLab-60"
33
vnic_type = "normal"
44
control_node_flavor = "vm.ska.cpu.general.quarter"
55
other_node_flavor = "vm.ska.cpu.general.small"
6+
volume_backed_instances = false

environments/.stackhpc/terraform/SMS.tfvars

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ cluster_subnet = "stackhpc-ipv4-geneve-subnet"
33
vnic_type = "direct"
44
control_node_flavor = "general.v1.medium"
55
other_node_flavor = "general.v1.tiny"
6+
volume_backed_instances = true

environments/.stackhpc/terraform/main.tf

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,6 @@ variable "cluster_name" {
1010
description = "Name for cluster, used as prefix for resources - set by environment var in CI"
1111
}
1212

13-
variable "create_nodes" {
14-
description = "Whether to create nodes (servers) or just ports and other infra"
15-
type = bool # can't use bool as want to pass from command-line
16-
default = true
17-
}
18-
1913
variable "cluster_image" {
2014
description = "single image for all cluster nodes - a convenience for CI"
2115
type = string
@@ -34,6 +28,8 @@ variable "control_node_flavor" {}
3428

3529
variable "other_node_flavor" {}
3630

31+
variable "volume_backed_instances" {}
32+
3733
module "cluster" {
3834
source = "../../skeleton/{{cookiecutter.environment}}/terraform/"
3935

@@ -68,7 +64,7 @@ module "cluster" {
6864
compute-2: "extra"
6965
compute-3: "extra"
7066
}
71-
create_nodes = var.create_nodes
67+
volume_backed_instances = var.volume_backed_instances
7268

7369
environment_root = var.environment_root
7470
# Can reduce volume size a lot for short-lived CI clusters:

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

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,18 @@ data "openstack_images_image_v2" "control" {
77
name = var.control_node.image
88
}
99

10+
data "openstack_images_image_v2" "login" {
11+
for_each = var.login_nodes
12+
13+
name = each.value.image
14+
}
15+
16+
data "openstack_images_image_v2" "compute" {
17+
for_each = var.compute_nodes
18+
19+
name = lookup(var.compute_images, each.key, var.compute_types[each.value].image)
20+
}
21+
1022
resource "openstack_networking_port_v2" "login" {
1123

1224
for_each = toset(keys(var.login_nodes))
@@ -68,7 +80,7 @@ resource "openstack_networking_port_v2" "compute" {
6880

6981
resource "openstack_compute_instance_v2" "control" {
7082

71-
for_each = var.create_nodes ? toset(["control"]) : toset([])
83+
for_each = toset(["control"])
7284

7385
name = "${var.cluster_name}-${each.key}"
7486
image_name = data.openstack_images_image_v2.control.name
@@ -79,7 +91,8 @@ resource "openstack_compute_instance_v2" "control" {
7991
block_device {
8092
uuid = data.openstack_images_image_v2.control.id
8193
source_type = "image"
82-
destination_type = "local"
94+
destination_type = var.volume_backed_instances ? "volume" : "local"
95+
volume_size = var.volume_backed_instances ? var.volume_size : null
8396
boot_index = 0
8497
delete_on_termination = true
8598
}
@@ -136,12 +149,24 @@ resource "openstack_compute_instance_v2" "control" {
136149

137150
resource "openstack_compute_instance_v2" "login" {
138151

139-
for_each = var.create_nodes ? var.login_nodes : {}
152+
for_each = var.login_nodes
140153

141154
name = "${var.cluster_name}-${each.key}"
142155
image_name = each.value.image
143156
flavor_name = each.value.flavor
144157
key_pair = var.key_pair
158+
159+
dynamic "block_device" {
160+
for_each = var.volume_backed_instances ? [1]: []
161+
content {
162+
uuid = data.openstack_images_image_v2.login[each.key].id
163+
source_type = "image"
164+
destination_type = "volume"
165+
volume_size = var.volume_size
166+
boot_index = 0
167+
delete_on_termination = true
168+
}
169+
}
145170

146171
network {
147172
port = openstack_networking_port_v2.login[each.key].id
@@ -162,12 +187,24 @@ resource "openstack_compute_instance_v2" "login" {
162187

163188
resource "openstack_compute_instance_v2" "compute" {
164189

165-
for_each = var.create_nodes ? var.compute_nodes : {}
190+
for_each = var.compute_nodes
166191

167192
name = "${var.cluster_name}-${each.key}"
168193
image_name = lookup(var.compute_images, each.key, var.compute_types[each.value].image)
169194
flavor_name = var.compute_types[each.value].flavor
170195
key_pair = var.key_pair
196+
197+
dynamic "block_device" {
198+
for_each = var.volume_backed_instances ? [1]: []
199+
content {
200+
uuid = data.openstack_images_image_v2.compute[each.key].id
201+
source_type = "image"
202+
destination_type = "volume"
203+
volume_size = var.volume_size
204+
boot_index = 0
205+
delete_on_termination = true
206+
}
207+
}
171208

172209
network {
173210
port = openstack_networking_port_v2.compute[each.key].id

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,14 @@ variable "nonlogin_security_groups" {
109109
]
110110
}
111111

112-
variable "create_nodes" {
113-
description = "Whether to create nodes (servers) or just ports and other infra"
114-
type = bool # can't use bool as want to pass from command-line
115-
default = true
112+
variable "volume_backed_instances" {
113+
description = "Whether to use volumes for root disks"
114+
type = bool
115+
default = false
116+
}
117+
118+
variable "root_volume_size" {
119+
description = "Size of volume for root volumes if using volume backed instances, in Gb"
120+
type = number
121+
default = 40
116122
}

0 commit comments

Comments
 (0)