aboutsummaryrefslogtreecommitdiff
path: root/terraform/arius-kvm
diff options
context:
space:
mode:
Diffstat (limited to 'terraform/arius-kvm')
-rw-r--r--terraform/arius-kvm/main.tf21
-rw-r--r--terraform/arius-kvm/test1.tf100
2 files changed, 121 insertions, 0 deletions
diff --git a/terraform/arius-kvm/main.tf b/terraform/arius-kvm/main.tf
new file mode 100644
index 0000000..afe402f
--- /dev/null
+++ b/terraform/arius-kvm/main.tf
@@ -0,0 +1,21 @@
+terraform {
+ required_providers {
+ libvirt = {
+ source = "dmacvicar/libvirt"
+ version = "0.6.10"
+ }
+ }
+}
+
+provider "libvirt" {
+ # https://github.com/dmacvicar/terraform-provider-libvirt/issues/864
+ # uri = "qemu+ssh://arius.vpn.trygvis.io/system"
+
+ # rm libvirt-arius.sock; ssh -nNT -L "$(pwd)/libvirt-arius.sock:/var/run/libvirt/libvirt-sock" arius.vpn.trygvis.io
+ uri = "qemu+unix:///session?socket=${path.root}/libvirt-arius.sock"
+}
+
+resource "libvirt_volume" "debian-10" {
+ name = "debian-10-openstack-amd64.qcow2"
+ source = "https://cloud.debian.org/cdimage/openstack/current-10/debian-10-openstack-amd64.qcow2"
+}
diff --git a/terraform/arius-kvm/test1.tf b/terraform/arius-kvm/test1.tf
new file mode 100644
index 0000000..d2d6702
--- /dev/null
+++ b/terraform/arius-kvm/test1.tf
@@ -0,0 +1,100 @@
+resource "libvirt_network" "terraform" {
+ name = "terraform"
+ mode = "nat"
+ addresses = ["10.17.3.0/24"]
+}
+
+resource "libvirt_domain" "test1" {
+ name = "test1"
+
+ # memory = "1024"
+ # vcpu = 1
+
+ cloudinit = libvirt_cloudinit_disk.commoninit.id
+
+ network_interface {
+ network_name = "default"
+ }
+
+ network_interface {
+ hostname = "wat"
+ network_id = libvirt_network.terraform.id
+ addresses = ["10.17.3.10"]
+ }
+
+ console {
+ type = "pty"
+ target_port = "0"
+ target_type = "serial"
+ }
+
+ console {
+ type = "pty"
+ target_type = "virtio"
+ target_port = "1"
+ }
+
+ disk {
+ volume_id = libvirt_volume.test1-root.id
+ scsi = "true"
+ }
+
+ graphics {
+ type = "spice"
+ listen_type = "address"
+ autoport = true
+ }
+
+# xml {
+# xslt = <<-EOF
+# <?xml version="1.0" ?>
+# <xsl:stylesheet version="1.0"
+# xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
+# <xsl:output omit-xml-declaration="yes" indent="yes"/>
+# <xsl:template match="node()|@*">
+# <xsl:copy>
+# <xsl:apply-templates select="node()|@*"/>
+# </xsl:copy>
+# </xsl:template>
+#
+# <xsl:template match="/domain/devices/interface[@type='network']/model/@type">
+# <xsl:attribute name="target">
+# <xsl:value-of select="'lan0'"/>
+# </xsl:attribute>
+# </xsl:template>
+#
+# </xsl:stylesheet>
+# EOF
+# }
+}
+
+resource "libvirt_volume" "test1-root" {
+ name = "test1-root.qcow2"
+ base_volume_id = libvirt_volume.debian-10.id
+}
+
+resource "libvirt_cloudinit_disk" "commoninit" {
+ name = "commoninit.iso"
+ user_data = data.template_file.user_data.rendered
+ network_config = data.template_file.network_config.rendered
+ # pool = libvirt_pool.ubuntu.name
+}
+
+data "template_file" "user_data" {
+ template = <<-EOF
+ #cloud-config
+ # vim: syntax=yaml
+ # ---> https://cloudinit.readthedocs.io/en/latest/topics/examples.html
+ ssh_authorized_keys:
+ - ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIL3UZyrbXX7WMHqcZCRspkoSIfB6egrbOxXPf1zyZkAw trygvis@arius-v4
+ EOF
+}
+
+data "template_file" "network_config" {
+ template = <<-EOF
+ version: 2
+ ethernets:
+ ens3:
+ dhcp4: true
+ EOF
+}