ansible-debops-infrastructure

DebOps and Ansible scripts to manage my infrastructure
git clone git://git.erethon.com/ansible-debops-infrastructure
Log | Files | Refs

commit e57a631ae9824fb24dddf4161de7ed2d47af00ea
parent 43e28766568c8bde2b49044920dd943ed17ecdaa
Author: Dionysis Grigoropoulos <dgrig@erethon.com>
Date:   Sun, 29 Sep 2019 19:22:18 +0300

terraform: Add module for libvirt based hosts

Diffstat:
terraform/infrastructure/modules/libvirt_host/main.tf | 40++++++++++++++++++++++++++++++++++++++++
terraform/infrastructure/modules/libvirt_host/vars.tf | 55+++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 95 insertions(+), 0 deletions(-)

diff --git a/terraform/infrastructure/modules/libvirt_host/main.tf b/terraform/infrastructure/modules/libvirt_host/main.tf @@ -0,0 +1,40 @@ +resource "libvirt_volume" "base_volume" { + count = (var.volume_source == "" ? 0 : 1 ) + name = "base_debian_10_image" + pool = var.storage_pool + format = var.volume_format + source = var.volume_source +} + +resource "libvirt_volume" "volume" { + name = var.volume_name + pool = var.storage_pool + format = var.volume_format + size = var.volume_size + base_volume_id = (var.volume_source == "" ? libvirt_volume.base_volume[0].id : null) +} + +resource "libvirt_domain" "libvirt_host" { + name = var.host_name + memory = var.host_memory + vcpu = var.host_vcpu + autostart = var.host_autostart + + boot_device { + dev = ["hd"] + } + + disk { + volume_id = libvirt_volume.volume.id + } + + network_interface { + network_id = (var.network_id != "" ? var.network_id : null) + addresses = (var.network_id != "" ? [cidrhost(var.network_cidr, var.network_host)] : null) + } + + graphics { + type = "spice" + listen_type = "none" + } +} diff --git a/terraform/infrastructure/modules/libvirt_host/vars.tf b/terraform/infrastructure/modules/libvirt_host/vars.tf @@ -0,0 +1,55 @@ +variable "network_id" { + type = string + default = "" +} + +variable "network_cidr" { + type = string + default = "" +} +variable "network_host" { + type = number + default = 0 +} + +variable "host_name" { + type = string +} + +variable "host_memory" { + type = number + default = 512 +} + +variable "host_vcpu" { + type = number + default = 1 +} + +variable "host_autostart" { + type = bool + default = true +} + +variable "storage_pool" { + type = string +} + +variable "volume_name" { + type = string +} + +variable "volume_size" { + type = number + default = 10737418240 +} + +variable "volume_format" { + type = string + default = "qcow2" +} + +variable "volume_source" { + type = string + default = "" +}