commit bc72c32c23d65ae0ed5f2d0159cbc2b6d95a94ea Author: Tobias Kurze Date: Thu May 20 20:08:54 2021 +0200 initial diff --git a/.terraform.lock.hcl b/.terraform.lock.hcl new file mode 100644 index 0000000..b5e3a99 --- /dev/null +++ b/.terraform.lock.hcl @@ -0,0 +1,27 @@ +# 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.3" + constraints = "0.6.3" + hashes = [ + "h1:bZS1zAHco1XJwU1bEZXWpwl7cExfroZ0vltmhMgV4Sw=", + ] +} + +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", + ] +} diff --git a/.terraform/providers/registry.terraform.io/dmacvicar/libvirt/0.6.3/linux_amd64 b/.terraform/providers/registry.terraform.io/dmacvicar/libvirt/0.6.3/linux_amd64 new file mode 120000 index 0000000..c4432c7 --- /dev/null +++ b/.terraform/providers/registry.terraform.io/dmacvicar/libvirt/0.6.3/linux_amd64 @@ -0,0 +1 @@ +/usr/share/terraform/plugins/registry.terraform.io/dmacvicar/libvirt/0.6.3/linux_amd64 \ No newline at end of file diff --git a/.terraform/providers/registry.terraform.io/hashicorp/template/2.2.0/linux_amd64/terraform-provider-template_v2.2.0_x4 b/.terraform/providers/registry.terraform.io/hashicorp/template/2.2.0/linux_amd64/terraform-provider-template_v2.2.0_x4 new file mode 100755 index 0000000..24c90e6 Binary files /dev/null and b/.terraform/providers/registry.terraform.io/hashicorp/template/2.2.0/linux_amd64/terraform-provider-template_v2.2.0_x4 differ diff --git a/ansible.cfg b/ansible.cfg new file mode 100644 index 0000000..807b05b --- /dev/null +++ b/ansible.cfg @@ -0,0 +1,6 @@ +[defaults] +host_key_checking = False +ansible_port = 22 +ansible_user = ubuntu +ansible_ssh_private_key_file = ~/.ssh/id_rsa +ansible_python_interpreter = /usr/bin/python3 diff --git a/ansible/playbook.yml b/ansible/playbook.yml new file mode 100644 index 0000000..90bbec7 --- /dev/null +++ b/ansible/playbook.yml @@ -0,0 +1,24 @@ +--- +# https://docs.ansible.com/ansible/latest/collections/ansible/builtin/apt_module.html +# https://docs.ansible.com/ansible/latest/collections/ansible/builtin/systemd_module.html#examples +- hosts: nginx + become: yes + become_user: root + become_method: sudo + tasks: + - name: Install nginx + apt: + name: nginx + state: latest + update_cache: yes + + - name: Enable service nginx and ensure it is not masked + systemd: + name: nginx + enabled: yes + masked: no + + - name: ensure nginx is started + systemd: + state: started + name: nginx diff --git a/config/cloud_init.yml b/config/cloud_init.yml new file mode 100644 index 0000000..47e88bb --- /dev/null +++ b/config/cloud_init.yml @@ -0,0 +1,27 @@ +#cloud-config +# vim: syntax=yaml +# examples: +# https://cloudinit.readthedocs.io/en/latest/topics/examples.html +bootcmd: + - echo 192.168.0.1 gw.homedns.xyz >> /etc/hosts +runcmd: + - [ ls, -l, / ] + - [ sh, -xc, "echo $(date) ': hello world!'" ] +ssh_pwauth: true +disable_root: false +chpasswd: + list: | + root:password + expire: false +package_update: true +packages: ['qemu-guest-agent'] +users: + - name: ubuntu + sudo: ALL=(ALL) NOPASSWD:ALL + groups: users, admin + home: /home/ubuntu + shell: /bin/bash + lock_passwd: false + ssh-authorized-keys: + - ssh-rsa AAAA ...your-public-ssh-key-goes-here... user@host +final_message: "The system is finally up, after $UPTIME seconds" diff --git a/config/network_config.yml b/config/network_config.yml new file mode 100644 index 0000000..5b2cbca --- /dev/null +++ b/config/network_config.yml @@ -0,0 +1,4 @@ +version: 2 +ethernets: + ens3: + dhcp4: true diff --git a/main.tf b/main.tf new file mode 100644 index 0000000..e722682 --- /dev/null +++ b/main.tf @@ -0,0 +1,96 @@ +provider "libvirt" { + #uri = "qemu+ssh://deploys@ams-kvm-remote-host/system" + uri = "qemu+ssh://tobias@localhost/system" +} + +resource "libvirt_pool" "tf_pool" { + name = "tf_pool" + type = "dir" + path = var.libvirt_disk_path +} + +resource "libvirt_volume" "ubuntu-qcow2" { + name = "ubuntu-qcow2" + pool = libvirt_pool.tf_pool.name + source = var.ubuntu_18_img_url + format = "qcow2" +} + +data "template_file" "user_data" { + template = file("${path.module}/config/cloud_init.yml") +} + +data "template_file" "network_config" { + template = file("${path.module}/config/network_config.yml") +} + +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.tf_pool.name +} + +resource "libvirt_domain" "domain-ubuntu" { + qemu_agent = true + name = var.vm_hostname + memory = "512" + vcpu = 1 + + cloudinit = libvirt_cloudinit_disk.commoninit.id + + network_interface { + network_name = "host-bridge" + wait_for_lease = true + hostname = var.vm_hostname + } + + console { + type = "pty" + target_port = "0" + target_type = "serial" + } + + console { + type = "pty" + target_type = "virtio" + target_port = "1" + } + + disk { + volume_id = libvirt_volume.ubuntu-qcow2.id + } + + graphics { + type = "spice" + listen_type = "address" + autoport = true + } + + provisioner "remote-exec" { + inline = [ + "echo 'Hello World'" + ] + + connection { + type = "ssh" + user = var.ssh_username + host = libvirt_domain.domain-ubuntu.network_interface[0].addresses[0] + private_key = file(var.ssh_private_key) + bastion_host = "ams-kvm-remote-host" + bastion_user = "deploys" + bastion_private_key = file("~/.ssh/deploys.pem") + timeout = "2m" + } + } + + provisioner "local-exec" { + command = < nginx.ini + echo "${libvirt_domain.domain-ubuntu.network_interface[0].addresses[0]}" >> nginx.ini + echo "[nginx:vars]" >> nginx.ini + echo "ansible_ssh_common_args='-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o ProxyCommand=\"ssh -W %h:%p -q ams-kvm-remote-host\"'" >> nginx.ini + ansible-playbook -u ${var.ssh_username} --private-key ${var.ssh_private_key} -i nginx.ini ansible/playbook.yml + EOT + } +} diff --git a/outputs.tf b/outputs.tf new file mode 100644 index 0000000..14b3ad2 --- /dev/null +++ b/outputs.tf @@ -0,0 +1,7 @@ +output "ip" { + value = libvirt_domain.domain-ubuntu.network_interface[0].addresses[0] +} + +output "url" { + value = "http://${libvirt_domain.domain-ubuntu.network_interface[0].addresses[0]}" +} diff --git a/providers.tf b/providers.tf new file mode 100644 index 0000000..4fff20c --- /dev/null +++ b/providers.tf @@ -0,0 +1,8 @@ +terraform { + required_providers { + libvirt = { + source = "dmacvicar/libvirt" + version = "0.6.3" + } + } +} diff --git a/terraform.tfstate b/terraform.tfstate new file mode 100644 index 0000000..e89320b --- /dev/null +++ b/terraform.tfstate @@ -0,0 +1,223 @@ +{ + "version": 4, + "terraform_version": "0.15.3", + "serial": 21, + "lineage": "af915bb1-8f21-5cbd-1e34-2c8a151a91f9", + "outputs": {}, + "resources": [ + { + "mode": "data", + "type": "template_file", + "name": "network_config", + "provider": "provider[\"registry.terraform.io/hashicorp/template\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "filename": null, + "id": "b36a1372ce4ea68b514354202c26c0365df9a17f25cd5acdeeaea525cd913edc", + "rendered": "version: 2\nethernets:\n ens3:\n dhcp4: true\n", + "template": "version: 2\nethernets:\n ens3:\n dhcp4: true\n", + "vars": null + }, + "sensitive_attributes": [] + } + ] + }, + { + "mode": "data", + "type": "template_file", + "name": "user_data", + "provider": "provider[\"registry.terraform.io/hashicorp/template\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "filename": null, + "id": "e2cb3caeafadc71aab833600ac7612d9c41b755e2549ad47a8d3ae2a625c4821", + "rendered": "#cloud-config\n# vim: syntax=yaml\n# examples:\n# https://cloudinit.readthedocs.io/en/latest/topics/examples.html\nbootcmd:\n - echo 192.168.0.1 gw.homedns.xyz \u003e\u003e /etc/hosts\nruncmd:\n - [ ls, -l, / ]\n - [ sh, -xc, \"echo $(date) ': hello world!'\" ]\nssh_pwauth: true\ndisable_root: false\nchpasswd:\n list: |\n root:password\n expire: false\npackage_update: true\npackages: ['qemu-guest-agent']\nusers:\n - name: ubuntu\n sudo: ALL=(ALL) NOPASSWD:ALL\n groups: users, admin\n home: /home/ubuntu\n shell: /bin/bash\n lock_passwd: false\n ssh-authorized-keys:\n - ssh-rsa AAAA ...your-public-ssh-key-goes-here... user@host\nfinal_message: \"The system is finally up, after $UPTIME seconds\"\n", + "template": "#cloud-config\n# vim: syntax=yaml\n# examples:\n# https://cloudinit.readthedocs.io/en/latest/topics/examples.html\nbootcmd:\n - echo 192.168.0.1 gw.homedns.xyz \u003e\u003e /etc/hosts\nruncmd:\n - [ ls, -l, / ]\n - [ sh, -xc, \"echo $(date) ': hello world!'\" ]\nssh_pwauth: true\ndisable_root: false\nchpasswd:\n list: |\n root:password\n expire: false\npackage_update: true\npackages: ['qemu-guest-agent']\nusers:\n - name: ubuntu\n sudo: ALL=(ALL) NOPASSWD:ALL\n groups: users, admin\n home: /home/ubuntu\n shell: /bin/bash\n lock_passwd: false\n ssh-authorized-keys:\n - ssh-rsa AAAA ...your-public-ssh-key-goes-here... user@host\nfinal_message: \"The system is finally up, after $UPTIME seconds\"\n", + "vars": null + }, + "sensitive_attributes": [] + } + ] + }, + { + "mode": "managed", + "type": "libvirt_cloudinit_disk", + "name": "commoninit", + "provider": "provider[\"registry.terraform.io/dmacvicar/libvirt\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "id": "/mnt/data1/libvirt_tf_volumes/commoninit.iso;60a65440-35d1-aff5-ed2f-1cf5899e0adc", + "meta_data": "", + "name": "commoninit.iso", + "network_config": "version: 2\nethernets:\n ens3:\n dhcp4: true\n", + "pool": "tf_pool", + "user_data": "#cloud-config\n# vim: syntax=yaml\n# examples:\n# https://cloudinit.readthedocs.io/en/latest/topics/examples.html\nbootcmd:\n - echo 192.168.0.1 gw.homedns.xyz \u003e\u003e /etc/hosts\nruncmd:\n - [ ls, -l, / ]\n - [ sh, -xc, \"echo $(date) ': hello world!'\" ]\nssh_pwauth: true\ndisable_root: false\nchpasswd:\n list: |\n root:password\n expire: false\npackage_update: true\npackages: ['qemu-guest-agent']\nusers:\n - name: ubuntu\n sudo: ALL=(ALL) NOPASSWD:ALL\n groups: users, admin\n home: /home/ubuntu\n shell: /bin/bash\n lock_passwd: false\n ssh-authorized-keys:\n - ssh-rsa AAAA ...your-public-ssh-key-goes-here... user@host\nfinal_message: \"The system is finally up, after $UPTIME seconds\"\n" + }, + "sensitive_attributes": [], + "private": "bnVsbA==", + "dependencies": [ + "data.template_file.network_config", + "data.template_file.user_data", + "libvirt_pool.tf_pool" + ] + } + ] + }, + { + "mode": "managed", + "type": "libvirt_domain", + "name": "domain-ubuntu", + "provider": "provider[\"registry.terraform.io/dmacvicar/libvirt\"]", + "instances": [ + { + "status": "tainted", + "schema_version": 0, + "attributes": { + "arch": "x86_64", + "autostart": false, + "boot_device": [], + "cloudinit": "/mnt/data1/libvirt_tf_volumes/commoninit.iso;60a65440-35d1-aff5-ed2f-1cf5899e0adc", + "cmdline": null, + "console": [ + { + "source_host": "127.0.0.1", + "source_path": "", + "source_service": "0", + "target_port": "0", + "target_type": "serial", + "type": "pty" + }, + { + "source_host": "127.0.0.1", + "source_path": "", + "source_service": "0", + "target_port": "1", + "target_type": "virtio", + "type": "pty" + } + ], + "coreos_ignition": null, + "cpu": null, + "description": "", + "disk": [ + { + "block_device": "", + "file": "", + "scsi": false, + "url": "", + "volume_id": "/mnt/data1/libvirt_tf_volumes/ubuntu-qcow2", + "wwn": "" + } + ], + "emulator": "/usr/bin/qemu-system-x86_64", + "filesystem": [], + "firmware": "", + "fw_cfg_name": "opt/com.coreos/config", + "graphics": [ + { + "autoport": true, + "listen_address": "127.0.0.1", + "listen_type": "address", + "type": "spice" + } + ], + "id": "7bb804b9-7827-465b-9c21-dc2db6417052", + "initrd": "", + "kernel": "", + "machine": "pc", + "memory": 512, + "metadata": null, + "name": "terraform-kvm-ansible", + "network_interface": [ + { + "addresses": [ + "192.168.20.64", + "fe80::5054:ff:fe22:2ae7" + ], + "bridge": "br0", + "hostname": "terraform-kvm-ansible", + "mac": "52:54:00:22:2A:E7", + "macvtap": "", + "network_id": "", + "network_name": "", + "passthrough": "", + "vepa": "", + "wait_for_lease": true + } + ], + "nvram": [], + "qemu_agent": true, + "running": true, + "timeouts": null, + "vcpu": 1, + "video": [], + "xml": [] + }, + "sensitive_attributes": [], + "private": "eyJlMmJmYjczMC1lY2FhLTExZTYtOGY4OC0zNDM2M2JjN2M0YzAiOnsiY3JlYXRlIjozMDAwMDAwMDAwMDB9fQ==", + "dependencies": [ + "libvirt_cloudinit_disk.commoninit", + "libvirt_volume.ubuntu-qcow2" + ] + } + ] + }, + { + "mode": "managed", + "type": "libvirt_pool", + "name": "tf_pool", + "provider": "provider[\"registry.terraform.io/dmacvicar/libvirt\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "allocation": 221347414016, + "available": null, + "capacity": 1967792529408, + "id": "40b537c5-c26e-49d3-9660-3bfe18eb0907", + "name": "tf_pool", + "path": "/mnt/data1/libvirt_tf_volumes", + "type": "dir", + "xml": [] + }, + "sensitive_attributes": [], + "private": "bnVsbA==" + } + ] + }, + { + "mode": "managed", + "type": "libvirt_volume", + "name": "ubuntu-qcow2", + "provider": "provider[\"registry.terraform.io/dmacvicar/libvirt\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "base_volume_id": null, + "base_volume_name": null, + "base_volume_pool": null, + "format": "qcow2", + "id": "/mnt/data1/libvirt_tf_volumes/ubuntu-qcow2", + "name": "ubuntu-qcow2", + "pool": "tf_pool", + "size": 2361393152, + "source": "http://cloud-images.ubuntu.com/releases/bionic/release-20191008/ubuntu-18.04-server-cloudimg-amd64.img", + "xml": [] + }, + "sensitive_attributes": [], + "private": "bnVsbA==", + "dependencies": [ + "libvirt_pool.tf_pool" + ] + } + ] + } + ] +} diff --git a/terraform.tfstate.backup b/terraform.tfstate.backup new file mode 100644 index 0000000..64cc64e --- /dev/null +++ b/terraform.tfstate.backup @@ -0,0 +1,220 @@ +{ + "version": 4, + "terraform_version": "0.15.3", + "serial": 18, + "lineage": "af915bb1-8f21-5cbd-1e34-2c8a151a91f9", + "outputs": {}, + "resources": [ + { + "mode": "data", + "type": "template_file", + "name": "network_config", + "provider": "provider[\"registry.terraform.io/hashicorp/template\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "filename": null, + "id": "b36a1372ce4ea68b514354202c26c0365df9a17f25cd5acdeeaea525cd913edc", + "rendered": "version: 2\nethernets:\n ens3:\n dhcp4: true\n", + "template": "version: 2\nethernets:\n ens3:\n dhcp4: true\n", + "vars": null + }, + "sensitive_attributes": [] + } + ] + }, + { + "mode": "data", + "type": "template_file", + "name": "user_data", + "provider": "provider[\"registry.terraform.io/hashicorp/template\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "filename": null, + "id": "e2cb3caeafadc71aab833600ac7612d9c41b755e2549ad47a8d3ae2a625c4821", + "rendered": "#cloud-config\n# vim: syntax=yaml\n# examples:\n# https://cloudinit.readthedocs.io/en/latest/topics/examples.html\nbootcmd:\n - echo 192.168.0.1 gw.homedns.xyz \u003e\u003e /etc/hosts\nruncmd:\n - [ ls, -l, / ]\n - [ sh, -xc, \"echo $(date) ': hello world!'\" ]\nssh_pwauth: true\ndisable_root: false\nchpasswd:\n list: |\n root:password\n expire: false\npackage_update: true\npackages: ['qemu-guest-agent']\nusers:\n - name: ubuntu\n sudo: ALL=(ALL) NOPASSWD:ALL\n groups: users, admin\n home: /home/ubuntu\n shell: /bin/bash\n lock_passwd: false\n ssh-authorized-keys:\n - ssh-rsa AAAA ...your-public-ssh-key-goes-here... user@host\nfinal_message: \"The system is finally up, after $UPTIME seconds\"\n", + "template": "#cloud-config\n# vim: syntax=yaml\n# examples:\n# https://cloudinit.readthedocs.io/en/latest/topics/examples.html\nbootcmd:\n - echo 192.168.0.1 gw.homedns.xyz \u003e\u003e /etc/hosts\nruncmd:\n - [ ls, -l, / ]\n - [ sh, -xc, \"echo $(date) ': hello world!'\" ]\nssh_pwauth: true\ndisable_root: false\nchpasswd:\n list: |\n root:password\n expire: false\npackage_update: true\npackages: ['qemu-guest-agent']\nusers:\n - name: ubuntu\n sudo: ALL=(ALL) NOPASSWD:ALL\n groups: users, admin\n home: /home/ubuntu\n shell: /bin/bash\n lock_passwd: false\n ssh-authorized-keys:\n - ssh-rsa AAAA ...your-public-ssh-key-goes-here... user@host\nfinal_message: \"The system is finally up, after $UPTIME seconds\"\n", + "vars": null + }, + "sensitive_attributes": [] + } + ] + }, + { + "mode": "managed", + "type": "libvirt_cloudinit_disk", + "name": "commoninit", + "provider": "provider[\"registry.terraform.io/dmacvicar/libvirt\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "id": "/mnt/data1/libvirt_tf_volumes/commoninit.iso;60a65440-35d1-aff5-ed2f-1cf5899e0adc", + "meta_data": "", + "name": "commoninit.iso", + "network_config": "version: 2\nethernets:\n ens3:\n dhcp4: true\n", + "pool": "tf_pool", + "user_data": "#cloud-config\n# vim: syntax=yaml\n# examples:\n# https://cloudinit.readthedocs.io/en/latest/topics/examples.html\nbootcmd:\n - echo 192.168.0.1 gw.homedns.xyz \u003e\u003e /etc/hosts\nruncmd:\n - [ ls, -l, / ]\n - [ sh, -xc, \"echo $(date) ': hello world!'\" ]\nssh_pwauth: true\ndisable_root: false\nchpasswd:\n list: |\n root:password\n expire: false\npackage_update: true\npackages: ['qemu-guest-agent']\nusers:\n - name: ubuntu\n sudo: ALL=(ALL) NOPASSWD:ALL\n groups: users, admin\n home: /home/ubuntu\n shell: /bin/bash\n lock_passwd: false\n ssh-authorized-keys:\n - ssh-rsa AAAA ...your-public-ssh-key-goes-here... user@host\nfinal_message: \"The system is finally up, after $UPTIME seconds\"\n" + }, + "sensitive_attributes": [], + "private": "bnVsbA==", + "dependencies": [ + "data.template_file.network_config", + "data.template_file.user_data", + "libvirt_pool.tf_pool" + ] + } + ] + }, + { + "mode": "managed", + "type": "libvirt_domain", + "name": "domain-ubuntu", + "provider": "provider[\"registry.terraform.io/dmacvicar/libvirt\"]", + "instances": [ + { + "status": "tainted", + "schema_version": 0, + "attributes": { + "arch": null, + "autostart": null, + "boot_device": [], + "cloudinit": "/mnt/data1/libvirt_tf_volumes/commoninit.iso;60a65440-35d1-aff5-ed2f-1cf5899e0adc", + "cmdline": null, + "console": [ + { + "source_host": "127.0.0.1", + "source_path": "", + "source_service": "0", + "target_port": "0", + "target_type": "serial", + "type": "pty" + }, + { + "source_host": "127.0.0.1", + "source_path": "", + "source_service": "0", + "target_port": "1", + "target_type": "virtio", + "type": "pty" + } + ], + "coreos_ignition": null, + "cpu": null, + "description": null, + "disk": [ + { + "block_device": "", + "file": "", + "scsi": false, + "url": "", + "volume_id": "/mnt/data1/libvirt_tf_volumes/ubuntu-qcow2", + "wwn": "" + } + ], + "emulator": null, + "filesystem": [], + "firmware": null, + "fw_cfg_name": "opt/com.coreos/config", + "graphics": [ + { + "autoport": true, + "listen_address": "127.0.0.1", + "listen_type": "address", + "type": "spice" + } + ], + "id": "4debffdc-9abf-495e-8230-ef7d6f032cf9", + "initrd": null, + "kernel": null, + "machine": null, + "memory": 512, + "metadata": null, + "name": "terraform-kvm-ansible", + "network_interface": [ + { + "addresses": [], + "bridge": "", + "hostname": "terraform-kvm-ansible", + "mac": "", + "macvtap": "", + "network_id": "", + "network_name": "host-bridge", + "passthrough": "", + "vepa": "", + "wait_for_lease": true + } + ], + "nvram": [], + "qemu_agent": false, + "running": true, + "timeouts": null, + "vcpu": 1, + "video": [], + "xml": [] + }, + "sensitive_attributes": [], + "private": "eyJlMmJmYjczMC1lY2FhLTExZTYtOGY4OC0zNDM2M2JjN2M0YzAiOnsiY3JlYXRlIjozMDAwMDAwMDAwMDB9fQ==", + "dependencies": [ + "libvirt_cloudinit_disk.commoninit", + "libvirt_volume.ubuntu-qcow2" + ] + } + ] + }, + { + "mode": "managed", + "type": "libvirt_pool", + "name": "tf_pool", + "provider": "provider[\"registry.terraform.io/dmacvicar/libvirt\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "allocation": 221347414016, + "available": null, + "capacity": 1967792529408, + "id": "40b537c5-c26e-49d3-9660-3bfe18eb0907", + "name": "tf_pool", + "path": "/mnt/data1/libvirt_tf_volumes", + "type": "dir", + "xml": [] + }, + "sensitive_attributes": [], + "private": "bnVsbA==" + } + ] + }, + { + "mode": "managed", + "type": "libvirt_volume", + "name": "ubuntu-qcow2", + "provider": "provider[\"registry.terraform.io/dmacvicar/libvirt\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "base_volume_id": null, + "base_volume_name": null, + "base_volume_pool": null, + "format": "qcow2", + "id": "/mnt/data1/libvirt_tf_volumes/ubuntu-qcow2", + "name": "ubuntu-qcow2", + "pool": "tf_pool", + "size": 2361393152, + "source": "http://cloud-images.ubuntu.com/releases/bionic/release-20191008/ubuntu-18.04-server-cloudimg-amd64.img", + "xml": [] + }, + "sensitive_attributes": [], + "private": "bnVsbA==", + "dependencies": [ + "libvirt_pool.tf_pool" + ] + } + ] + } + ] +} diff --git a/variables.tf b/variables.tf new file mode 100644 index 0000000..3077cf4 --- /dev/null +++ b/variables.tf @@ -0,0 +1,25 @@ +variable "libvirt_disk_path" { + description = "path for libvirt pool" + default = "/mnt/data1/libvirt_tf_volumes" + #default = "/opt/kvm/pool1" +} + +variable "ubuntu_18_img_url" { + description = "ubuntu 18.04 image" + default = "http://cloud-images.ubuntu.com/releases/bionic/release-20191008/ubuntu-18.04-server-cloudimg-amd64.img" +} + +variable "vm_hostname" { + description = "vm hostname" + default = "terraform-kvm-ansible" +} + +variable "ssh_username" { + description = "the ssh user to use" + default = "ubuntu" +} + +variable "ssh_private_key" { + description = "the private key to use" + default = "~/.ssh/id_rsa" +}