-
Notifications
You must be signed in to change notification settings - Fork 509
Expand file tree
/
Copy pathalpine_cloudinit.tf
More file actions
160 lines (141 loc) · 2.74 KB
/
alpine_cloudinit.tf
File metadata and controls
160 lines (141 loc) · 2.74 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
terraform {
required_providers {
libvirt = {
source = "dmacvicar/libvirt"
}
}
}
provider "libvirt" {
uri = "qemu:///system"
}
# Base Alpine Linux cloud image stored in the default pool.
resource "libvirt_volume" "alpine_base" {
name = "alpine-3.22-base.qcow2"
pool = "default"
target = {
format = {
type = "qcow2"
}
}
create = {
content = {
url = "https://dl-cdn.alpinelinux.org/alpine/v3.22/releases/cloud/generic_alpine-3.22.2-x86_64-bios-cloudinit-r0.qcow2"
}
}
}
# Writable copy-on-write layer for the VM.
resource "libvirt_volume" "alpine_disk" {
name = "alpine-vm.qcow2"
pool = "default"
target = {
format = {
type = "qcow2"
}
}
capacity = 2147483648
backing_store = {
path = libvirt_volume.alpine_base.path
format = {
type = "qcow2"
}
}
}
# Cloud-init seed ISO.
resource "libvirt_cloudinit_disk" "alpine_seed" {
name = "alpine-cloudinit"
user_data = <<-EOF
#cloud-config
chpasswd:
list: |
root:password
expire: false
ssh_pwauth: true
packages:
- openssh-server
timezone: UTC
EOF
meta_data = <<-EOF
instance-id: alpine-001
local-hostname: alpine-vm
EOF
network_config = <<-EOF
version: 2
ethernets:
eth0:
dhcp4: true
EOF
}
# Upload the cloud-init ISO into the pool.
resource "libvirt_volume" "alpine_seed_volume" {
name = "alpine-cloudinit.iso"
pool = "default"
create = {
content = {
url = libvirt_cloudinit_disk.alpine_seed.path
}
}
}
# Virtual machine definition.
resource "libvirt_domain" "alpine" {
name = "alpine-vm"
memory = 1048576
vcpu = 1
type = "kvm"
os = {
type = "hvm"
type_arch = "x86_64"
type_machine = "q35"
}
devices = {
disks = [
{
source = {
volume = {
pool = libvirt_volume.alpine_disk.pool
volume = libvirt_volume.alpine_disk.name
}
}
target = {
dev = "vda"
bus = "virtio"
}
driver = {
type = "qcow2"
}
},
{
device = "cdrom"
source = {
volume = {
pool = libvirt_volume.alpine_seed_volume.pool
volume = libvirt_volume.alpine_seed_volume.name
}
}
target = {
dev = "sda"
bus = "sata"
}
}
]
interfaces = [
{
type = "network"
model = { type = "virtio" }
source = {
network = {
network = "default"
}
}
}
]
graphics = [
{
vnc = {
auto_port = true
listen = "127.0.0.1"
}
}
]
}
running = true
}