-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.tf
72 lines (60 loc) · 1.62 KB
/
main.tf
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
66
67
68
69
70
71
72
provider "libvirt" {
uri= "qemu:///system" # For Local Provisioning
}
resource "libvirt_network" "net-example" {
name = "net-example"
addresses = ["192.168.10.0/24"]
}
resource "libvirt_volume" "example-img" {
name = "example-img.qcow2"
pool = "default"
source = "/home/arya/Downloads/bionic-server-cloudimg-amd64.img"
}
resource "libvirt_volume" "example-volume" {
name = "example-volume.qcow2"
pool = "default"
base_volume_id = "${libvirt_volume.example-img.id}"
size = "5368709120" # Size in Bytes, This is 5GB
}
resource "libvirt_cloudinit_disk" "cloudinit-example" {
name = "cloudinit-example"
pool = "default"
user_data = "${data.template_file.user_data.rendered}"
network_config = "${data.template_file.network_config.rendered}"
}
data "template_file" "user_data" {
template = "${file("${path.module}/cloud_init.cfg")}"
}
data "template_file" "network_config" {
template = "${file("${path.module}/network_config.cfg")}"
}
resource "libvirt_domain" "vm-example" {
name = "vm-example"
vcpu = "1"
memory = "2048"
machine = "pc-i440fx-bionic"
cloudinit = "${libvirt_cloudinit_disk.cloudinit-example.id}"
network_interface {
network_id = "${libvirt_network.net-example.id}"
network_name = "net-example"
addresses = ["192.168.10.0/24"]
}
console {
type = "pty"
target_port = "0"
target_type = "serial"
}
console {
type = "pty"
target_port = "0"
target_type = "virtio"
}
disk {
volume_id = "${libvirt_volume.example-volume.id}"
}
graphics {
type = "vnc"
listen_type = "address"
autoport = true
}
}