feat: add debian vm

This commit is contained in:
Aravinth Manivannan 2022-10-24 11:27:14 +05:30
parent d9cf6f08f1
commit 55ce464567
Signed by: realaravinth
GPG Key ID: AD9F0F08E855ED88
3 changed files with 418 additions and 5 deletions

View File

@ -1,7 +1,7 @@
{
"version": 4,
"terraform_version": "1.3.2",
"serial": 5,
"serial": 12,
"lineage": "ad020180-a9b1-2642-e7c1-0de5d2b318c5",
"outputs": {},
"resources": [
@ -72,7 +72,7 @@
{
"mode": "managed",
"type": "libvirt_domain",
"name": "domain-ubuntu",
"name": "domain-debian-ansible-playground",
"provider": "provider[\"registry.terraform.io/dmacvicar/libvirt\"]",
"instances": [
{
@ -108,6 +108,110 @@
}
],
"description": "",
"disk": [
{
"block_device": "",
"file": "",
"scsi": false,
"url": "",
"volume_id": "/tmp/terraform-provider-libvirt-pool-ubuntu/debian-qcow2",
"wwn": ""
}
],
"emulator": "/usr/bin/qemu-system-x86_64",
"filesystem": [],
"firmware": null,
"fw_cfg_name": "opt/com.coreos/config",
"graphics": [
{
"autoport": true,
"listen_address": "127.0.0.1",
"listen_type": "address",
"type": "spice",
"websocket": 0
}
],
"id": "cd8a2617-049f-46e7-884b-06f522ad6d8a",
"initrd": "",
"kernel": "",
"machine": "pc",
"memory": 3000,
"metadata": null,
"name": "debian-ansible-playground-terraform",
"network_interface": [
{
"addresses": [],
"bridge": "",
"hostname": "",
"mac": "52:54:00:66:55:DF",
"macvtap": "",
"network_id": "f50e127a-7413-4d45-80de-587b22da0aa6",
"network_name": "default",
"passthrough": "",
"vepa": "",
"wait_for_lease": false
}
],
"nvram": [],
"qemu_agent": false,
"running": true,
"timeouts": null,
"tpm": [],
"vcpu": 4,
"video": [],
"xml": []
},
"sensitive_attributes": [],
"private": "eyJlMmJmYjczMC1lY2FhLTExZTYtOGY4OC0zNDM2M2JjN2M0YzAiOnsiY3JlYXRlIjozMDAwMDAwMDAwMDB9fQ==",
"dependencies": [
"data.template_file.network_config",
"data.template_file.user_data",
"libvirt_cloudinit_disk.commoninit",
"libvirt_pool.ubuntu",
"libvirt_volume.debian-qcow2"
]
}
]
},
{
"mode": "managed",
"type": "libvirt_domain",
"name": "domain-ubuntu",
"provider": "provider[\"registry.terraform.io/dmacvicar/libvirt\"]",
"instances": [
{
"schema_version": 0,
"attributes": {
"arch": "x86_64",
"autostart": false,
"boot_device": [],
"cloudinit": "/tmp/terraform-provider-libvirt-pool-ubuntu/commoninit.iso;f998a504-a990-4b4a-bb52-4df8b70f3934",
"cmdline": [],
"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": [
{
"mode": "custom"
}
],
"description": "",
"disk": [
{
"block_device": "",
@ -140,7 +244,9 @@
"name": "ubuntu-terraform",
"network_interface": [
{
"addresses": [],
"addresses": [
"192.168.122.105"
],
"bridge": "",
"hostname": "",
"mac": "52:54:00:AA:5B:84",
@ -182,8 +288,8 @@
{
"schema_version": 0,
"attributes": {
"allocation": 36864,
"available": 11981750272,
"allocation": 572428288,
"available": 11409358848,
"capacity": 11981787136,
"id": "b8d85970-bfed-4907-9b73-c26c3578b7c6",
"name": "ubuntu",
@ -196,6 +302,34 @@
}
]
},
{
"mode": "managed",
"type": "libvirt_volume",
"name": "debian-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": "/tmp/terraform-provider-libvirt-pool-ubuntu/debian-qcow2",
"name": "debian-qcow2",
"pool": "ubuntu",
"size": 2147483648,
"source": "https://cloud.debian.org/images/cloud/buster/latest/debian-10-genericcloud-amd64.qcow2",
"xml": []
},
"sensitive_attributes": [],
"private": "bnVsbA==",
"dependencies": [
"libvirt_pool.ubuntu"
]
}
]
},
{
"mode": "managed",
"type": "libvirt_volume",

View File

@ -0,0 +1,229 @@
{
"version": 4,
"terraform_version": "1.3.2",
"serial": 5,
"lineage": "ad020180-a9b1-2642-e7c1-0de5d2b318c5",
"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": "74c90b4966a0af6c145fc5551db49d4e5e463b0e5cdf771229aee494649157e3",
"rendered": "#cloud-config\n# vim: syntax=yaml\n#\n# ***********************\n# \t---- for more examples look at: ------\n# ---\u003e https://cloudinit.readthedocs.io/en/latest/topics/examples.html\n# ******************************\n#\n# This is the configuration syntax that the write_files module\n# will know how to understand. encoding can be given b64 or gzip or (gz+b64).\n# The content will be decoded accordingly and then written to the path that is\n# provided.\n#\n# Note: Content strings here are truncated for example purposes.\nssh_pwauth: True\nchpasswd:\n list: |\n root:terraform-libvirt-linux\n expire: False\n",
"template": "#cloud-config\n# vim: syntax=yaml\n#\n# ***********************\n# \t---- for more examples look at: ------\n# ---\u003e https://cloudinit.readthedocs.io/en/latest/topics/examples.html\n# ******************************\n#\n# This is the configuration syntax that the write_files module\n# will know how to understand. encoding can be given b64 or gzip or (gz+b64).\n# The content will be decoded accordingly and then written to the path that is\n# provided.\n#\n# Note: Content strings here are truncated for example purposes.\nssh_pwauth: True\nchpasswd:\n list: |\n root:terraform-libvirt-linux\n expire: False\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": "/tmp/terraform-provider-libvirt-pool-ubuntu/commoninit.iso;f998a504-a990-4b4a-bb52-4df8b70f3934",
"meta_data": "",
"name": "commoninit.iso",
"network_config": "version: 2\nethernets:\n ens3:\n dhcp4: true\n",
"pool": "ubuntu",
"user_data": "#cloud-config\n# vim: syntax=yaml\n#\n# ***********************\n# \t---- for more examples look at: ------\n# ---\u003e https://cloudinit.readthedocs.io/en/latest/topics/examples.html\n# ******************************\n#\n# This is the configuration syntax that the write_files module\n# will know how to understand. encoding can be given b64 or gzip or (gz+b64).\n# The content will be decoded accordingly and then written to the path that is\n# provided.\n#\n# Note: Content strings here are truncated for example purposes.\nssh_pwauth: True\nchpasswd:\n list: |\n root:terraform-libvirt-linux\n expire: False\n"
},
"sensitive_attributes": [],
"private": "bnVsbA==",
"dependencies": [
"data.template_file.network_config",
"data.template_file.user_data",
"libvirt_pool.ubuntu"
]
}
]
},
{
"mode": "managed",
"type": "libvirt_domain",
"name": "domain-ubuntu",
"provider": "provider[\"registry.terraform.io/dmacvicar/libvirt\"]",
"instances": [
{
"schema_version": 0,
"attributes": {
"arch": "x86_64",
"autostart": false,
"boot_device": [],
"cloudinit": "/tmp/terraform-provider-libvirt-pool-ubuntu/commoninit.iso;f998a504-a990-4b4a-bb52-4df8b70f3934",
"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": [
{
"mode": "custom"
}
],
"description": "",
"disk": [
{
"block_device": "",
"file": "",
"scsi": false,
"url": "",
"volume_id": "/tmp/terraform-provider-libvirt-pool-ubuntu/ubuntu-qcow2",
"wwn": ""
}
],
"emulator": "/usr/bin/qemu-system-x86_64",
"filesystem": [],
"firmware": null,
"fw_cfg_name": "opt/com.coreos/config",
"graphics": [
{
"autoport": true,
"listen_address": "127.0.0.1",
"listen_type": "address",
"type": "spice",
"websocket": 0
}
],
"id": "c932a058-d7f3-4b2c-a21f-b54a3c3e8c10",
"initrd": "",
"kernel": "",
"machine": "pc",
"memory": 512,
"metadata": null,
"name": "ubuntu-terraform",
"network_interface": [
{
"addresses": [],
"bridge": "",
"hostname": "",
"mac": "52:54:00:AA:5B:84",
"macvtap": "",
"network_id": "f50e127a-7413-4d45-80de-587b22da0aa6",
"network_name": "default",
"passthrough": "",
"vepa": "",
"wait_for_lease": false
}
],
"nvram": [],
"qemu_agent": false,
"running": true,
"timeouts": null,
"tpm": [],
"vcpu": 1,
"video": [],
"xml": []
},
"sensitive_attributes": [],
"private": "eyJlMmJmYjczMC1lY2FhLTExZTYtOGY4OC0zNDM2M2JjN2M0YzAiOnsiY3JlYXRlIjozMDAwMDAwMDAwMDB9fQ==",
"dependencies": [
"data.template_file.network_config",
"data.template_file.user_data",
"libvirt_cloudinit_disk.commoninit",
"libvirt_pool.ubuntu",
"libvirt_volume.ubuntu-qcow2"
]
}
]
},
{
"mode": "managed",
"type": "libvirt_pool",
"name": "ubuntu",
"provider": "provider[\"registry.terraform.io/dmacvicar/libvirt\"]",
"instances": [
{
"schema_version": 0,
"attributes": {
"allocation": 36864,
"available": 11981750272,
"capacity": 11981787136,
"id": "b8d85970-bfed-4907-9b73-c26c3578b7c6",
"name": "ubuntu",
"path": "/tmp/terraform-provider-libvirt-pool-ubuntu",
"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": "/tmp/terraform-provider-libvirt-pool-ubuntu/ubuntu-qcow2",
"name": "ubuntu-qcow2",
"pool": "ubuntu",
"size": 2361393152,
"source": "https://cloud-images.ubuntu.com/releases/xenial/release/ubuntu-16.04-server-cloudimg-amd64-disk1.img",
"xml": []
},
"sensitive_attributes": [],
"private": "bnVsbA==",
"dependencies": [
"libvirt_pool.ubuntu"
]
}
]
}
],
"check_results": []
}

View File

@ -27,6 +27,16 @@ resource "libvirt_volume" "ubuntu-qcow2" {
format = "qcow2"
}
# We fetch the latest ubuntu release image from their mirrors
resource "libvirt_volume" "debian-qcow2" {
name = "debian-qcow2"
pool = libvirt_pool.ubuntu.name
source = "https://cloud.debian.org/images/cloud/buster/latest/debian-10-genericcloud-amd64.qcow2"
format = "qcow2"
}
data "template_file" "user_data" {
template = file("${path.module}/cloud_init.cfg")
}
@ -84,4 +94,44 @@ resource "libvirt_domain" "domain-ubuntu" {
}
}
# Create the machine
resource "libvirt_domain" "domain-debian-ansible-playground" {
name = "debian-ansible-playground-terraform"
memory = "3000"
vcpu = 4
cloudinit = libvirt_cloudinit_disk.commoninit.id
network_interface {
network_name = "default"
}
# IMPORTANT: this is a known bug on cloud images, since they expect a console
# we need to pass it
# https://bugs.launchpad.net/cloud-images/+bug/1573095
console {
type = "pty"
target_port = "0"
target_type = "serial"
}
console {
type = "pty"
target_type = "virtio"
target_port = "1"
}
disk {
volume_id = libvirt_volume.debian-qcow2.id
}
graphics {
type = "spice"
listen_type = "address"
autoport = true
}
}
# IPs: use wait_for_lease true or after creation use terraform refresh and terraform show for the ips of domain