add support for file share
This commit is contained in:
parent
a286450d0a
commit
308e572471
3 changed files with 33 additions and 0 deletions
|
@ -3,9 +3,11 @@ hostname: "${name}"
|
||||||
manage_etc_hosts: true
|
manage_etc_hosts: true
|
||||||
disable_root: false
|
disable_root: false
|
||||||
ssh_authorized_keys:
|
ssh_authorized_keys:
|
||||||
|
|
||||||
%{ for key in admin_authorized_keys ~}
|
%{ for key in admin_authorized_keys ~}
|
||||||
- "${key}"
|
- "${key}"
|
||||||
%{ endfor ~}
|
%{ endfor ~}
|
||||||
|
|
||||||
%{ if insecure_password }
|
%{ if insecure_password }
|
||||||
chpasswd:
|
chpasswd:
|
||||||
list: |
|
list: |
|
||||||
|
@ -15,12 +17,14 @@ ssh_pwauth: true
|
||||||
%{ else }
|
%{ else }
|
||||||
ssh_pwauth: false
|
ssh_pwauth: false
|
||||||
%{ endif }
|
%{ endif }
|
||||||
|
|
||||||
%{ if use_host_cert }
|
%{ if use_host_cert }
|
||||||
ssh_keys:
|
ssh_keys:
|
||||||
ed25519_private: |
|
ed25519_private: |
|
||||||
${indent(4, private_key)}
|
${indent(4, private_key)}
|
||||||
ed25519_certificate: "${host_cert}"
|
ed25519_certificate: "${host_cert}"
|
||||||
%{ endif}
|
%{ endif}
|
||||||
|
|
||||||
write_files:
|
write_files:
|
||||||
- path: /etc/default/locale
|
- path: /etc/default/locale
|
||||||
content: |
|
content: |
|
||||||
|
@ -29,10 +33,12 @@ write_files:
|
||||||
- path: /etc/locale.gen
|
- path: /etc/locale.gen
|
||||||
content: |
|
content: |
|
||||||
en_US.UTF-8 UTF-8
|
en_US.UTF-8 UTF-8
|
||||||
|
|
||||||
runcmd:
|
runcmd:
|
||||||
- dhclient -r
|
- dhclient -r
|
||||||
- dhclient
|
- dhclient
|
||||||
- locale-gen
|
- locale-gen
|
||||||
|
|
||||||
%{ if data_disk }
|
%{ if data_disk }
|
||||||
device_aliases:
|
device_aliases:
|
||||||
data: /dev/vdb
|
data: /dev/vdb
|
||||||
|
@ -46,9 +52,18 @@ fs_setup:
|
||||||
filesystem: 'ext4'
|
filesystem: 'ext4'
|
||||||
device: data.1
|
device: data.1
|
||||||
overwrite: false
|
overwrite: false
|
||||||
|
%{ endif }
|
||||||
|
|
||||||
|
%{ if data_disk || add_data_share }
|
||||||
mounts:
|
mounts:
|
||||||
|
%{ if data_disk }
|
||||||
- ["data.1", "/mnt/data"]
|
- ["data.1", "/mnt/data"]
|
||||||
%{ endif }
|
%{ endif }
|
||||||
|
%{ if add_data_share }
|
||||||
|
- ["data", "/mnt/data", "9p", "trans=virtio", "0", "0"]
|
||||||
|
%{ endif }
|
||||||
|
%{ endif }
|
||||||
|
|
||||||
%{ if fixed_dns != "" }
|
%{ if fixed_dns != "" }
|
||||||
manage_resolv_conf: true
|
manage_resolv_conf: true
|
||||||
resolv_conf:
|
resolv_conf:
|
||||||
|
|
12
main.tf
12
main.tf
|
@ -16,6 +16,7 @@ locals {
|
||||||
private_key = tls_private_key.debian.private_key_openssh,
|
private_key = tls_private_key.debian.private_key_openssh,
|
||||||
data_disk = var.data_disk != null
|
data_disk = var.data_disk != null
|
||||||
fixed_dns = var.fixed_dns
|
fixed_dns = var.fixed_dns
|
||||||
|
add_data_share = var.add_data_share
|
||||||
})
|
})
|
||||||
cloudinit_network_config = templatefile("${path.module}/files/network_config.cfg.tftpl", {
|
cloudinit_network_config = templatefile("${path.module}/files/network_config.cfg.tftpl", {
|
||||||
fixed_address = var.fixed_address
|
fixed_address = var.fixed_address
|
||||||
|
@ -93,11 +94,22 @@ resource "libvirt_domain" "debian" {
|
||||||
|
|
||||||
dynamic "disk" {
|
dynamic "disk" {
|
||||||
for_each = var.data_disk != null ? [1] : []
|
for_each = var.data_disk != null ? [1] : []
|
||||||
|
|
||||||
content {
|
content {
|
||||||
volume_id = var.data_disk
|
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 {
|
network_interface {
|
||||||
bridge = var.bridge_name
|
bridge = var.bridge_name
|
||||||
hostname = var.name
|
hostname = var.name
|
||||||
|
|
|
@ -106,3 +106,9 @@ variable "fixed_dns" {
|
||||||
default = ""
|
default = ""
|
||||||
description = "Fixed DNS server the machine should have."
|
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."
|
||||||
|
}
|
||||||
|
|
Reference in a new issue