ansible-debops-infrastructure

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

commit ae12529208cc44fea483705a7be52693a97189fc
parent bb70653367721e42db153e2c87fb40177c48cd7a
Author: Dionysis Grigoropoulos <dgrig@erethon.com>
Date:   Fri, 11 Oct 2019 00:32:59 +0300

libvirt_host: Add support for cloud-init

Diffstat:
terraform/infrastructure/modules/libvirt_host/main.tf | 30+++++++++++++++++++++---------
terraform/infrastructure/modules/libvirt_host/vars.tf | 23++++++++++++++---------
2 files changed, 35 insertions(+), 18 deletions(-)

diff --git a/terraform/infrastructure/modules/libvirt_host/main.tf b/terraform/infrastructure/modules/libvirt_host/main.tf @@ -1,24 +1,36 @@ 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 + 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 + 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) } +data "template_file" "user_data" { + count = (var.cloudinit_template != "" ? 1 : 0) + template = var.cloudinit_template +} + +resource "libvirt_cloudinit_disk" "cloud_init" { + count = (var.cloudinit_template != "" ? 1 : 0) + name = "cloud-init.iso" + user_data = "${data.template_file.user_data[count.index].rendered}" +} + resource "libvirt_domain" "libvirt_host" { name = var.host_name memory = var.host_memory vcpu = var.host_vcpu autostart = var.host_autostart + cloudinit = (var.cloudinit_template != "" ? libvirt_cloudinit_disk.cloud_init[0].id : null) boot_device { dev = ["hd"] diff --git a/terraform/infrastructure/modules/libvirt_host/vars.tf b/terraform/infrastructure/modules/libvirt_host/vars.tf @@ -1,14 +1,14 @@ variable "network_id" { - type = string + type = string default = "" } variable "network_cidr" { - type = string + type = string default = "" } variable "network_host" { - type = number + type = number default = 0 } @@ -17,17 +17,17 @@ variable "host_name" { } variable "host_memory" { - type = number + type = number default = 512 } variable "host_vcpu" { - type = number + type = number default = 1 } variable "host_autostart" { - type = bool + type = bool default = true } @@ -40,16 +40,21 @@ variable "volume_name" { } variable "volume_size" { - type = number + type = number default = 10737418240 } variable "volume_format" { - type = string + type = string default = "qcow2" } variable "volume_source" { - type = string + type = string + default = "" +} + +variable "cloudinit_template" { + type = string default = "" }