Skip to content

Commit

Permalink
Merge pull request #11 from chrodriguez/main
Browse files Browse the repository at this point in the history
Add support to attach multiple disks
  • Loading branch information
MonolithProjects authored Feb 5, 2022
2 parents afbe7f2 + d12388e commit 3912952
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 3 deletions.
49 changes: 46 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Terraform module for KVM/Libvirt Virtual Machine. This module will create a KVM
- one NIC per domain, connected to the network using the **bridge interface**
- setup network interface using DHCP or static configuration
- cloud_init VM(s) configuration (Ubuntu+Netplan complient)
- optionally add multiple extra disks
- test the ssh connection

## Tested on
Expand All @@ -30,6 +31,7 @@ Terraform module for KVM/Libvirt Virtual Machine. This module will create a KVM
|index_start|From where the index start| 1
|vm_hostname_prefix|VM hostname prefix|vm
|memory|RAM in MB|1024
|additional_disk_ids|List of volume ids to be attached to domain| []
|hugepages|Use Hugepages|false
|vcpu|Number of vCPUs|1
|pool|Storage pool name|default
Expand Down Expand Up @@ -70,7 +72,7 @@ provider "libvirt" {
module "vm" {
source = "MonolithProjects/vm/libvirt"
version = "1.6.0"
version = "1.8.0"
vm_hostname_prefix = "server"
vm_count = 3
Expand Down Expand Up @@ -117,7 +119,7 @@ provider "libvirt" {
module "vm" {
source = "MonolithProjects/vm/libvirt"
version = "1.6.0"
version = "1.8.0"
vm_hostname_prefix = "server"
vm_count = 3
Expand Down Expand Up @@ -157,7 +159,48 @@ output "outputs" {
}
```

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`
> 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`
Create a VM with an extra disk

```
# Creates a 50GB extra-data-disk within vms pool
resource "libvirt_volume" "data_volume" {
pool = "vms"
name = "extra-data-disk.qcow2"
format = "qcow2"
size = 1024*1024*1024*50
}
module "vm" {
source = "MonolithProjects/vm/libvirt"
version = "1.8.0"
vm_hostname_prefix = "data-server"
base_volume_name = "debian-11-base.qcow2"
base_pool_name = "linked-images"
vm_count = 1
bridge = "bridge-dmz"
memory = "4096"
hugepages = false
vcpu = 4
pool = "vms"
system_volume = 25
additional_disk_ids = [ libvirt_volume.data_volume.id ]
dhcp = true
ssh_admin = "admin"
ssh_keys = [
chomp(file("~/.ssh/id_rsa.pub"))
]
time_zone = "America/Argentina/Buenos_Aires"
}
output "ip_addresses" {
value = module.vm
}
```

## Module output example

Expand Down
7 changes: 7 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ resource "libvirt_domain" "virt-machine" {
volume_id = element(libvirt_volume.volume-qcow2.*.id, count.index)
}

dynamic "disk" {
for_each = var.additional_disk_ids
content {
volume_id = disk.value
}
}

dynamic "filesystem" {
for_each = var.share_filesystem.source != null ? [ var.share_filesystem.source] : []
content {
Expand Down
5 changes: 5 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ variable "base_pool_name" {
default = null
}

variable "additional_disk_ids" {
description = "List of volume ids"
default = []
}


variable "autostart" {
description = "Autostart the domain"
Expand Down

0 comments on commit 3912952

Please sign in to comment.