Proposing fixes for contrib/terraform/vsphere/ #8436 (#8441)

* fixes issues in vSphere Terraform contrib. #8436

* fix formatting

* add variables to the main module and document changes

* add missing newline
This commit is contained in:
ceesios
2022-01-25 14:24:30 +01:00
committed by GitHub
parent d64b341b38
commit d86a3b962c
11 changed files with 95 additions and 63 deletions

View File

@@ -46,15 +46,31 @@ resource "vsphere_virtual_machine" "worker" {
client_device = true
}
vapp {
properties = {
"user-data" = base64encode(templatefile("${path.module}/templates/cloud-init.tmpl", { ip = each.value.ip,
netmask = each.value.netmask,
gw = var.gateway,
dns = var.dns_primary,
ssh_public_keys = var.ssh_public_keys}))
dynamic "vapp" {
for_each = var.vapp ? [1] : []
content {
properties = {
"user-data" = base64encode(templatefile("${path.module}/templates/vapp-cloud-init.tpl", { ssh_public_keys = var.ssh_public_keys }))
}
}
}
extra_config = {
"isolation.tools.copy.disable" = "FALSE"
"isolation.tools.paste.disable" = "FALSE"
"isolation.tools.setGUIOptions.enable" = "TRUE"
"guestinfo.userdata" = base64encode(templatefile("${path.module}/templates/cloud-init.tpl", { ssh_public_keys = var.ssh_public_keys }))
"guestinfo.userdata.encoding" = "base64"
"guestinfo.metadata" = base64encode(templatefile("${path.module}/templates/metadata.tpl", { hostname = "${var.prefix}-${each.key}",
interface_name = var.interface_name
ip = each.value.ip,
netmask = each.value.netmask,
gw = var.gateway,
dns = var.dns_primary,
ssh_public_keys = var.ssh_public_keys }))
"guestinfo.metadata.encoding" = "base64"
}
}
resource "vsphere_virtual_machine" "master" {
@@ -105,13 +121,29 @@ resource "vsphere_virtual_machine" "master" {
client_device = true
}
vapp {
properties = {
"user-data" = base64encode(templatefile("${path.module}/templates/cloud-init.tmpl", { ip = each.value.ip,
netmask = each.value.netmask,
gw = var.gateway,
dns = var.dns_primary,
ssh_public_keys = var.ssh_public_keys}))
dynamic "vapp" {
for_each = var.vapp ? [1] : []
content {
properties = {
"user-data" = base64encode(templatefile("${path.module}/templates/vapp-cloud-init.tpl", { ssh_public_keys = var.ssh_public_keys }))
}
}
}
extra_config = {
"isolation.tools.copy.disable" = "FALSE"
"isolation.tools.paste.disable" = "FALSE"
"isolation.tools.setGUIOptions.enable" = "TRUE"
"guestinfo.userdata" = base64encode(templatefile("${path.module}/templates/cloud-init.tpl", { ssh_public_keys = var.ssh_public_keys }))
"guestinfo.userdata.encoding" = "base64"
"guestinfo.metadata" = base64encode(templatefile("${path.module}/templates/metadata.tpl", { hostname = "${var.prefix}-${each.key}",
interface_name = var.interface_name
ip = each.value.ip,
netmask = each.value.netmask,
gw = var.gateway,
dns = var.dns_primary,
ssh_public_keys = var.ssh_public_keys }))
"guestinfo.metadata.encoding" = "base64"
}
}

View File

@@ -1,7 +1,7 @@
output "master_ip" {
value = {
for name, machine in var.machines :
name => machine.ip
"${var.prefix}-${name}" => machine.ip
if machine.node_type == "master"
}
}
@@ -9,8 +9,7 @@ output "master_ip" {
output "worker_ip" {
value = {
for name, machine in var.machines :
name => machine.ip
"${var.prefix}-${name}" => machine.ip
if machine.node_type == "worker"
}
}

View File

@@ -0,0 +1,6 @@
#cloud-config
ssh_authorized_keys:
%{ for ssh_public_key in ssh_public_keys ~}
- ${ssh_public_key}
%{ endfor ~}

View File

@@ -0,0 +1,14 @@
instance-id: ${hostname}
local-hostname: ${hostname}
network:
version: 2
ethernets:
${interface_name}:
match:
name: ${interface_name}
dhcp4: false
addresses:
- ${ip}/${netmask}
gateway4: ${gw}
nameservers:
addresses: [${dns}]

View File

@@ -6,23 +6,12 @@ ssh_authorized_keys:
%{ endfor ~}
write_files:
- path: /etc/netplan/20-internal-network.yaml
content: |
network:
version: 2
ethernets:
"lo:0":
match:
name: lo
dhcp4: false
addresses:
- 172.17.0.100/32
- path: /etc/netplan/10-user-network.yaml
content: |
content: |.
network:
version: 2
ethernets:
ens192:
${interface_name}:
dhcp4: false #true to use dhcp
addresses:
- ${ip}/${netmask}

View File

@@ -18,9 +18,13 @@ variable "datastore_id" {}
variable "guest_id" {}
variable "scsi_type" {}
variable "network_id" {}
variable "interface_name" {}
variable "adapter_type" {}
variable "disk_thin_provisioned" {}
variable "template_id" {}
variable "vapp" {
type = bool
}
variable "firmware" {}
variable "folder" {}
variable "ssh_public_keys" {