Skip to content

Commit

Permalink
Merge pull request #15 from nimbolus/add-ephemeral-disk-option
Browse files Browse the repository at this point in the history
allow using ephemeral data disk instead of cinder volume
  • Loading branch information
lu1as committed Mar 14, 2022
2 parents 347d52f + cb2b485 commit 4634dd8
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 8 deletions.
35 changes: 28 additions & 7 deletions k3s-openstack/main.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
locals {
create_data_volume = var.data_volume_size > 0
data_volume_name = var.image_scsi_bus ? "/dev/sdb" : "/dev/vdb"
}

data "openstack_compute_flavor_v2" "k3s" {
count = var.flavor_id == null ? 1 : 0

Expand All @@ -12,6 +17,8 @@ data "openstack_images_image_v2" "k3s" {
}

resource "openstack_blockstorage_volume_v3" "data" {
count = local.create_data_volume && !var.ephemeral_data_volume ? 1 : 0

name = "${var.name}-data"
availability_zone = var.availability_zone
volume_type = var.data_volume_type
Expand All @@ -35,7 +42,7 @@ module "k3s" {
custom_cloud_config_runcmd = var.custom_cloud_config_runcmd
bootstrap_token_id = var.bootstrap_token_id
bootstrap_token_secret = var.bootstrap_token_secret
persistent_volume_dev = var.image_scsi_bus ? "/dev/sdb" : "/dev/vdb"
persistent_volume_dev = local.create_data_volume ? local.data_volume_name : ""
}

resource "openstack_compute_instance_v2" "node" {
Expand Down Expand Up @@ -73,12 +80,26 @@ resource "openstack_compute_instance_v2" "node" {
source_type = "image"
}

block_device {
boot_index = -1
uuid = openstack_blockstorage_volume_v3.data.id
source_type = "volume"
destination_type = "volume"
delete_on_termination = false
dynamic "block_device" {
for_each = local.create_data_volume && var.ephemeral_data_volume ? { "data" = { "size" = var.data_volume_size } } : {}
content {
boot_index = -1
source_type = "blank"
destination_type = "local"
delete_on_termination = true
volume_size = block_device.value["size"]
}
}

dynamic "block_device" {
for_each = openstack_blockstorage_volume_v3.data
content {
boot_index = -1
uuid = block_device.value["id"]
source_type = "volume"
destination_type = "volume"
delete_on_termination = false
}
}

lifecycle {
Expand Down
8 changes: 7 additions & 1 deletion k3s-openstack/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,18 @@ variable "additional_port_ids" {
default = []
}

variable "ephemeral_data_volume" {
default = false
description = "use an ephemeral disk for data, which will be deleted on instance termination"
}

variable "data_volume_type" {
default = "__DEFAULT__"
}

variable "data_volume_size" {
default = 10
default = 10
description = "data volume size in GB, can be set to 0 to omit data volume creation"
}

variable "data_volume_enable_online_resize" {
Expand Down

0 comments on commit 4634dd8

Please sign in to comment.