ansible-debops-infrastructure

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

main.tf (1682B)


      1 resource "random_pet" "random_volume" {
      2   count     = (var.volume_source == "" ? 0 : 1)
      3   separator = "_"
      4 }
      5 
      6 resource "libvirt_volume" "base_volume" {
      7   count  = (var.volume_source == "" ? 0 : 1)
      8   name   = "base_volume_${random_pet.random_volume[0].id}"
      9   pool   = var.storage_pool
     10   format = var.volume_format
     11   source = var.volume_source
     12 }
     13 
     14 resource "libvirt_volume" "volume" {
     15   name           = var.volume_name
     16   pool           = var.storage_pool
     17   format         = var.volume_format
     18   size           = var.volume_size
     19   base_volume_id = (var.volume_source != "" ? libvirt_volume.base_volume[0].id : null)
     20 }
     21 
     22 resource "random_pet" "random" {
     23   count     = (var.cloudinit_template != "" ? 1 : 0)
     24   separator = "_"
     25 }
     26 
     27 data "template_file" "user_data" {
     28   count    = (var.cloudinit_template != "" ? 1 : 0)
     29   template = var.cloudinit_template
     30 }
     31 
     32 resource "libvirt_cloudinit_disk" "cloud_init" {
     33   count     = (var.cloudinit_template != "" ? 1 : 0)
     34   name      = "cloud-init-${random_pet.random[0].id}.iso"
     35   user_data = data.template_file.user_data[count.index].rendered
     36 }
     37 
     38 resource "libvirt_domain" "libvirt_host" {
     39   name      = var.host_name
     40   memory    = var.host_memory
     41   vcpu      = var.host_vcpu
     42   autostart = var.host_autostart
     43   cloudinit = (var.cloudinit_template != "" ? libvirt_cloudinit_disk.cloud_init[0].id : null)
     44 
     45   boot_device {
     46     dev = ["hd"]
     47   }
     48 
     49   disk {
     50     volume_id = libvirt_volume.volume.id
     51   }
     52 
     53   network_interface {
     54     network_id = (var.network_id != "" ? var.network_id : null)
     55     addresses  = (var.network_id != "" ? [cidrhost(var.network_cidr, var.network_host)] : null)
     56   }
     57 
     58   graphics {
     59     type        = "spice"
     60     listen_type = "none"
     61   }
     62 }