Skip to content

Commit 9077c06

Browse files
Merge pull request #35 from MonolithProjects/develop
Develop to main
2 parents ce031aa + 466f0c6 commit 9077c06

File tree

4 files changed

+109
-9
lines changed

4 files changed

+109
-9
lines changed

README.md

+37-3
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ No modules.
5252
| <a name="input_bridge"></a> [bridge](#input\_bridge) | Bridge interface | `string` | `"virbr0"` | no |
5353
| <a name="input_cpu_mode"></a> [cpu\_mode](#input\_cpu\_mode) | CPU mode | `string` | `"host-passthrough"` | no |
5454
| <a name="input_dhcp"></a> [dhcp](#input\_dhcp) | Use DHCP or Static IP settings | `bool` | `false` | no |
55-
| <a name="input_graphics"></a> [graphics](#graphics) | Graphics type (can be '`spice`' or '`vnc`') | `string` | `spice` | no |
55+
| <a name="input_graphics"></a> [graphics](#input\_graphics) | Graphics type (can be '`spice`' or '`vnc`') | `string` | `spice` | no |
5656
| <a name="input_index_start"></a> [index\_start](#input\_index\_start) | From where the indexig start | `number` | `1` | no |
5757
| <a name="input_ip_address"></a> [ip\_address](#input\_ip\_address) | List of IP addresses | `list(string)` | <pre>[<br> "192.168.123.101"<br>]</pre> | no |
5858
| <a name="input_ip_gateway"></a> [ip\_gateway](#input\_ip\_gateway) | IP addresses of a gateway | `string` | `"192.168.123.1"` | no |
@@ -66,13 +66,17 @@ No modules.
6666
| <a name="input_share_filesystem"></a> [share\_filesystem](#input\_share\_filesystem) | n/a | <pre>object({<br> source = string<br> target = string<br> readonly = bool<br> mode = string<br> })</pre> | <pre>{<br> "mode": null,<br> "readonly": false,<br> "source": null,<br> "target": null<br>}</pre> | no |
6767
| <a name="input_ssh_admin"></a> [ssh\_admin](#input\_ssh\_admin) | Admin user with ssh access | `string` | `"ssh-admin"` | no |
6868
| <a name="input_ssh_keys"></a> [ssh\_keys](#input\_ssh\_keys) | List of public ssh keys | `list(string)` | `[]` | no |
69-
| <a name="input_ssh_private_key"></a> [ssh\_private\_key](#input\_ssh\_private\_key) | Private key for SSH connection test | `string` | `null` | no |
69+
| <a name="input_ssh_private_key"></a> [ssh\_private\_key](#input\_ssh\_private\_key) | Private key for SSH connection test (either path to file or key content) | `string` | `null` | no |
7070
| <a name="input_system_volume"></a> [system\_volume](#input\_system\_volume) | System Volume size (GB) | `number` | `10` | no |
7171
| <a name="input_time_zone"></a> [time\_zone](#input\_time\_zone) | Time Zone | `string` | `"UTC"` | no |
7272
| <a name="input_vcpu"></a> [vcpu](#input\_vcpu) | Number of vCPUs | `number` | `1` | no |
7373
| <a name="input_vm_count"></a> [vm\_count](#input\_vm\_count) | Number of VMs | `number` | `1` | no |
7474
| <a name="input_vm_hostname_prefix"></a> [vm\_hostname\_prefix](#input\_vm\_hostname\_prefix) | VM hostname prefix | `string` | `"vm"` | no |
75-
| <a name="input_xml_override"></a> [xml\_override](#input\_xml\_override) | With these variables you can: Enable hugepages; Set USB controllers; Attach USB devices | <pre>object({<br> hugepages = bool<br> usb_controllers = list(object({<br> model = string<br> }))<br> usb_devices = list(object({<br> vendor = string<br> product = string<br> }))<br> })</pre> | <pre>{<br> "hugepages": false,<br> "usb_controllers": [<br> {<br> "model": "piix3-uhci"<br> }<br> ],<br> "usb_devices": []<br>}</pre> | no |
75+
| <a name="input_xml_override"></a> [xml\_override](#input\_xml\_override) | With these variables you can: Enable hugepages; Set USB controllers; Attach USB devices | <pre>object({<br> hugepages = bool<br> usb_controllers = list(object({<br> model = string<br> }))<br> usb_devices = list(object({<br> vendor = string<br> product = string<br> }))<br> pci_devices_passthrough = list(object({<br> src_domain = string<br> src_bus = string<br> src_slot = string<br> src_func = string<br> dst_domain = string<br> dst_bus = string<br> dst_slot = string<br> dst_func = string<br> }))<br> })</pre> | <pre>{<br> "hugepages": false,<br> "usb_controllers": [<br> {<br> "model": "piix3-uhci"<br> }<br> ],<br> "usb_devices": []<br> "pci_devices_passthrough": []<br>}</pre> | no |
76+
| <a name="input_bastion_host"></a> [bastion\_host](#input\_bastion\_host) | ssh bastion host | `string` | `null` | no |
77+
| <a name="input_bastion_user"></a> [bastion\_user](#input\_bastion\_user) | ssh user on bastion host | `string` | `null` | no |
78+
| <a name="input_bastion_ssh_private_key"></a> [bastion\_ssh\_private\_key](#input\_bastion\_ssh\_private\_key) | ssh private key for bastion host (either path to file or key content) | `string` | `null` | no |
79+
7680

7781
## Outputs
7882

@@ -96,6 +100,11 @@ terraform {
96100
}
97101
}
98102
103+
resource "tls_private_key" "ecdsa-p384-bastion" {
104+
algorithm = "ECDSA"
105+
ecdsa_curve = "P384"
106+
}
107+
99108
provider "libvirt" {
100109
uri = "qemu+ssh://[email protected]/system"
101110
}
@@ -118,6 +127,9 @@ module "vm" {
118127
ssh_keys = [
119128
"ssh-ed25519 AAAAxxxxxxxxxxxxSSHxxxKEY example",
120129
]
130+
bastion_host = "10.0.0.1"
131+
bastion_user = "admin"
132+
bastion_ssh_private_key = tls_private_key.ecdsa-p384-bastion.private_key_pem
121133
time_zone = "CET"
122134
os_img_url = "file:///home/myuser/ubuntu-20.04-server-cloudimg-amd64.img"
123135
xml_override = {
@@ -133,6 +145,28 @@ module "vm" {
133145
product = "0xab28"
134146
}
135147
]
148+
pci_devices_passthrough = [
149+
{
150+
src_domain = "0x0000",
151+
src_bus = "0xc1",
152+
src_slot = "0x00",
153+
src_func = "0x0",
154+
dst_domain = "0x0000",
155+
dst_bus = "0x00",
156+
dst_slot = "0x08"
157+
dst_func = "0x0"
158+
},
159+
{
160+
src_domain = "0x0000",
161+
src_bus = "0xc1",
162+
src_slot = "0x00",
163+
src_func = "0x1",
164+
dst_domain = "0x0000",
165+
dst_bus = "0x00",
166+
dst_slot = "0x09"
167+
dst_func = "0x0"
168+
}
169+
]
136170
}
137171
}
138172

main.tf

+8-5
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,14 @@ resource "libvirt_domain" "virt-machine" {
7676
"date"
7777
]
7878
connection {
79-
type = "ssh"
80-
user = var.ssh_admin
81-
host = self.network_interface[0].addresses[0]
82-
private_key = var.ssh_private_key != null ? file(var.ssh_private_key) : null
83-
timeout = "2m"
79+
type = "ssh"
80+
user = var.ssh_admin
81+
host = self.network_interface[0].addresses[0]
82+
private_key = try(file(var.ssh_private_key), var.ssh_private_key, null)
83+
timeout = "2m"
84+
bastion_host = var.bastion_host
85+
bastion_user = var.bastion_user
86+
bastion_private_key = try(file(var.bastion_ssh_private_key), var.bastion_ssh_private_key, null)
8487
}
8588
}
8689
}

variables.tf

+41-1
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,16 @@ variable "xml_override" {
7070
vendor = string
7171
product = string
7272
}))
73+
pci_devices_passthrough = list(object({
74+
src_domain = string
75+
src_bus = string
76+
src_slot = string
77+
src_func = string
78+
dst_domain = string
79+
dst_bus = string
80+
dst_slot = string
81+
dst_func = string
82+
}))
7383
})
7484
default = {
7585

@@ -86,6 +96,18 @@ variable "xml_override" {
8696
# vendor = "0x0123",
8797
# product = "0xabcd"
8898
# }
99+
],
100+
pci_devices_passthrough = [
101+
#{
102+
# src_domain = "0x0000",
103+
# src_bus = "0xc1",
104+
# src_slot = "0x00",
105+
# src_func = "0x0",
106+
# dst_domain = "0x0000",
107+
# dst_bus = "0x00",
108+
# dst_slot = "0x08"
109+
# dst_func = "0x0"
110+
#}
89111
]
90112
}
91113

@@ -185,7 +207,7 @@ variable "time_zone" {
185207
}
186208

187209
variable "ssh_private_key" {
188-
description = "Private key for SSH connection test"
210+
description = "Private key for SSH connection test (either path to file or key content)"
189211
type = string
190212
default = null
191213
}
@@ -211,3 +233,21 @@ variable "graphics" {
211233
error_message = "Graphics type not supported. Only 'spice' or 'vnc' are valid options."
212234
}
213235
}
236+
237+
variable "bastion_host" {
238+
description = "Bastion host"
239+
type = string
240+
default = null
241+
}
242+
243+
variable "bastion_user" {
244+
description = "Bastion ssh user"
245+
type = string
246+
default = null
247+
}
248+
249+
variable "bastion_ssh_private_key" {
250+
description = "Bastion private key for SSH connection test (either path to file or key content)"
251+
type = string
252+
default = null
253+
}

xslt/template.tftpl

+23
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,29 @@
4444
<xsl:attribute name="model">${usb_controller.model}</xsl:attribute>
4545
</xsl:element>
4646
%{ endfor ~}
47+
%{if pci_devices_passthrough != [] ~}
48+
%{ for pci_devices in pci_devices_passthrough ~}
49+
<xsl:element name="hostdev">
50+
<xsl:attribute name="type">pci</xsl:attribute>
51+
<xsl:attribute name="managed">yes</xsl:attribute>
52+
<xsl:element name="source">
53+
<xsl:element name="address">
54+
<xsl:attribute name="domain">${pci_devices.src_domain}</xsl:attribute>
55+
<xsl:attribute name="bus">${pci_devices.src_bus}</xsl:attribute>
56+
<xsl:attribute name="slot">${pci_devices.src_slot}</xsl:attribute>
57+
<xsl:attribute name="function">${pci_devices.src_func}</xsl:attribute>
58+
</xsl:element>
59+
</xsl:element>
60+
<xsl:element name="address">
61+
<xsl:attribute name="type">pci</xsl:attribute>
62+
<xsl:attribute name="domain">${pci_devices.dst_domain}</xsl:attribute>
63+
<xsl:attribute name="bus">${pci_devices.dst_bus}</xsl:attribute>
64+
<xsl:attribute name="slot">${pci_devices.dst_slot}</xsl:attribute>
65+
<xsl:attribute name="function">${pci_devices.dst_func}</xsl:attribute>
66+
</xsl:element>
67+
</xsl:element>
68+
%{ endfor ~}
69+
%{ endif ~}
4770
</xsl:copy>
4871
</xsl:template>
4972
</xsl:stylesheet>

0 commit comments

Comments
 (0)