ansible-debops-infrastructure

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

commit 09624b2981a45c138fd75d2068603aab4061942f
parent 8e4330637e62f05c1de578b63e9e4f788392e008
Author: Dionysis Grigoropoulos <dgrig@erethon.com>
Date:   Thu, 24 Jan 2019 21:38:22 +0200

tf: Seperate dev and production environments

Diffstat:
terraform/infrastructure/README.org | 2+-
terraform/infrastructure/dev/main.tf | 85+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
terraform/infrastructure/dev/variables.tf | 19+++++++++++++++++++
terraform/infrastructure/main.tf | 119-------------------------------------------------------------------------------
terraform/infrastructure/variables.tf | 19-------------------
5 files changed, 105 insertions(+), 139 deletions(-)

diff --git a/terraform/infrastructure/README.org b/terraform/infrastructure/README.org @@ -4,7 +4,7 @@ - [[https://www.terraform.io][Terraform]] - [[https://github.com/dmacvicar/terraform-provider-libvirt][Terraform libvirt provider]] - A remote host running =libvirtd= -- =netcat-openbsd= package if the remote is a Debian host =asda= +- =netcat-openbsd= package if the remote is a Debian host * Spawning hosts Create =terraform.tfvars= if necessary with your custom variables and then run: diff --git a/terraform/infrastructure/dev/main.tf b/terraform/infrastructure/dev/main.tf @@ -0,0 +1,85 @@ +provider "libvirt" { + uri = "${var.libvirt_uri}" +} + +resource "libvirt_network" "dev_network" { + name = "dev_network" + mode = "nat" + addresses = "${var.libvirt_cidr}" + autostart = true + bridge = "virbr1" +} + +resource "libvirt_volume" "debian_dev" { + name = "debian_dev" + pool = "${var.libvirt_storage_pool}" + format = "qcow2" + size = 10737418240 +} + +resource "libvirt_volume" "obsd_dev" { + name = "obsd_dev" + pool = "${var.libvirt_storage_pool}" + format = "qcow2" + size = 10737418240 +} + +resource "libvirt_volume" "obsd_dn42" { + name = "obsd_dn42" + pool = "${var.libvirt_storage_pool}" + format = "qcow2" + size = 10737418240 +} + +resource "libvirt_domain" "obsd_dev_domain" { + name = "obsd_dev" + memory = "1024" + vcpu = 2 + autostart = "true" + + boot_device { + dev = ["hd"] + } + + ## Not needed after initial installation + ## disk { + ## file = "${var.openbsd_iso}" + ## } + + disk { + volume_id = "${libvirt_volume.obsd_dev.id}" + } + network_interface { + network_id = "${libvirt_network.dev_network.id}" + addresses = ["192.168.199.2"] + } + graphics { + type = "spice" + listen_type = "none" + } +} + +resource "libvirt_domain" "debian_dev_domain" { + name = "debian_dev" + memory = "512" + vcpu = 1 + autostart = "true" + + boot_device { + dev = ["hd"] + } + + disk { + volume_id = "${libvirt_volume.debian_dev.id}" + } + + network_interface { + network_id = "${libvirt_network.dev_network.id}" + addresses = ["192.168.199.4"] + } + + graphics { + type = "spice" + listen_type = "none" + } +} diff --git a/terraform/infrastructure/dev/variables.tf b/terraform/infrastructure/dev/variables.tf @@ -0,0 +1,19 @@ +variable "libvirt_uri" { + description = "URI for libvirt to use" + default = "qemu+ssh://user@host/system" +} + +variable "libvirt_storage_pool" { + description = "Storage pool to use for VM disks" + default = "tf_pool" +} + +variable "libvirt_cidr" { + description = "Network CIDR to use for VMs" + default = ["192.168.199.0/24"] +} + +variable "openbsd_iso" { + description = "OpenBSD installation ISO to use" + default = "/data/iso/install64.iso" +} diff --git a/terraform/infrastructure/main.tf b/terraform/infrastructure/main.tf @@ -1,119 +0,0 @@ -provider "libvirt" { - uri = "${var.libvirt_uri}" -} - -resource "libvirt_volume" "debian_jenkins" { - name = "debian_jenkins" - pool = "${var.libvirt_storage_pool}" - format = "qcow2" - size = 21474836480 -} - -resource "libvirt_volume" "debian_dev" { - name = "debian_dev" - pool = "${var.libvirt_storage_pool}" - format = "qcow2" - size = 10737418240 -} - -resource "libvirt_volume" "obsd_dev" { - name = "obsd_dev" - pool = "${var.libvirt_storage_pool}" - format = "qcow2" - size = 10737418240 -} - -resource "libvirt_network" "dev_network" { - name = "dev_network" - mode = "nat" - addresses = "${var.libvirt_cidr}" - autostart = true - bridge = "virbr1" -} - -resource "libvirt_volume" "obsd_dn42" { - name = "obsd_dn42" - pool = "${var.libvirt_storage_pool}" - format = "qcow2" - size = 10737418240 -} - -resource "libvirt_domain" "obsd_dev_domain" { - name = "obsd_dev" - memory = "1024" - vcpu = 2 - autostart = "true" - - boot_device { - dev = ["hd"] - } - - ## Not needed after initial installation - ## disk { - ## file = "${var.openbsd_iso}" - ## } - - disk { - volume_id = "${libvirt_volume.obsd_dev.id}" - } - - network_interface { - network_id = "${libvirt_network.dev_network.id}" - addresses = ["192.168.199.2"] - } - - graphics { - type = "spice" - listen_type = "none" - } -} - -resource "libvirt_domain" "debian_jenkins_domain" { - name = "debian_jenkins" - memory = "2048" - vcpu = 2 - autostart = "true" - - boot_device { - dev = ["hd"] - } - - disk { - volume_id = "${libvirt_volume.debian_jenkins.id}" - } - - network_interface { - network_id = "${libvirt_network.dev_network.id}" - addresses = ["192.168.199.3"] - } - - graphics { - type = "spice" - listen_type = "none" - } -} - -resource "libvirt_domain" "debian_dev_domain" { - name = "debian_dev" - memory = "512" - vcpu = 1 - autostart = "true" - - boot_device { - dev = ["hd"] - } - - disk { - volume_id = "${libvirt_volume.debian_dev.id}" - } - - network_interface { - network_id = "${libvirt_network.dev_network.id}" - addresses = ["192.168.199.4"] - } - - graphics { - type = "spice" - listen_type = "none" - } -} diff --git a/terraform/infrastructure/variables.tf b/terraform/infrastructure/variables.tf @@ -1,19 +0,0 @@ -variable "libvirt_uri" { - description = "URI for libvirt to use" - default = "qemu+ssh://user@host/system" -} - -variable "libvirt_storage_pool" { - description = "Storage pool to use for VM disks" - default = "tf_pool" -} - -variable "libvirt_cidr" { - description = "Network CIDR to use for VMs" - default = ["192.168.199.0/24"] -} - -variable "openbsd_iso" { - description = "OpenBSD installation ISO to use" - default = "/data/iso/install64.iso" -}