Last active
February 13, 2024 09:08
-
-
Save adeturner/844ec33d4210a1b6741842980fc30efd to your computer and use it in GitHub Desktop.
vsphere remote_exec example
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
resource "vsphere_virtual_machine" "runner" { | |
name = local.hostname | |
datastore_id = data.vsphere_datastore.datastore.id | |
resource_pool_id = vsphere_resource_pool.workload_rp.id | |
folder = vsphere_folder.workload_folder.path | |
wait_for_guest_net_timeout = 5 | |
firmware = "efi" | |
network_interface { | |
network_id = data.vsphere_network.network.id | |
} | |
disk { | |
label = "disk0" | |
size = var.vm_os_disk_gb | |
unit_number = 0 # must be unique (default 0) | |
} | |
disk { | |
label = "disk1" | |
attach = true | |
datastore_id = data.vsphere_datastore.datastore.id | |
path = vsphere_virtual_disk.runner_data.vmdk_path | |
unit_number = 1 # must be unique | |
} | |
clone { | |
template_uuid = data.vsphere_content_library_item.RUNNER_OVF.id | |
customize { | |
# ... other configuration ... | |
linux_options { | |
host_name = lower(local.hostname) | |
domain = var.network_domain_str | |
} | |
# use dhcp if blank | |
network_interface {} | |
} | |
} | |
connection { | |
type = "ssh" | |
user = var.adminuser_name | |
password = azurerm_key_vault_secret.workload_packer_admin_password.value | |
host = self.default_ip_address | |
} | |
provisioner "file" { | |
source = "workload.sh" | |
destination = "/tmp/workload.sh" | |
} | |
provisioner "remote-exec" { | |
inline = [ | |
"sudo bash /tmp/workload.sh ${var.adminuser_name} ${local.public_ssh_key} > /tmp/workload.log 2>&1", | |
] | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment