|
| 1 | +# -[Provider]-------------------------------------------------------------- |
| 2 | +provider "libvirt" { |
| 3 | + uri = "qemu:///system" |
| 4 | +} |
| 5 | + |
| 6 | +# -[Variables]------------------------------------------------------------- |
| 7 | +variable "hosts" { |
| 8 | + default = 1 |
| 9 | +} |
| 10 | + |
| 11 | +variable "hostname_format" { |
| 12 | + type = "string" |
| 13 | + default = "coreos%02d" |
| 14 | +} |
| 15 | + |
| 16 | +variable "libvirt_provider" { |
| 17 | + type = "string" |
| 18 | +} |
| 19 | + |
| 20 | +# -[Resources]------------------------------------------------------------- |
| 21 | +resource "libvirt_volume" "coreos-disk" { |
| 22 | + name = "${format(var.hostname_format, count.index + 1)}.qcow2" |
| 23 | + count = "${var.hosts}" |
| 24 | + base_volume_name = "coreos_production_qemu" |
| 25 | + pool = "default" |
| 26 | + format = "qcow2" |
| 27 | +} |
| 28 | + |
| 29 | +# Loading ignition configs in QEMU requires at least QEMU v2.6 |
| 30 | +resource "libvirt_ignition" "ignition" { |
| 31 | + name = "${format(var.hostname_format, count.index + 1)}-ignition" |
| 32 | + pool = "default" |
| 33 | + count = "${var.hosts}" |
| 34 | + content = "${element(data.ignition_config.startup.*.rendered, count.index)}" |
| 35 | +} |
| 36 | + |
| 37 | +# Create the virtual machines |
| 38 | +resource "libvirt_domain" "coreos-machine" { |
| 39 | + count = "${var.hosts}" |
| 40 | + name = "${format(var.hostname_format, count.index + 1)}" |
| 41 | + vcpu = "1" |
| 42 | + memory = "2048" |
| 43 | + |
| 44 | + ## Use qemu-agent in conjunction with the container |
| 45 | + #qemu_agent = true |
| 46 | + coreos_ignition = "${element(libvirt_ignition.ignition.*.id, count.index)}" |
| 47 | + |
| 48 | + disk { |
| 49 | + volume_id = "${element(libvirt_volume.coreos-disk.*.id, count.index)}" |
| 50 | + } |
| 51 | + |
| 52 | + graphics { |
| 53 | + ## Bug in linux up to 4.14-rc2 |
| 54 | + ## https://bugzilla.redhat.com/show_bug.cgi?id=1432684 |
| 55 | + ## No Spice/VNC available if more then one machine is generated at a time |
| 56 | + ## Comment the address line, uncomment the none line and the console block below |
| 57 | + #listen_type = "none" |
| 58 | + listen_type = "address" |
| 59 | + } |
| 60 | + |
| 61 | + ## Makes the tty0 available via `virsh console` |
| 62 | + #console { |
| 63 | + # type = "pty" |
| 64 | + # target_port = "0" |
| 65 | + #} |
| 66 | + |
| 67 | + network_interface { |
| 68 | + network_name = "default" |
| 69 | + |
| 70 | + # Requires qemu-agent container if network is not native to libvirt |
| 71 | + wait_for_lease = true |
| 72 | + } |
| 73 | + |
| 74 | + ## mounts filesystem local to the kvm host. used to patch in the |
| 75 | + ## qemu-guest-agent as docker container |
| 76 | + #filesystem { |
| 77 | + # source = "/srv/images/" |
| 78 | + # target = "qemu_docker_images" |
| 79 | + # readonly = true |
| 80 | + #} |
| 81 | +} |
| 82 | + |
| 83 | +# -[Output]------------------------------------------------------------- |
| 84 | +output "ipv4" { |
| 85 | + value = "${libvirt_domain.coreos-machine.*.network_interface.0.addresses}" |
| 86 | +} |
0 commit comments