Skip to content

Commit

Permalink
Merge pull request #10 from MonolithProjects/develop
Browse files Browse the repository at this point in the history
Develop to Main
  • Loading branch information
MonolithProjects authored Jan 24, 2022
2 parents 8839153 + 8512d70 commit afbe7f2
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 8 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ Terraform module for KVM/Libvirt Virtual Machine. This module will create a KVM
| Parameter | Description | Default value
|-----------------|-----|-----
|os_img_url|URL to the OS image|https://cloud-images.ubuntu.com/focal/current/focal-server-cloudimg-amd64.img
|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
|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
|autostart| Autostart the Domain| true
|vm_count|Number of VMs| 1
|index_start|From where the index start| 1
Expand All @@ -43,10 +45,10 @@ Terraform module for KVM/Libvirt Virtual Machine. This module will create a KVM
|ip_gateway|Static IP addresses of a gateway|192.168.123.1
|ssh_admin|Admin user with ssh access|ssh-admin
|ssh_keys|List of public ssh keys| []
|local_admin|Admin user without ssh access|local-admin
|local_admin|Admin user without ssh access|""
|local_admin_passwd|Local admin user password|password_example
|time_zone|Time Zone|UTC
|ssh_private_key|Private key for SSH connection test|~/.ssh/id_ed25519
|ssh_private_key|Private key for SSH connection test|null

## Example

Expand Down
3 changes: 1 addition & 2 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,11 @@ resource "libvirt_domain" "virt-machine" {
"echo \"Virtual Machine \"$(hostname)\" is UP!\"",
"date"
]

connection {
type = "ssh"
user = var.ssh_admin
host = self.network_interface.0.addresses.0
private_key = file(var.ssh_private_key)
private_key = var.ssh_private_key != null ? file(var.ssh_private_key): null
timeout = "2m"
}
}
Expand Down
8 changes: 6 additions & 2 deletions storage.tf
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
resource "libvirt_volume" "base-volume-qcow2" {
count = var.base_volume_name != null ? 0 : 1
name = format("${var.vm_hostname_prefix}-base.qcow2")
pool = var.pool
source = var.os_img_url
Expand All @@ -10,7 +11,10 @@ resource "libvirt_volume" "volume-qcow2" {
name = format("${var.vm_hostname_prefix}%02d.qcow2", count.index + var.index_start)
pool = var.pool
size = 1024*1024*1024*var.system_volume
base_volume_id = libvirt_volume.base-volume-qcow2.id
base_volume_id = var.base_volume_name != null ? null : element(libvirt_volume.base-volume-qcow2, 0).id
base_volume_name = var.base_volume_name
base_volume_pool = var.base_pool_name

format = "qcow2"
}

Expand All @@ -20,4 +24,4 @@ resource "libvirt_cloudinit_disk" "commoninit" {
user_data = data.template_cloudinit_config.init_config[count.index].rendered
network_config = data.template_file.network_config[count.index].rendered
pool = var.pool
}
}
2 changes: 2 additions & 0 deletions templates/cloud_init.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@ users:
system: False
ssh_authorized_keys: ${ssh_keys}
shell: /bin/bash
%{ if local_admin != "" }
- name: ${local_admin}
gecos: Local admin (no SSH)
lock-passwd: false
sudo: ALL=(ALL) ALL
passwd: ${local_admin_passwd}
shell: /bin/bash
%{ endif }

write_files:
- path: /etc/ssh/sshd_config
Expand Down
15 changes: 13 additions & 2 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,17 @@ variable "os_img_url" {
default = "https://cloud-images.ubuntu.com/focal/current/focal-server-cloudimg-amd64.img"
}

variable "base_volume_name" {
description = "Name of base OS image"
default = null
}

variable "base_pool_name" {
description = "Name of base OS image"
default = null
}


variable "autostart" {
description = "Autostart the domain"
default = true
Expand Down Expand Up @@ -111,7 +122,7 @@ variable "ssh_keys" {

variable "local_admin" {
description = "Admin user without ssh access"
default = "local-admin"
default = ""
}

variable "local_admin_passwd" {
Expand All @@ -126,5 +137,5 @@ variable "time_zone" {

variable "ssh_private_key" {
description = "Private key for SSH connection test"
default = "~/.ssh/id_ed25519"
default = null
}

0 comments on commit afbe7f2

Please sign in to comment.