diff options
author | Trygve Laugstøl <trygvis@inamo.no> | 2021-08-18 19:25:36 +0200 |
---|---|---|
committer | Trygve Laugstøl <trygvis@inamo.no> | 2021-08-18 19:25:36 +0200 |
commit | 6bee445a2ab132e778276ca21c76770de43ad17d (patch) | |
tree | d7ad66f8cece68efa5036e2e1cbb73fc8edd65b9 /terraform | |
parent | f0803cb1b11ac5f4c8bd30d0dea8ceccb7a72602 (diff) | |
download | infra-6bee445a2ab132e778276ca21c76770de43ad17d.tar.gz infra-6bee445a2ab132e778276ca21c76770de43ad17d.tar.bz2 infra-6bee445a2ab132e778276ca21c76770de43ad17d.tar.xz infra-6bee445a2ab132e778276ca21c76770de43ad17d.zip |
terraform/arius-kvm
Diffstat (limited to 'terraform')
-rw-r--r-- | terraform/.terraform.lock.hcl | 38 | ||||
-rw-r--r-- | terraform/arius-kvm/main.tf | 21 | ||||
-rw-r--r-- | terraform/arius-kvm/test1.tf | 100 | ||||
-rw-r--r-- | terraform/main.tf | 4 |
4 files changed, 163 insertions, 0 deletions
diff --git a/terraform/.terraform.lock.hcl b/terraform/.terraform.lock.hcl index aa81d62..d03222a 100644 --- a/terraform/.terraform.lock.hcl +++ b/terraform/.terraform.lock.hcl @@ -1,6 +1,44 @@ # This file is maintained automatically by "terraform init". # Manual edits may be lost in future updates. +provider "registry.terraform.io/dmacvicar/libvirt" { + version = "0.6.10" + constraints = "0.6.10" + hashes = [ + "h1:lPIBiMvzyFAg0nN67hCFMI7UELTy41UWY3ou35rS6vg=", + "zh:30445bfec552ef33521bde07217ecf3a52d48f4abcf9307a654e5b50e2f5ef79", + "zh:3c125a5cdc25253f9a8ec7b323681c1b2c74f0e3439acc6b049af162afde207a", + "zh:4539b89abe6cf522e9c50b7106bb47a2b25a74ff29076ac863d44f3c398f941b", + "zh:66dbe885d359d6f962ee8bef508c2c8df56d020021bd5aadc50f7a18ced93e15", + "zh:7472c1127eb5e2f8135a04763f2b2326cd944a61159595199613a5f260e495c1", + "zh:77777f45d205e4851b640d2f16297d832f47cf19cd1ba3bc7f0eacfbb8ff62df", + "zh:7f055105f0d5932851c4d5220b09b2248f24deb123f45d898757bc89b2f1b828", + "zh:92add3ccd015a8550f8a963e9b5a55874bc8dbe054bb005bb518e9b04c1d3da2", + "zh:9711d56c8edb5b781f76a30d4d17411d0be61846027aa18be61e6f2609e6a068", + "zh:aa4fb874d11f17228e64c60f7960366b7f8cc28a8df7a90ed2aa20d3601c5e43", + "zh:ab20312dcba1e604f950dd85e0c9361dcee6cce64038f9a95980722568425358", + "zh:dc4296f688d51380941917c57c78811bda8185777cc5e01d057a0d3f1aec9b05", + "zh:ec26c4ce3c9c1a3e20de55175c7729978da27b27627f273bd1de98beea8bd415", + ] +} + +provider "registry.terraform.io/hashicorp/template" { + version = "2.2.0" + hashes = [ + "h1:94qn780bi1qjrbC3uQtjJh3Wkfwd5+tTtJHOb7KTg9w=", + "zh:01702196f0a0492ec07917db7aaa595843d8f171dc195f4c988d2ffca2a06386", + "zh:09aae3da826ba3d7df69efeb25d146a1de0d03e951d35019a0f80e4f58c89b53", + "zh:09ba83c0625b6fe0a954da6fbd0c355ac0b7f07f86c91a2a97849140fea49603", + "zh:0e3a6c8e16f17f19010accd0844187d524580d9fdb0731f675ffcf4afba03d16", + "zh:45f2c594b6f2f34ea663704cc72048b212fe7d16fb4cfd959365fa997228a776", + "zh:77ea3e5a0446784d77114b5e851c970a3dde1e08fa6de38210b8385d7605d451", + "zh:8a154388f3708e3df5a69122a23bdfaf760a523788a5081976b3d5616f7d30ae", + "zh:992843002f2db5a11e626b3fc23dc0c87ad3729b3b3cff08e32ffb3df97edbde", + "zh:ad906f4cebd3ec5e43d5cd6dc8f4c5c9cc3b33d2243c89c5fc18f97f7277b51d", + "zh:c979425ddb256511137ecd093e23283234da0154b7fa8b21c2687182d9aea8b2", + ] +} + provider "registry.terraform.io/linode/linode" { version = "1.13.2" constraints = "~> 1.13" 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 +} diff --git a/terraform/main.tf b/terraform/main.tf index f3f0ddb..5319a6c 100644 --- a/terraform/main.tf +++ b/terraform/main.tf @@ -73,3 +73,7 @@ output "pg_backup_knot" { bucket : module.pg-backup-knot.bucket, } } + +module "arius-kvm" { + source = "./arius-kvm" +} |