Created
December 8, 2020 03:53
-
-
Save corrigat/91bd21f8e65eb74300417fc39b1da4c7 to your computer and use it in GitHub Desktop.
Packer HCL template for VM with nested virtualization enabled
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
source "vsphere-iso" "centos7-base" { | |
# vCenter settings | |
vcenter_server = var.vcenter_server | |
username = var.vcenter_username | |
password = var.vcenter_password | |
insecure_connection = true | |
cluster = var.vcenter_cluster | |
datacenter = var.vcenter_datacenter | |
#host = var.vcenter_host | |
datastore = var.vcenter_datastore | |
convert_to_template = false | |
folder = var.vcenter_folder | |
NestedHV = true | |
configuration_parameters = { | |
"featMask.vm.hv.capable" = "Min:1" | |
"vhv.enable" = "TRUE" | |
} | |
# VM Settings | |
ip_wait_timeout = "45m" | |
ssh_username = var.connection_username | |
ssh_password = var.connection_password | |
ssh_timeout = "12h" | |
ssh_port = "22" | |
ssh_handshake_attempts = "20" | |
shutdown_timeout = "15m" | |
vm_version = var.vm_hardware_version | |
iso_paths = [var.os_iso_path] | |
iso_checksum = var.iso_checksum | |
vm_name = var.vm_name | |
guest_os_type = var.guest_os_type | |
disk_controller_type = ["pvscsi"] | |
floppy_files = ["boot_config/ks.cfg"] | |
network_adapters { | |
network = var.vm_network | |
network_card = var.nic_type | |
} | |
storage { | |
disk_size = var.root_disk_size | |
disk_thin_provisioned = true | |
} | |
CPUs = var.num_cpu | |
cpu_cores = var.num_cores | |
RAM = var.vm_ram | |
boot_wait = "5s" | |
boot_command = var.boot_command | |
} | |
build { | |
sources = [ | |
"source.vsphere-iso.centos7-base", | |
] | |
provisioner "shell" { | |
execute_command = "echo '${var.connection_password}' | {{.Vars}} sudo -S -E sh -eux '{{.Path}}'" # Scripts requiring sudo | |
scripts = [ | |
"scripts/vmware-tools.sh", | |
"scripts/yum-update.sh", | |
"scripts/cleanup-centos.sh", | |
"scripts/clean-ssh-key.sh" | |
] | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment