add support for file share

This commit is contained in:
Pim Kunis 2023-04-25 22:33:57 +02:00
parent a286450d0a
commit 308e572471
3 changed files with 33 additions and 0 deletions

View file

@ -3,9 +3,11 @@ hostname: "${name}"
manage_etc_hosts: true
disable_root: false
ssh_authorized_keys:
%{ for key in admin_authorized_keys ~}
- "${key}"
%{ endfor ~}
%{ if insecure_password }
chpasswd:
list: |
@ -15,12 +17,14 @@ ssh_pwauth: true
%{ else }
ssh_pwauth: false
%{ endif }
%{ if use_host_cert }
ssh_keys:
ed25519_private: |
${indent(4, private_key)}
ed25519_certificate: "${host_cert}"
%{ endif}
write_files:
- path: /etc/default/locale
content: |
@ -29,10 +33,12 @@ write_files:
- path: /etc/locale.gen
content: |
en_US.UTF-8 UTF-8
runcmd:
- dhclient -r
- dhclient
- locale-gen
%{ if data_disk }
device_aliases:
data: /dev/vdb
@ -46,9 +52,18 @@ fs_setup:
filesystem: 'ext4'
device: data.1
overwrite: false
%{ endif }
%{ if data_disk || add_data_share }
mounts:
%{ if data_disk }
- ["data.1", "/mnt/data"]
%{ endif }
%{ if add_data_share }
- ["data", "/mnt/data", "9p", "trans=virtio", "0", "0"]
%{ endif }
%{ endif }
%{ if fixed_dns != "" }
manage_resolv_conf: true
resolv_conf:

12
main.tf
View file

@ -16,6 +16,7 @@ locals {
private_key = tls_private_key.debian.private_key_openssh,
data_disk = var.data_disk != null
fixed_dns = var.fixed_dns
add_data_share = var.add_data_share
})
cloudinit_network_config = templatefile("${path.module}/files/network_config.cfg.tftpl", {
fixed_address = var.fixed_address
@ -93,11 +94,22 @@ resource "libvirt_domain" "debian" {
dynamic "disk" {
for_each = var.data_disk != null ? [1] : []
content {
volume_id = var.data_disk
}
}
dynamic "filesystem" {
for_each = var.add_data_share ? [1] : []
content {
source = "/data/${local.domain_name}/"
target = "data"
readonly = false
}
}
network_interface {
bridge = var.bridge_name
hostname = var.name

View file

@ -106,3 +106,9 @@ variable "fixed_dns" {
default = ""
description = "Fixed DNS server the machine should have."
}
variable "add_data_share" {
type = bool
default = true
description = "Whether to share /data with the guest OS."
}