diff options
Diffstat (limited to 'terraform/libvirt/mini_environment/main.tf')
-rw-r--r-- | terraform/libvirt/mini_environment/main.tf | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/terraform/libvirt/mini_environment/main.tf b/terraform/libvirt/mini_environment/main.tf new file mode 100644 index 0000000..00c3394 --- /dev/null +++ b/terraform/libvirt/mini_environment/main.tf @@ -0,0 +1,83 @@ +variable "backend_remote_state_address" { + type = "string" +} + +variable "machine_name" { + type = "string" +} + +variable "host_name" { + type = "string" +} + +variable "uri" { + type = "string" +} + +variable "vm_image_and_system" { + type = "string" +} + +terraform { + backend "http" {} +} + +provider "libvirt" { + uri = "${var.uri}" +} + +data "terraform_remote_state" "backend" { + backend = "http" + config { + address = "${var.backend_remote_state_address}" + } +} + +resource "local_file" "dnsmasq-config" { + content = "address=/${var.host_name}/${libvirt_domain.main.network_interface.0.addresses.0}" + filename = "/etc/NetworkManager/dnsmasq.d/${var.host_name}.conf" +} + +resource "libvirt_domain" "main" { + name = "${var.machine_name}" + memory = "8196" + vcpu = 4 + + kernel = "${var.vm_image_and_system}/system/kernel/bzImage" + initrd = "${var.vm_image_and_system}/system/initrd" + + cmdline { + "--root" = "/dev/vda1" + "--system" = "${var.vm_image_and_system}/system" + "--load" = "${var.vm_image_and_system}/system/boot" + } + + filesystem { + source = "/gnu/store" + target = "TAG_gnu_store" + readonly = true + accessmode = "passthrough" + } + + disk { + file = "${var.vm_image_and_system}/image" + readonly = true + } + + network_interface { + network_name = "${data.terraform_remote_state.backend.network_name}" + wait_for_lease = true + } + + console { + type = "pty" + target_port = "0" + target_type = "serial" + } + + console { + type = "pty" + target_type = "virtio" + target_port = "1" + } +} |