tf-ansible-workflow

Terraform/Ansible Workflow for Libvirt
git clone https://git.in0rdr.ch/tf-ansible-workflow.git
Log | Files | Refs | Pull requests |Archive

vms-type2.tf (1550B)


      1 resource "libvirt_volume" "base_volume_type2" {
      2     name   = "${var.project}-base-type2"
      3     pool   = libvirt_pool.pool.name
      4     source = var.baseimage_type2
      5     format = var.baseimage_format
      6 
      7     # todo: required for "terraform destroy"
      8     depends_on = [libvirt_pool.pool]
      9 }
     10 
     11 resource "libvirt_volume" "volume_type2" {
     12     # unique image (based on backing file) for each host
     13     for_each       = toset(var.type2_hosts)
     14 
     15     name           = "${var.project}-cow-${each.value}"
     16     pool           = libvirt_pool.pool.name
     17     base_volume_id = libvirt_volume.base_volume_type2.id
     18     size           = var.disk
     19 }
     20 
     21 resource "libvirt_domain" "hosts_type2" {
     22     # create each host
     23     for_each = toset(var.type2_hosts)
     24 
     25     name   = each.value
     26     memory = var.memory
     27     vcpu   = var.vcpu
     28 
     29     cloudinit = libvirt_cloudinit_disk.commoninit.id
     30     qemu_agent = true
     31 
     32     network_interface {
     33         network_name   = libvirt_network.network.name
     34         wait_for_lease = true
     35     }
     36 
     37     # IMPORTANT: this is a known bug on cloud images, since they expect a console
     38     # we need to pass it
     39     # https://bugs.launchpad.net/cloud-images/+bug/1573095
     40     console {
     41         type        = "pty"
     42         target_port = "0"
     43         target_type = "serial"
     44     }
     45 
     46     console {
     47         type        = "pty"
     48         target_type = "virtio"
     49         target_port = "1"
     50     }
     51 
     52     disk {
     53         volume_id = libvirt_volume.volume_type2[each.value].id
     54     }
     55 
     56     graphics {
     57         type        = "spice"
     58         listen_type = "address"
     59         autoport    = true
     60     }
     61 }