summaryrefslogtreecommitdiff
path: root/libvirt.tf
blob: d1caeaf9805a21cde52c552b94c9f82ade0734e3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# Defining VM Volume
resource "libvirt_volume" "rocky-qcow2" {
  name   = "rocky.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"
  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" "rocky" {
  name   = "rocky"
  memory = "2048"
  vcpu   = 2
  qemu_agent = true


 cpu {
    mode = "host-passthrough"
  }

  network_interface {
    #network_name = "default"
    bridge = "nm-bridge"
    wait_for_lease = true
  }

  disk {
    volume_id = libvirt_volume.rocky-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.rocky.network_interface.0.addresses
}