From 51f8d2c817097492cd762f2a1b151b0efeba0315 Mon Sep 17 00:00:00 2001 From: jerome Date: Wed, 29 Jan 2025 18:51:37 +0100 Subject: ajout de variables --- libvirt.tf | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) (limited to 'libvirt.tf') diff --git a/libvirt.tf b/libvirt.tf index d1caeaf..c7cbb5a 100644 --- a/libvirt.tf +++ b/libvirt.tf @@ -1,15 +1,18 @@ # Defining VM Volume -resource "libvirt_volume" "rocky-qcow2" { - name = "rocky.qcow2" +resource "libvirt_volume" "qcow2_vol" { + name = "${var.nom}.qcow2" pool = "default" - #source = "https://download.rockylinux.org/pub/rocky/9/images/x86_64/Rocky-9-GenericCloud-Base.latest.x86_64.qcow2" - source = "/home/jerome/Téléchargements/isos/Rocky-9-GenericCloud-Base.latest.x86_64.qcow2" + source = var.image format = "qcow2" } # get user data info data "template_file" "user_data" { template = file("${path.module}/cloud_init.cfg") + vars = { + nom = var.nom + package = var.package + } } # Use CloudInit to add the instance @@ -20,25 +23,25 @@ resource "libvirt_cloudinit_disk" "commoninit" { } # Define KVM domain to create -resource "libvirt_domain" "rocky" { - name = "rocky" - memory = "2048" - vcpu = 2 +resource "libvirt_domain" "vm_domain" { + name = var.nom + memory = "2048" + vcpu = 2 qemu_agent = true - cpu { + cpu { mode = "host-passthrough" } network_interface { #network_name = "default" - bridge = "nm-bridge" + bridge = "bridge0" wait_for_lease = true } disk { - volume_id = libvirt_volume.rocky-qcow2.id + volume_id = libvirt_volume.qcow2_vol.id } cloudinit = libvirt_cloudinit_disk.commoninit.id @@ -57,6 +60,7 @@ resource "libvirt_domain" "rocky" { } # Output Server IP +# Nécessite qemu-guest-agent sinon bloque la fin de l'installation !!! output "ip" { - value = libvirt_domain.rocky.network_interface.0.addresses + value = libvirt_domain.vm_domain.network_interface.0.addresses } -- cgit v1.2.3