terraform-k8s/roles/terraform/files/cloud-init.tf.j2

55 lines
1.3 KiB
Django/Jinja

resource "libvirt_cloudinit_disk" "cloud-init-{{ item.hostname }}" {
name = "cloud-init-{{ item.hostname }}.iso"
pool = "{{ libvirt_storage_pool }}"
user_data = "${data.template_file.user-data-{{ item.hostname }}.rendered}"
}
data "template_file" "user-data-{{ item.hostname }}" {
template = "${file("${path.module}/{{ item.hostname }}.cloud_init.cfg")}"
}
resource "libvirt_volume" "{{ item.hostname }}" {
name = "{{ item.hostname }}"
source = "{{ source_cloud_image_name }}"
pool = "{{ libvirt_storage_pool }}"
format = "qcow2"
}
resource "libvirt_domain" "domain-{{ item.hostname }}" {
name = "{{ item.hostname }}"
memory = "{{ item.memory }}"
vcpu = "{{ item.vcpu }}"
cloudinit = "${libvirt_cloudinit_disk.cloud-init-{{ item.hostname }}.id}"
console {
type = "pty"
target_port = "0"
target_type = "serial"
}
console {
type = "pty"
target_type = "virtio"
target_port = "1"
}
network_interface {
bridge = "{{ libvirt_network_bridge }}"
mac = "{{ item.mac_address }}"
}
boot_device {
dev = ["hd"]
}
disk {
volume_id = "${libvirt_volume.{{ item.hostname }}.id}"
}
graphics {
type = "spice"
listen_type = "address"
autoport = true
}
}