infra_code

infrastructure-as-code
git clone git://git.pyratebeard.net/infra_code.git
Log | Files | Refs | README

infra.tf (1075B)


      1 resource "libvirt_volume" "base-debian12-qcow2" {
      2 	name = "debian-12-genericcloud-amd64.qcow2"
      3 	pool = "labfs"
      4 	source = "http://cloud.debian.org/images/cloud/bookworm/latest/debian-12-genericcloud-amd64.qcow2"
      5 	format = "qcow2"
      6 }
      7 
      8 resource "libvirt_volume" "debian12-qcow2" {
      9 	name = "${var.vm_name}.qcow2"
     10 	pool = "labfs"
     11 	format = "qcow2"
     12 	size = var.vm_size
     13 	base_volume_id = libvirt_volume.base-debian12-qcow2.id
     14 }
     15 
     16 data "template_file" "user_data" {
     17 	template = "${file("${path.module}/cloud_init.cfg")}"
     18 	vars = {
     19 		hostname = var.vm_name
     20 	}
     21 }
     22 
     23 resource "libvirt_cloudinit_disk" "commoninit" {
     24 	name = "commoninit.iso"
     25 	pool = "labfs"
     26 	user_data = "${data.template_file.user_data.rendered}"
     27 }
     28 
     29 resource "libvirt_domain" "debian12" {
     30 	name = var.vm_name
     31 	memory = var.vm_mem
     32 	vcpu = var.vm_vcpus
     33 
     34 	network_interface {
     35 		network_name = "default"
     36 		wait_for_lease = true
     37 	}
     38 
     39 	disk {
     40 		volume_id = "${libvirt_volume.debian12-qcow2.id}"
     41 	}
     42 
     43 	cloudinit = "${libvirt_cloudinit_disk.commoninit.id}"
     44 
     45 	console {
     46 		type = "pty"
     47 		target_type = "serial"
     48 		target_port = "0"
     49 	}
     50 }