Browse Source

use storage pools

main
Nicolas Massé 4 years ago
parent
commit
1ad3167b8f
  1. 4
      README.md
  2. 4
      bootstrap.tf
  3. 5
      lb.tf
  4. 6
      main.tf
  5. 4
      master.tf
  6. 7
      storage.tf
  7. 12
      variables.tf
  8. 4
      worker.tf

4
README.md

@ -83,8 +83,8 @@ dns=dnsmasq
Download the required images. Download the required images.
```sh ```sh
curl https://mirror.openshift.com/pub/openshift-v4/dependencies/rhcos/4.7/4.7.0/rhcos-4.7.0-x86_64-qemu.x86_64.qcow2.gz |gunzip -c > /var/lib/libvirt/images/rhcos-4.7.0-x86_64-qemu.x86_64.qcow2 curl https://mirror.openshift.com/pub/openshift-v4/dependencies/rhcos/4.9/4.9.0/rhcos-4.9.0-x86_64-qemu.x86_64.qcow2.gz |gunzip -c > /var/lib/libvirt/images/base-images/rhcos-4.9.0-x86_64-qemu.x86_64.qcow2
curl -Lo /var/lib/libvirt/images/centos-stream-8.qcow2 http://cloud.centos.org/centos/8-stream/x86_64/images/CentOS-Stream-GenericCloud-8-20210210.0.x86_64.qcow2 curl -Lo /var/lib/libvirt/images/base-images/centos-stream-8.qcow2 http://cloud.centos.org/centos/8-stream/x86_64/images/CentOS-Stream-GenericCloud-8-20210210.0.x86_64.qcow2
``` ```
## Install ## Install

4
bootstrap.tf

@ -2,14 +2,16 @@ resource "libvirt_volume" "bootstrap_disk" {
name = "${local.bootstrap_name}.${var.volume_format}" name = "${local.bootstrap_name}.${var.volume_format}"
count = var.bootstrap_nodes count = var.bootstrap_nodes
format = var.volume_format format = var.volume_format
pool = var.pool_name pool = libvirt_pool.cluster_storage.name
base_volume_name = "${var.coreos_image}.${var.volume_format}" base_volume_name = "${var.coreos_image}.${var.volume_format}"
base_volume_pool = var.base_image_pool
size = var.bootstrap_disk_size size = var.bootstrap_disk_size
} }
resource "libvirt_ignition" "bootstrap_ignition" { resource "libvirt_ignition" "bootstrap_ignition" {
name = "${var.cluster_name}-bootstrap-ignition" name = "${var.cluster_name}-bootstrap-ignition"
content = file("${path.module}/.clusters/${var.cluster_name}/bootstrap.ign") content = file("${path.module}/.clusters/${var.cluster_name}/bootstrap.ign")
pool = libvirt_pool.cluster_storage.name
} }
locals { locals {

5
lb.tf

@ -2,7 +2,7 @@ resource "libvirt_cloudinit_disk" "lb_cloudinit" {
name = "${local.lb_name}-cloudinit.iso" name = "${local.lb_name}-cloudinit.iso"
user_data = data.template_file.lb_user_data.rendered user_data = data.template_file.lb_user_data.rendered
network_config = data.template_file.lb_network_config.rendered network_config = data.template_file.lb_network_config.rendered
pool = var.pool_name pool = libvirt_pool.cluster_storage.name
} }
data "template_file" "lb_user_data" { data "template_file" "lb_user_data" {
@ -23,8 +23,9 @@ data "template_file" "lb_network_config" {
resource "libvirt_volume" "lb_disk" { resource "libvirt_volume" "lb_disk" {
name = "${local.lb_name}.${var.volume_format}" name = "${local.lb_name}.${var.volume_format}"
format = var.volume_format format = var.volume_format
pool = var.pool_name pool = libvirt_pool.cluster_storage.name
base_volume_name = "${var.centos_image}.${var.volume_format}" base_volume_name = "${var.centos_image}.${var.volume_format}"
base_volume_pool = var.base_image_pool
size = var.lb_disk_size size = var.lb_disk_size
} }

6
main.tf

@ -32,6 +32,12 @@ terraform {
} }
} }
resource "libvirt_pool" "cluster_storage" {
name = var.cluster_name
type = "dir"
path = "/var/lib/libvirt/images/${var.cluster_name}"
}
locals { locals {
additional_nodes = [local.lb_node, local.storage_node] additional_nodes = [local.lb_node, local.storage_node]
all_nodes = concat(local.additional_nodes, local.master_nodes, local.worker_nodes, local.bootstrap_nodes) all_nodes = concat(local.additional_nodes, local.master_nodes, local.worker_nodes, local.bootstrap_nodes)

4
master.tf

@ -2,14 +2,16 @@ resource "libvirt_volume" "master_disk" {
name = "${format(local.master_format, count.index + 1)}.${var.volume_format}" name = "${format(local.master_format, count.index + 1)}.${var.volume_format}"
count = var.master_nodes count = var.master_nodes
format = var.volume_format format = var.volume_format
pool = var.pool_name pool = libvirt_pool.cluster_storage.name
base_volume_name = "${var.coreos_image}.${var.volume_format}" base_volume_name = "${var.coreos_image}.${var.volume_format}"
base_volume_pool = var.base_image_pool
size = var.master_disk_size size = var.master_disk_size
} }
resource "libvirt_ignition" "master_ignition" { resource "libvirt_ignition" "master_ignition" {
name = "${var.cluster_name}-master-ignition" name = "${var.cluster_name}-master-ignition"
content = file("${path.module}/.clusters/${var.cluster_name}/master.ign") content = file("${path.module}/.clusters/${var.cluster_name}/master.ign")
pool = libvirt_pool.cluster_storage.name
} }
locals { locals {

7
storage.tf

@ -2,7 +2,7 @@ resource "libvirt_cloudinit_disk" "storage_cloudinit" {
name = "${local.storage_name}-cloudinit.iso" name = "${local.storage_name}-cloudinit.iso"
user_data = data.template_file.storage_user_data.rendered user_data = data.template_file.storage_user_data.rendered
network_config = data.template_file.storage_network_config.rendered network_config = data.template_file.storage_network_config.rendered
pool = var.pool_name pool = libvirt_pool.cluster_storage.name
} }
data "template_file" "storage_user_data" { data "template_file" "storage_user_data" {
@ -16,14 +16,15 @@ data "template_file" "storage_network_config" {
resource "libvirt_volume" "storage_os_disk" { resource "libvirt_volume" "storage_os_disk" {
name = "${local.storage_name}-os.${var.volume_format}" name = "${local.storage_name}-os.${var.volume_format}"
format = var.volume_format format = var.volume_format
pool = var.pool_name pool = libvirt_pool.cluster_storage.name
base_volume_name = "${var.centos_image}.${var.volume_format}" base_volume_name = "${var.centos_image}.${var.volume_format}"
base_volume_pool = var.base_image_pool
} }
resource "libvirt_volume" "storage_data_disk" { resource "libvirt_volume" "storage_data_disk" {
name = "${local.storage_name}-data.${var.volume_format}" name = "${local.storage_name}-data.${var.volume_format}"
format = var.volume_format format = var.volume_format
pool = var.pool_name pool = libvirt_pool.cluster_storage.name
size = var.storage_disk_size size = var.storage_disk_size
} }

12
variables.tf

@ -13,11 +13,6 @@ variable "bootstrap_nodes" {
default = 1 default = 1
} }
variable "pool_name" {
type = string
default = "default"
}
variable "volume_format" { variable "volume_format" {
type = string type = string
default = "qcow2" default = "qcow2"
@ -30,7 +25,7 @@ variable "centos_image" {
variable "coreos_image" { variable "coreos_image" {
type = string type = string
default = "rhcos-4.7.0-x86_64-qemu.x86_64" default = "rhcos-4.9.0-x86_64-qemu.x86_64"
} }
variable "cluster_name" { variable "cluster_name" {
@ -146,6 +141,11 @@ variable "acme_account_email" {
type = string type = string
} }
variable "base_image_pool" {
type = string
default = "base-images"
}
locals { locals {
master_format = "${var.cluster_name}-master-%02d" master_format = "${var.cluster_name}-master-%02d"
worker_format = "${var.cluster_name}-worker-%02d" worker_format = "${var.cluster_name}-worker-%02d"

4
worker.tf

@ -2,14 +2,16 @@ resource "libvirt_volume" "worker_disk" {
name = "${format(local.worker_format, count.index + 1)}.${var.volume_format}" name = "${format(local.worker_format, count.index + 1)}.${var.volume_format}"
count = var.worker_nodes count = var.worker_nodes
format = var.volume_format format = var.volume_format
pool = var.pool_name pool = libvirt_pool.cluster_storage.name
base_volume_name = "${var.coreos_image}.${var.volume_format}" base_volume_name = "${var.coreos_image}.${var.volume_format}"
base_volume_pool = var.base_image_pool
size = var.worker_disk_size size = var.worker_disk_size
} }
resource "libvirt_ignition" "worker_ignition" { resource "libvirt_ignition" "worker_ignition" {
name = "${var.cluster_name}-worker-ignition" name = "${var.cluster_name}-worker-ignition"
content = file("${path.module}/.clusters/${var.cluster_name}/worker.ign") content = file("${path.module}/.clusters/${var.cluster_name}/worker.ign")
pool = libvirt_pool.cluster_storage.name
} }
locals { locals {

Loading…
Cancel
Save