diff options
| author | jerome <jerome@xlinfo.fr> | 2025-05-21 22:34:55 +0200 |
|---|---|---|
| committer | jerome <jerome@xlinfo.fr> | 2025-05-21 22:34:55 +0200 |
| commit | 538ff0a46de955e65cb7f12c99ba566c76c19391 (patch) | |
| tree | 5a317258c3398c005022bc21003dc9b8cafc43af | |
| parent | d02be3667151e4a836174d45c2d3cf27937ff602 (diff) | |
| download | kvm-multi-538ff0a46de955e65cb7f12c99ba566c76c19391.tar.gz kvm-multi-538ff0a46de955e65cb7f12c99ba566c76c19391.zip | |
initial commit
| -rw-r--r-- | libvirt.tf | 14 | ||||
| -rw-r--r-- | variables.tf | 7 |
2 files changed, 13 insertions, 8 deletions
@@ -7,7 +7,8 @@ resource "libvirt_volume" "base" { } resource "libvirt_volume" "image" { - name = "${var.nom}.qcow2" + count = var.vm_count + name = "${var.nom}-${count.index + 1}.qcow2" base_volume_id = libvirt_volume.base.id pool = "default" size = 10 * 1024 * 1024 * 1024 @@ -31,7 +32,8 @@ resource "libvirt_cloudinit_disk" "commoninit" { # Define KVM domain to create resource "libvirt_domain" "vm_domain" { - name = var.nom + count = var.vm_count + name = "${var.nom}-${count.index + 1}" memory = "2048" vcpu = 2 qemu_agent = true @@ -48,7 +50,7 @@ resource "libvirt_domain" "vm_domain" { } disk { - volume_id = libvirt_volume.image.id + volume_id = libvirt_volume.image[count.index].id } cloudinit = libvirt_cloudinit_disk.commoninit.id @@ -73,7 +75,11 @@ resource "libvirt_domain" "vm_domain" { # Output Server IP # Nécessite qemu-guest-agent sinon bloque la fin de l'installation !!! output "ip" { - value = "libvirt_domain.vm_domain.network_interface.0.addresses" + value = { + for vm in libvirt_domain.vm_domain.* : + vm.name => vm.network_interface.0.addresses } +} + diff --git a/variables.tf b/variables.tf index 99d67e3..d7c03a7 100644 --- a/variables.tf +++ b/variables.tf @@ -1,9 +1,8 @@ # définition des variables -variable "nb" { - description = "nombre de vms" - type = number - default = 1 +variable "vm_count" { + type = number + default = 2 } variable "nom" { |
