Skip to content

Commit afbe7f2

Browse files
Merge pull request #10 from MonolithProjects/develop
Develop to Main
2 parents 8839153 + 8512d70 commit afbe7f2

File tree

5 files changed

+26
-8
lines changed

5 files changed

+26
-8
lines changed

Diff for: README.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ Terraform module for KVM/Libvirt Virtual Machine. This module will create a KVM
2323
| Parameter | Description | Default value
2424
|-----------------|-----|-----
2525
|os_img_url|URL to the OS image|https://cloud-images.ubuntu.com/focal/current/focal-server-cloudimg-amd64.img
26+
|base_pool_name|When defined it will be used in combination with `base_volume_name` to create root volume as linked clone from this pool name|null
27+
|base_volume_name|When defined it will be used in combination with `base_pool_name` to create root volume as linked clone from this pool/vol name. Defining this variable will disable downloading `os_img_url` and creating a base volume| null
2628
|autostart| Autostart the Domain| true
2729
|vm_count|Number of VMs| 1
2830
|index_start|From where the index start| 1
@@ -43,10 +45,10 @@ Terraform module for KVM/Libvirt Virtual Machine. This module will create a KVM
4345
|ip_gateway|Static IP addresses of a gateway|192.168.123.1
4446
|ssh_admin|Admin user with ssh access|ssh-admin
4547
|ssh_keys|List of public ssh keys| []
46-
|local_admin|Admin user without ssh access|local-admin
48+
|local_admin|Admin user without ssh access|""
4749
|local_admin_passwd|Local admin user password|password_example
4850
|time_zone|Time Zone|UTC
49-
|ssh_private_key|Private key for SSH connection test|~/.ssh/id_ed25519
51+
|ssh_private_key|Private key for SSH connection test|null
5052

5153
## Example
5254

Diff for: main.tf

+1-2
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,11 @@ resource "libvirt_domain" "virt-machine" {
6666
"echo \"Virtual Machine \"$(hostname)\" is UP!\"",
6767
"date"
6868
]
69-
7069
connection {
7170
type = "ssh"
7271
user = var.ssh_admin
7372
host = self.network_interface.0.addresses.0
74-
private_key = file(var.ssh_private_key)
73+
private_key = var.ssh_private_key != null ? file(var.ssh_private_key): null
7574
timeout = "2m"
7675
}
7776
}

Diff for: storage.tf

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
resource "libvirt_volume" "base-volume-qcow2" {
2+
count = var.base_volume_name != null ? 0 : 1
23
name = format("${var.vm_hostname_prefix}-base.qcow2")
34
pool = var.pool
45
source = var.os_img_url
@@ -10,7 +11,10 @@ resource "libvirt_volume" "volume-qcow2" {
1011
name = format("${var.vm_hostname_prefix}%02d.qcow2", count.index + var.index_start)
1112
pool = var.pool
1213
size = 1024*1024*1024*var.system_volume
13-
base_volume_id = libvirt_volume.base-volume-qcow2.id
14+
base_volume_id = var.base_volume_name != null ? null : element(libvirt_volume.base-volume-qcow2, 0).id
15+
base_volume_name = var.base_volume_name
16+
base_volume_pool = var.base_pool_name
17+
1418
format = "qcow2"
1519
}
1620

@@ -20,4 +24,4 @@ resource "libvirt_cloudinit_disk" "commoninit" {
2024
user_data = data.template_cloudinit_config.init_config[count.index].rendered
2125
network_config = data.template_file.network_config[count.index].rendered
2226
pool = var.pool
23-
}
27+
}

Diff for: templates/cloud_init.tpl

+2
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,14 @@ users:
2222
system: False
2323
ssh_authorized_keys: ${ssh_keys}
2424
shell: /bin/bash
25+
%{ if local_admin != "" }
2526
- name: ${local_admin}
2627
gecos: Local admin (no SSH)
2728
lock-passwd: false
2829
sudo: ALL=(ALL) ALL
2930
passwd: ${local_admin_passwd}
3031
shell: /bin/bash
32+
%{ endif }
3133

3234
write_files:
3335
- path: /etc/ssh/sshd_config

Diff for: variables.tf

+13-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,17 @@ variable "os_img_url" {
33
default = "https://cloud-images.ubuntu.com/focal/current/focal-server-cloudimg-amd64.img"
44
}
55

6+
variable "base_volume_name" {
7+
description = "Name of base OS image"
8+
default = null
9+
}
10+
11+
variable "base_pool_name" {
12+
description = "Name of base OS image"
13+
default = null
14+
}
15+
16+
617
variable "autostart" {
718
description = "Autostart the domain"
819
default = true
@@ -111,7 +122,7 @@ variable "ssh_keys" {
111122

112123
variable "local_admin" {
113124
description = "Admin user without ssh access"
114-
default = "local-admin"
125+
default = ""
115126
}
116127

117128
variable "local_admin_passwd" {
@@ -126,5 +137,5 @@ variable "time_zone" {
126137

127138
variable "ssh_private_key" {
128139
description = "Private key for SSH connection test"
129-
default = "~/.ssh/id_ed25519"
140+
default = null
130141
}

0 commit comments

Comments
 (0)