summaryrefslogtreecommitdiff
path: root/libvirt.tf
diff options
context:
space:
mode:
Diffstat (limited to 'libvirt.tf')
-rw-r--r--libvirt.tf53
1 files changed, 53 insertions, 0 deletions
diff --git a/libvirt.tf b/libvirt.tf
new file mode 100644
index 0000000..56ab930
--- /dev/null
+++ b/libvirt.tf
@@ -0,0 +1,53 @@
+# Defining VM Volume
+resource "libvirt_volume" "rocky8-qcow2" {
+ name = "rocky8.qcow2"
+ pool = "default"
+ source = "https://download.rockylinux.org/pub/rocky/8/images/x86_64/Rocky-8-GenericCloud-Base.latest.x86_64.qcow2"
+ format = "qcow2"
+}
+
+# get user data info
+data "template_file" "user_data" {
+ template = file("${path.module}/cloud_init.cfg")
+}
+
+# Use CloudInit to add the instance
+resource "libvirt_cloudinit_disk" "commoninit" {
+ name = "commoninit.iso"
+ pool = "default" # List storage pools using virsh pool-list
+ user_data = data.template_file.user_data.rendered
+}
+
+# Define KVM domain to create
+resource "libvirt_domain" "rocky8" {
+ name = "rocky8"
+ memory = "2048"
+ vcpu = 2
+
+ network_interface {
+ network_name = "default"
+ }
+
+ disk {
+ volume_id = libvirt_volume.rocky8-qcow2.id
+ }
+
+ cloudinit = libvirt_cloudinit_disk.commoninit.id
+
+ console {
+ type = "pty"
+ target_type = "serial"
+ target_port = "0"
+ }
+
+ graphics {
+ type = "spice"
+ listen_type = "address"
+ autoport = true
+ }
+}
+
+# Output Server IP
+output "ip" {
+ value = libvirt_domain.rocky8.network_interface.0.addresses.0
+}