github.com/SUSE/skuba@v1.4.17/ci/infra/vmware/worker-instance.tf (about) 1 data "template_file" "worker_repositories" { 2 template = file("cloud-init/repository.tpl") 3 count = length(var.repositories) 4 5 vars = { 6 repository_url = element(values(var.repositories), count.index) 7 repository_name = element(keys(var.repositories), count.index) 8 } 9 } 10 11 data "template_file" "worker_register_scc" { 12 template = file("cloud-init/register-scc.tpl") 13 count = var.caasp_registry_code == "" ? 0 : 1 14 15 vars = { 16 caasp_registry_code = var.caasp_registry_code 17 } 18 } 19 20 data "template_file" "worker_register_rmt" { 21 template = file("cloud-init/register-rmt.tpl") 22 count = var.rmt_server_name == "" ? 0 : 1 23 24 vars = { 25 rmt_server_name = var.rmt_server_name 26 } 27 } 28 29 data "template_file" "worker_commands" { 30 template = file("cloud-init/commands.tpl") 31 count = join("", var.packages) == "" ? 0 : 1 32 33 vars = { 34 packages = join(", ", var.packages) 35 } 36 } 37 38 data "template_file" "worker_cloud_init_metadata" { 39 template = file("cloud-init/metadata.tpl") 40 41 vars = { 42 network_config = base64gzip(data.local_file.network_cloud_init.content) 43 instance_id = "${var.stack_name}-worker" 44 } 45 } 46 47 data "template_file" "worker_cloud_init_userdata" { 48 template = file("cloud-init/common.tpl") 49 count = var.workers 50 51 vars = { 52 authorized_keys = join("\n", formatlist(" - %s", var.authorized_keys)) 53 repositories = join("\n", data.template_file.worker_repositories.*.rendered) 54 register_scc = join("\n", data.template_file.worker_register_scc.*.rendered) 55 register_rmt = join("\n", data.template_file.worker_register_rmt.*.rendered) 56 commands = join("\n", data.template_file.worker_commands.*.rendered) 57 ntp_servers = join("\n", formatlist(" - %s", var.ntp_servers)) 58 hostname = "${var.stack_name}-worker-${count.index}" 59 hostname_from_dhcp = var.hostname_from_dhcp == true ? "yes" : "no" 60 } 61 } 62 63 resource "vsphere_virtual_machine" "worker" { 64 depends_on = [vsphere_folder.folder] 65 66 count = var.workers 67 name = "${var.stack_name}-worker-${count.index}" 68 num_cpus = var.worker_cpus 69 memory = var.worker_memory 70 guest_id = var.guest_id 71 firmware = var.firmware 72 scsi_type = data.vsphere_virtual_machine.template.scsi_type 73 resource_pool_id = data.vsphere_resource_pool.pool.id 74 datastore_id = (var.vsphere_datastore == null ? null : data.vsphere_datastore.datastore[0].id) 75 datastore_cluster_id = (var.vsphere_datastore_cluster == null ? null : data.vsphere_datastore_cluster.datastore[0].id) 76 folder = var.cpi_enable == true ? vsphere_folder.folder[0].path : null 77 78 clone { 79 template_uuid = data.vsphere_virtual_machine.template.id 80 } 81 82 hardware_version = var.vsphere_hardware_version 83 84 disk { 85 label = "disk0" 86 size = var.worker_disk_size 87 } 88 89 extra_config = { 90 "guestinfo.metadata" = base64gzip(data.template_file.worker_cloud_init_metadata.rendered) 91 "guestinfo.metadata.encoding" = "gzip+base64" 92 "guestinfo.userdata" = base64gzip(data.template_file.worker_cloud_init_userdata[count.index].rendered) 93 "guestinfo.userdata.encoding" = "gzip+base64" 94 } 95 enable_disk_uuid = var.cpi_enable == true ? true : false 96 97 network_interface { 98 network_id = data.vsphere_network.network.id 99 } 100 } 101 102 resource "null_resource" "worker_wait_cloudinit" { 103 depends_on = [vsphere_virtual_machine.worker] 104 count = var.workers 105 106 connection { 107 host = element( 108 vsphere_virtual_machine.worker.*.guest_ip_addresses.0, 109 count.index, 110 ) 111 user = var.username 112 type = "ssh" 113 agent = true 114 } 115 116 provisioner "remote-exec" { 117 inline = [ 118 "cloud-init status --wait > /dev/null", 119 ] 120 } 121 }