Skip to content

Commit cdd4b65

Browse files
Merge branch 'main' into develop
2 parents 6d62faa + ad6c5ae commit cdd4b65

File tree

4 files changed

+56
-4
lines changed

4 files changed

+56
-4
lines changed

README.md

+43-3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Terraform module for KVM/Libvirt Virtual Machine. This module will create a KVM
1212
- one NIC per domain, connected to the network using the **bridge interface**
1313
- setup network interface using DHCP or static configuration
1414
- cloud_init VM(s) configuration (Ubuntu+Netplan complient)
15+
- optionally add multiple extra disks
1516
- test the ssh connection
1617

1718
## Tested on
@@ -80,6 +81,7 @@ No modules.
8081
| <a name="output_ip_address"></a> [ip\_address](#output\_ip\_address) | n/a |
8182
| <a name="output_name"></a> [name](#output\_name) | n/a |
8283
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
84+
8385
## Example
8486

8587
Example with enable HugePages, Attached USB device, changed USB controller model... :
@@ -100,7 +102,7 @@ provider "libvirt" {
100102
101103
module "vm" {
102104
source = "MonolithProjects/vm/libvirt"
103-
version = "1.6.0"
105+
version = "1.8.0"
104106
105107
vm_hostname_prefix = "server"
106108
vm_count = 3
@@ -158,7 +160,7 @@ provider "libvirt" {
158160
159161
module "vm" {
160162
source = "MonolithProjects/vm/libvirt"
161-
version = "1.6.0"
163+
version = "1.8.0"
162164
163165
vm_hostname_prefix = "server"
164166
vm_count = 3
@@ -197,7 +199,45 @@ output "outputs" {
197199
}
198200
```
199201

200-
The shared directory from the example can be mounted inside the VM with command `sudo mount -t 9p -o trans=virtio,version=9p2000.L,rw tmp /host/tmp`
202+
> The shared directory from the example can be mounted inside the VM with command `sudo mount -t 9p -o trans=virtio,version=9p2000.L,rw tmp /host/tmp`
203+
204+
Create a VM with an extra disk
205+
206+
```
207+
# Creates a 50GB extra-data-disk within vms pool
208+
resource "libvirt_volume" "data_volume" {
209+
pool = "vms"
210+
name = "extra-data-disk.qcow2"
211+
format = "qcow2"
212+
size = 1024*1024*1024*50
213+
}
214+
215+
module "vm" {
216+
source = "MonolithProjects/vm/libvirt"
217+
version = "1.8.0"
218+
219+
vm_hostname_prefix = "data-server"
220+
base_volume_name = "debian-11-base.qcow2"
221+
base_pool_name = "linked-images"
222+
vm_count = 1
223+
bridge = "bridge-dmz"
224+
memory = "4096"
225+
vcpu = 4
226+
pool = "vms"
227+
system_volume = 25
228+
additional_disk_ids = [ libvirt_volume.data_volume.id ]
229+
dhcp = true
230+
ssh_admin = "admin"
231+
ssh_keys = [
232+
chomp(file("~/.ssh/id_rsa.pub"))
233+
]
234+
time_zone = "America/Argentina/Buenos_Aires"
235+
}
236+
237+
output "ip_addresses" {
238+
value = module.vm
239+
}
240+
```
201241

202242
## Module output example
203243

main.tf

+7
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,13 @@ resource "libvirt_domain" "virt-machine" {
4848
volume_id = element(libvirt_volume.volume-qcow2.*.id, count.index)
4949
}
5050

51+
dynamic "disk" {
52+
for_each = var.additional_disk_ids
53+
content {
54+
volume_id = disk.value
55+
}
56+
}
57+
5158
dynamic "filesystem" {
5259
for_each = var.share_filesystem.source != null ? [var.share_filesystem.source] : []
5360
content {

storage.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ resource "libvirt_volume" "volume-qcow2" {
2020

2121
resource "libvirt_cloudinit_disk" "commoninit" {
2222
count = var.vm_count
23-
name = format("${var.vm_hostname_prefix}_init%2d.iso", count.index + 1)
23+
name = format("${var.vm_hostname_prefix}_init%02d.iso", count.index + 1)
2424
user_data = data.template_cloudinit_config.init_config[count.index].rendered
2525
network_config = data.template_file.network_config[count.index].rendered
2626
pool = var.pool

variables.tf

+5
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ variable "base_pool_name" {
1313
default = null
1414
}
1515

16+
variable "additional_disk_ids" {
17+
description = "List of volume ids"
18+
default = []
19+
}
20+
1621

1722
variable "autostart" {
1823
description = "Autostart the domain"

0 commit comments

Comments
 (0)