Skip to content

Commit

Permalink
Merge pull request ocp-power-automation#212 from aishwaryabk/data-disk
Browse files Browse the repository at this point in the history
To attach additional data volumes to nodes
  • Loading branch information
Power Cloud Robot authored Jul 6, 2021
2 parents fff1125 + ab3dbff commit fd9751e
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 2 deletions.
5 changes: 5 additions & 0 deletions docs/var.tfvars-doc.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ bootstrap = {instance_type = "<bootstrap-compute-template>"
master = {instance_type = "<master-compute-template>", image_id = "<image-uuid-rhcos>", "count" = 3, fixed_ips = ["<IPv4 address>", "<IPv4 address>", "<IPv4 address>"]}
worker = {instance_type = "<worker-compute-template>", image_id = "<image-uuid-rhcos>", "count" = 2, fixed_ips = ["<IPv4 address>", "<IPv4 address>"]}
```
To attach additional volumes to master or worker nodes, set the optional `data_volume_count` key to the number of volumes that is to be attached and the `data_volume_size` to the size (in GB) for each volume.
```
master = {instance_type = "<master-compute-template>", image_id = "<image-uuid-rhcos>", "count" = 3, data_volume_count = 0, data_volume_size = 100}
worker = {instance_type = "<worker-compute-template>", image_id = "<image-uuid-rhcos>", "count" = 2, data_volume_count = 0, data_volume_size = 100}
```
These set of variables specify the username and the SSH key to be used for accessing the bastion node.
```
rhel_username = "root"
Expand Down
37 changes: 37 additions & 0 deletions modules/4_nodes/nodes.tf
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,24 @@ resource "openstack_compute_instance_v2" "master" {
}
}

locals {
master = {
volume_count = lookup(var.master, "data_volume_count", 0),
volume_size = lookup(var.master, "data_volume_size", 0)
}
}

resource "openstack_blockstorage_volume_v2" "master" {
count = local.master.volume_count * var.master["count"]
name = "${var.cluster_id}-master-${count.index}-volume"
size = local.master.volume_size
}

resource "openstack_compute_volume_attach_v2" "master" {
count = local.master.volume_count * var.master["count"]
instance_id = openstack_compute_instance_v2.master.*.id[floor(count.index / local.master.volume_count)]
volume_id = openstack_blockstorage_volume_v2.master.*.id[count.index]
}

#worker
data "ignition_config" "worker" {
Expand Down Expand Up @@ -191,6 +209,25 @@ resource "openstack_compute_instance_v2" "worker" {
}
}

locals {
worker = {
volume_count = lookup(var.worker, "data_volume_count", 0),
volume_size = lookup(var.worker, "data_volume_size", 0)
}
}

resource "openstack_blockstorage_volume_v2" "worker" {
count = local.worker.volume_count * var.worker["count"]
name = "${var.cluster_id}-worker-${count.index}-volume"
size = local.worker.volume_size
}

resource "openstack_compute_volume_attach_v2" "worker" {
count = local.worker.volume_count * var.worker["count"]
instance_id = openstack_compute_instance_v2.worker.*.id[floor(count.index / local.worker.volume_count)]
volume_id = openstack_blockstorage_volume_v2.worker.*.id[count.index]
}

resource "null_resource" "remove_worker" {
count = var.worker["count"]
depends_on = [openstack_compute_instance_v2.worker]
Expand Down
4 changes: 2 additions & 2 deletions var.tfvars
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ worker = {instance_type = "<worker-compute-template>",
# With all optional attributes
# bastion = {instance_type = "<bastion-compute-template>", image_id = "<image-uuid-rhel>", availability_zone = "<availability zone>", "count" = 1, fixed_ip_v4 = "<IPv4 address>"}
# bootstrap = {instance_type = "<bootstrap-compute-template>", image_id = "<image-uuid-rhcos>", availability_zone = "<availability zone>", "count" = 1}
# master = {instance_type = "<master-compute-template>", image_id = "<image-uuid-rhcos>", availability_zone = "<availability zone>", "count" = 3}
# worker = {instance_type = "<worker-compute-template>", image_id = "<image-uuid-rhcos>", availability_zone = "<availability zone>", "count" = 2}
# master = {instance_type = "<master-compute-template>", image_id = "<image-uuid-rhcos>", availability_zone = "<availability zone>", "count" = 3, data_volume_count = 0, data_volume_size = 100}
# worker = {instance_type = "<worker-compute-template>", image_id = "<image-uuid-rhcos>", availability_zone = "<availability zone>", "count" = 2, data_volume_count = 0, data_volume_size = 100}


rhel_username = "root"
Expand Down
6 changes: 6 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ variable "master" {
# availability_zone = ""
# optional fixed IPs
# fixed_ips = []
# optional data volumes to master nodes
# data_volume_size = 100 #Default volume size (in GB) to be attached to the master nodes.
# data_volume_count = 0 #Number of volumes to be attached to each master node.
}
}

Expand All @@ -109,6 +112,9 @@ variable "worker" {
# availability_zone = ""
# optional fixed IPs
# fixed_ips = []
# optional data volumes to worker nodes
# data_volume_size = 100 #Default volume size (in GB) to be attached to the worker nodes.
# data_volume_count = 0 #Number of volumes to be attached to each worker node.
}
}

Expand Down

0 comments on commit fd9751e

Please sign in to comment.