commit 02c7ca28ae2e155f1dd4bbc915eaf60e366f63f4
parent d62dca0a61f717fed3cfb1173198caa1932d9b5d
Author: Dionysis Grigoropoulos <dgrig@erethon.com>
Date: Sat, 26 Oct 2019 16:23:43 +0300
terraform: Move modules directory outside of infra
Diffstat:
10 files changed, 175 insertions(+), 157 deletions(-)
diff --git a/terraform/infrastructure/modules/libvirt_host/main.tf b/terraform/infrastructure/modules/libvirt_host/main.tf
@@ -1,62 +0,0 @@
-resource "random_pet" "random_volume" {
- count = (var.volume_source == "" ? 0 : 1)
- separator = "_"
-}
-
-resource "libvirt_volume" "base_volume" {
- count = (var.volume_source == "" ? 0 : 1)
- name = "base_volume_${random_pet.random_volume[0].id}"
- 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 "random_pet" "random" {
- count = (var.cloudinit_template != "" ? 1 : 0)
- separator = "_"
-}
-
-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-${random_pet.random[0].id}.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"]
- }
-
- 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
@@ -1,60 +0,0 @@
-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 = ""
-}
-
-variable "cloudinit_template" {
- type = string
- default = ""
-}
diff --git a/terraform/infrastructure/modules/libvirt_network/main.tf b/terraform/infrastructure/modules/libvirt_network/main.tf
@@ -1,7 +0,0 @@
-resource "libvirt_network" "network" {
- name = "${var.network_name}"
- mode = "${var.network_mode}"
- addresses = ["${var.network_cidr}"]
- autostart = "${var.network_autostart}"
- bridge = "${var.network_bridge_interface}"
-}
diff --git a/terraform/infrastructure/modules/libvirt_network/outputs.tf b/terraform/infrastructure/modules/libvirt_network/outputs.tf
@@ -1,7 +0,0 @@
-output cidr {
- value = "${var.network_cidr}"
-}
-
-output id {
- value = libvirt_network.network.id
-}
diff --git a/terraform/infrastructure/modules/libvirt_network/vars.tf b/terraform/infrastructure/modules/libvirt_network/vars.tf
@@ -1,21 +0,0 @@
-variable "network_name" {
- type = string
-}
-
-variable "network_mode" {
- type = string
- default = "nat"
-}
-
-variable "network_cidr" {
- type = string
-}
-
-variable "network_autostart" {
- type = bool
- default = true
-}
-
-variable "network_bridge_interface" {
- type = string
-}
diff --git a/terraform/modules/libvirt_host/main.tf b/terraform/modules/libvirt_host/main.tf
@@ -0,0 +1,64 @@
+resource "libvirt_volume" "volume" {
+ count = (var.volume_name != "" ? 1 : 0)
+ name = var.volume_name
+ pool = var.storage_pool
+ format = var.volume_format
+ size = var.volume_size
+ base_volume_id = (var.base_volume_id != "" ? var.base_volume_id : null)
+}
+
+resource "random_pet" "random" {
+ count = (var.cloudinit_template != "" ? 1 : 0)
+ separator = "_"
+}
+
+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-${random_pet.random[0].id}.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"]
+ }
+
+ #disk {
+ # volume_id = (libvirt_volume.volume[0].id != "" ? libvirt_volume.volume[0].id : null)
+ #}
+
+ #disk {
+ # file = (var.iso != "" ? var.iso : null)
+ # scsi = (var.iso != "" ? false : null)
+ #}
+
+ dynamic "disk" {
+ for_each = var.disks
+ iterator = disk
+ content {
+ #file = (disk.iso != "" ? disk.iso : null)
+ volume_id = (libvirt_volume.volume[0].id != "" ? libvirt_volume.volume[0].id : null)
+ }
+ }
+
+ 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/modules/libvirt_host/vars.tf b/terraform/modules/libvirt_host/vars.tf
@@ -0,0 +1,76 @@
+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
+ default = ""
+}
+
+variable "volume_size" {
+ type = number
+ default = 10737418240
+}
+
+variable "volume_format" {
+ type = string
+ default = "qcow2"
+}
+
+variable "volume_source" {
+ type = string
+ default = ""
+}
+
+variable "cloudinit_template" {
+ type = string
+ default = ""
+}
+
+variable "base_volume_id" {
+ type = string
+ default = ""
+}
+
+variable "iso" {
+ type = string
+ default = ""
+}
+
+variable "disks" {
+ type = list
+ default = []
+}
diff --git a/terraform/modules/libvirt_network/main.tf b/terraform/modules/libvirt_network/main.tf
@@ -0,0 +1,7 @@
+resource "libvirt_network" "network" {
+ name = "${var.network_name}"
+ mode = "${var.network_mode}"
+ addresses = ["${var.network_cidr}"]
+ autostart = "${var.network_autostart}"
+ bridge = "${var.network_bridge_interface}"
+}
diff --git a/terraform/modules/libvirt_network/outputs.tf b/terraform/modules/libvirt_network/outputs.tf
@@ -0,0 +1,7 @@
+output cidr {
+ value = "${var.network_cidr}"
+}
+
+output id {
+ value = libvirt_network.network.id
+}
diff --git a/terraform/modules/libvirt_network/vars.tf b/terraform/modules/libvirt_network/vars.tf
@@ -0,0 +1,21 @@
+variable "network_name" {
+ type = string
+}
+
+variable "network_mode" {
+ type = string
+ default = "nat"
+}
+
+variable "network_cidr" {
+ type = string
+}
+
+variable "network_autostart" {
+ type = bool
+ default = true
+}
+
+variable "network_bridge_interface" {
+ type = string
+}