-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.tf
More file actions
65 lines (55 loc) · 1.44 KB
/
Copy pathmain.tf
File metadata and controls
65 lines (55 loc) · 1.44 KB
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
63
64
65
terraform {
required_providers {
libvirt = {
source = "dmacvicar/libvirt"
}
}
}
provider "libvirt" {
uri = var.libvirt_uri
}
resource "libvirt_pool" "pool" {
count = try(var.pool ? 0 : 1, 0)
name = var.vm_name
type = "dir"
path = var.libvirt_pool_path
}
resource "libvirt_volume" "debian-base" {
name = "${var.vm_name}_base.img"
pool = try(var.pool, libvirt_pool.pool.0.name)
source = var.base_img_url
format = "qcow2"
}
resource "libvirt_volume" "debian-disk-resized" {
name = "${var.vm_name}_resized.img"
pool = try(var.pool, libvirt_pool.pool.0.name)
base_volume_id = libvirt_volume.debian-base.id
size = 5361393664
}
data "template_file" "user_data" {
template = file("${path.module}/cloud_init.yml")
vars = {
vm_hostname = "${var.vm_name}.local"
}
}
resource "libvirt_cloudinit_disk" "commoninit" {
name = "${var.vm_name}_cloudinit.iso"
user_data = data.template_file.user_data.rendered #if you set network user no go
pool = try(var.pool, libvirt_pool.pool.0.name)
}
resource "libvirt_domain" "domain-debian" {
name = var.vm_name
memory = var.vm_memory
vcpu = var.vm_cpus
running = true
autostart = true
qemu_agent = true
cloudinit = libvirt_cloudinit_disk.commoninit.id
network_interface {
bridge = "br0"
wait_for_lease = true
}
disk {
volume_id = libvirt_volume.debian-disk-resized.id
}
}