From d8b0b3bc1559ac24247b0e80b388f80c828f504a Mon Sep 17 00:00:00 2001 From: Antonio Huete Jimenez Date: Thu, 19 Jan 2023 11:37:42 +0100 Subject: [PATCH 1/3] Allow SSH host/port override --- README.md | 2 ++ main.tf | 3 ++- variables.tf | 11 +++++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 5078d71..c66ed95 100644 --- a/README.md +++ b/README.md @@ -67,6 +67,8 @@ No modules. | [ssh\_admin](#input\_ssh\_admin) | Admin user with ssh access | `string` | `"ssh-admin"` | no | | [ssh\_keys](#input\_ssh\_keys) | List of public ssh keys | `list(string)` | `[]` | no | | [ssh\_private\_key](#input\_ssh\_private\_key) | Private key for SSH connection test | `any` | `null` | no | +| [ssh\_host\_override](#input\_ssh\_private\_key) | Host override for SSH connection test | `string` | `null` | no | +| [ssh\_port\_override](#input\_ssh\_private\_key) | Port override for SSH connection test | `string` | `"22"` | no | | [system\_volume](#input\_system\_volume) | System Volume size (GB) | `number` | `10` | no | | [time\_zone](#input\_time\_zone) | Time Zone | `string` | `"UTC"` | no | | [vcpu](#input\_vcpu) | Number of vCPUs | `number` | `1` | no | diff --git a/main.tf b/main.tf index 41e5f81..b5822a7 100644 --- a/main.tf +++ b/main.tf @@ -78,7 +78,8 @@ resource "libvirt_domain" "virt-machine" { connection { type = "ssh" user = var.ssh_admin - host = self.network_interface.0.addresses.0 + host = var.ssh_host_override != null ? var.ssh_host_override : self.network_interface.0.addresses.0 + port = var.ssh_port_override private_key = var.ssh_private_key != null ? file(var.ssh_private_key) : null timeout = "2m" } diff --git a/variables.tf b/variables.tf index 25aefb3..5a56a5b 100644 --- a/variables.tf +++ b/variables.tf @@ -167,6 +167,17 @@ variable "ssh_private_key" { default = null } +variable "ssh_host_override" { + description = "Host for SSH connection test" + default = null +} + +variable "ssh_port_override" { + description = "Port for SSH connection test" + default = 22 +} + + variable "runcmd" { description = "Extra commands to be run with cloud init" type = list(string) From 5717ae36833c13a6bcfb6fa719f93e82cefa954d Mon Sep 17 00:00:00 2001 From: Antonio Huete Jimenez Date: Thu, 19 Jan 2023 19:48:32 +0100 Subject: [PATCH 2/3] Allow specifying a bastion host for remote-exec provider --- main.tf | 14 +++++++++----- variables.tf | 10 ++++++++++ 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/main.tf b/main.tf index b5822a7..89c5ddc 100644 --- a/main.tf +++ b/main.tf @@ -76,11 +76,15 @@ resource "libvirt_domain" "virt-machine" { "date" ] connection { - type = "ssh" - user = var.ssh_admin - host = var.ssh_host_override != null ? var.ssh_host_override : self.network_interface.0.addresses.0 - port = var.ssh_port_override - private_key = var.ssh_private_key != null ? file(var.ssh_private_key) : null + type = "ssh" + user = var.ssh_admin + host = var.ssh_host_override != null ? var.ssh_host_override : self.network_interface.0.addresses.0 + port = var.ssh_port_override + private_key = var.ssh_private_key != null ? file(var.ssh_private_key) : null + bastion_host = try(var.ssh_bastion_connect["host"], "") != "" ? var.ssh_bastion_connect["host"] : null + bastion_user = try(var.ssh_bastion_connect["user"], "") != "" ? var.ssh_bastion_connect["user"] : null + bastion_port = try(var.ssh_bastion_connect["port"], "") != "" ? var.ssh_bastion_connect["port"] : null + bastion_private_key = try(var.ssh_bastion_connect["privkey"], null) != null ? var.ssh_bastion_connect["privkey"] : null timeout = "2m" } } diff --git a/variables.tf b/variables.tf index 5a56a5b..e042be4 100644 --- a/variables.tf +++ b/variables.tf @@ -177,6 +177,16 @@ variable "ssh_port_override" { default = 22 } +variable "ssh_bastion_connect" { + description = "Use a bastion host to connect through" + default = { + host = "" + port = "22" + user = "root" + passwd = "" + privkey = null + } +} variable "runcmd" { description = "Extra commands to be run with cloud init" From 4f6621d90226c4acc1336e9548a590305bfb1b1e Mon Sep 17 00:00:00 2001 From: Antonio Huete Jimenez Date: Sun, 3 Mar 2024 17:18:25 +0100 Subject: [PATCH 3/3] Allow specifying MAC address --- main.tf | 1 + variables.tf | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/main.tf b/main.tf index 89c5ddc..05ac606 100644 --- a/main.tf +++ b/main.tf @@ -25,6 +25,7 @@ resource "libvirt_domain" "virt-machine" { bridge = var.bridge wait_for_lease = true hostname = format("${var.vm_hostname_prefix}%02d", count.index + var.index_start) + mac = length(var.mac_address) == var.vm_count ? element(var.mac_address, count.index) : null } xml { diff --git a/variables.tf b/variables.tf index e042be4..66dbeab 100644 --- a/variables.tf +++ b/variables.tf @@ -120,6 +120,13 @@ variable "bridge" { default = "virbr0" } +variable "mac_address" { + description = "MAC address" + type = list + default = [] +} + + variable "ip_address" { description = "List of IP addresses" type = list(string)