Skip to content
This repository has been archived by the owner on Feb 9, 2024. It is now read-only.

Commit

Permalink
Added support for data disk and disks' size (#2188)
Browse files Browse the repository at this point in the history
* Added support for data disk and disks' size

* Addressed PR comments
  • Loading branch information
Lele authored Oct 7, 2020
1 parent bfb932e commit 134dc60
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 6 deletions.
11 changes: 9 additions & 2 deletions terraform-dev/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
IMAGEURL := https://cloud-images.ubuntu.com/releases/bionic/release/ubuntu-18.04-server-cloudimg-amd64.img
CPU_COUNT ?= 1
DISK_SIZE ?= 15000000000
MEMORY_SIZE ?= 4096
DISK_POOL ?= default
ROOT_DISK_SIZE ?= 15000000000
DATA_DISK_SIZE ?= 15000000000
OS ?= ubuntu
ANSIBLE_EXTRA_VARS ?=
NODES_COUNT ?= 3
Expand All @@ -11,7 +14,11 @@ endif

IMAGENAME := $(shell basename $(IMAGEURL))
TF_VARIABLES := TF_VAR_image_name=$(IMAGENAME) TF_VAR_cpu_count=$(CPU_COUNT)\
TF_VAR_disk_size=$(DISK_SIZE) TF_VAR_username=$(OS) TF_VAR_nodes_count=$(NODES_COUNT)
TF_VAR_memory_size=$(MEMORY_SIZE) \
TF_VAR_disk_pool=$(DISK_POOL) \
TF_VAR_root_disk_size=$(ROOT_DISK_SIZE) \
TF_VAR_data_disk_size=$(DATA_DISK_SIZE) \
TF_VAR_username=$(OS) TF_VAR_nodes_count=$(NODES_COUNT)

.PHONY: all
all: apply install
Expand Down
31 changes: 27 additions & 4 deletions terraform-dev/cluster.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,17 @@ variable "image_name" {
default = "ubuntu-18.04-server-cloudimg-amd64.img"
}

variable "disk_size" {
variable "disk_pool" {
type = string
default = "default"
}

variable "root_disk_size" {
type = string
default = "15000000000"
}

variable "data_disk_size" {
type = string
default = "15000000000"
}
Expand Down Expand Up @@ -31,9 +41,8 @@ provider "libvirt" {
# Use locally pre-fetched image
resource "libvirt_volume" "os-qcow2" {
name = "os-disk-${count.index}.qcow2"
pool = "default"
pool = "${var.disk_pool}"
source = "/var/lib/libvirt/images/${var.image_name}"
format = "raw"
count = var.nodes_count
}

Expand All @@ -47,11 +56,21 @@ resource "libvirt_network" "vm_network" {
}
}

# "root" volume will be used to store the OS installation filesystem
resource "libvirt_volume" "root" {
name = "root-disk-${count.index}.qcow2"
base_volume_id = element(libvirt_volume.os-qcow2.*.id, count.index)
pool = "default"
size = var.disk_size
size = var.root_disk_size
count = var.nodes_count
}

# "data" volume may be used as a secondary disk volume in specific scenarios
# (eg: running tests against docker using 'devicemapper' based storage)
resource "libvirt_volume" "data" {
name = "data-disk-${count.index}.qcow2"
pool = "default"
size = var.data_disk_size
count = var.nodes_count
}

Expand Down Expand Up @@ -99,6 +118,10 @@ resource "libvirt_domain" "domain-gravity" {
disk {
volume_id = element(libvirt_volume.root.*.id, count.index)
}

disk {
volume_id = element(libvirt_volume.data.*.id, count.index)
}
}

terraform {
Expand Down

0 comments on commit 134dc60

Please sign in to comment.