You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

149 lines
4.3 KiB

  1. resource "vsphere_virtual_machine" "worker" {
  2. for_each = {
  3. for name, machine in var.machines :
  4. name => machine
  5. if machine.node_type == "worker"
  6. }
  7. name = "${var.prefix}-${each.key}"
  8. resource_pool_id = var.pool_id
  9. datastore_id = var.datastore_id
  10. num_cpus = var.worker_cores
  11. memory = var.worker_memory
  12. memory_reservation = var.worker_memory
  13. guest_id = var.guest_id
  14. enable_disk_uuid = "true" # needed for CSI provider
  15. scsi_type = var.scsi_type
  16. folder = var.folder
  17. firmware = var.firmware
  18. hardware_version = var.hardware_version
  19. wait_for_guest_net_routable = false
  20. wait_for_guest_net_timeout = 0
  21. network_interface {
  22. network_id = var.network_id
  23. adapter_type = var.adapter_type
  24. }
  25. disk {
  26. label = "disk0"
  27. size = var.worker_disk_size
  28. thin_provisioned = var.disk_thin_provisioned
  29. }
  30. lifecycle {
  31. ignore_changes = [disk]
  32. }
  33. clone {
  34. template_uuid = var.template_id
  35. }
  36. cdrom {
  37. client_device = true
  38. }
  39. dynamic "vapp" {
  40. for_each = var.vapp ? [1] : []
  41. content {
  42. properties = {
  43. "user-data" = base64encode(templatefile("${path.module}/templates/vapp-cloud-init.tpl", { ssh_public_keys = var.ssh_public_keys }))
  44. }
  45. }
  46. }
  47. extra_config = {
  48. "isolation.tools.copy.disable" = "FALSE"
  49. "isolation.tools.paste.disable" = "FALSE"
  50. "isolation.tools.setGUIOptions.enable" = "TRUE"
  51. "guestinfo.userdata" = base64encode(templatefile("${path.module}/templates/cloud-init.tpl", { ssh_public_keys = var.ssh_public_keys }))
  52. "guestinfo.userdata.encoding" = "base64"
  53. "guestinfo.metadata" = base64encode(templatefile("${path.module}/templates/metadata.tpl", { hostname = "${var.prefix}-${each.key}",
  54. interface_name = var.interface_name
  55. ip = each.value.ip,
  56. netmask = each.value.netmask,
  57. gw = var.gateway,
  58. dns = var.dns_primary,
  59. ssh_public_keys = var.ssh_public_keys }))
  60. "guestinfo.metadata.encoding" = "base64"
  61. }
  62. }
  63. resource "vsphere_virtual_machine" "master" {
  64. for_each = {
  65. for name, machine in var.machines :
  66. name => machine
  67. if machine.node_type == "master"
  68. }
  69. name = "${var.prefix}-${each.key}"
  70. resource_pool_id = var.pool_id
  71. datastore_id = var.datastore_id
  72. num_cpus = var.master_cores
  73. memory = var.master_memory
  74. memory_reservation = var.master_memory
  75. guest_id = var.guest_id
  76. enable_disk_uuid = "true" # needed for CSI provider
  77. scsi_type = var.scsi_type
  78. folder = var.folder
  79. firmware = var.firmware
  80. hardware_version = var.hardware_version
  81. wait_for_guest_net_routable = false
  82. wait_for_guest_net_timeout = 0
  83. network_interface {
  84. network_id = var.network_id
  85. adapter_type = var.adapter_type
  86. }
  87. disk {
  88. label = "disk0"
  89. size = var.master_disk_size
  90. thin_provisioned = var.disk_thin_provisioned
  91. }
  92. lifecycle {
  93. ignore_changes = [disk]
  94. }
  95. clone {
  96. template_uuid = var.template_id
  97. }
  98. cdrom {
  99. client_device = true
  100. }
  101. dynamic "vapp" {
  102. for_each = var.vapp ? [1] : []
  103. content {
  104. properties = {
  105. "user-data" = base64encode(templatefile("${path.module}/templates/vapp-cloud-init.tpl", { ssh_public_keys = var.ssh_public_keys }))
  106. }
  107. }
  108. }
  109. extra_config = {
  110. "isolation.tools.copy.disable" = "FALSE"
  111. "isolation.tools.paste.disable" = "FALSE"
  112. "isolation.tools.setGUIOptions.enable" = "TRUE"
  113. "guestinfo.userdata" = base64encode(templatefile("${path.module}/templates/cloud-init.tpl", { ssh_public_keys = var.ssh_public_keys }))
  114. "guestinfo.userdata.encoding" = "base64"
  115. "guestinfo.metadata" = base64encode(templatefile("${path.module}/templates/metadata.tpl", { hostname = "${var.prefix}-${each.key}",
  116. interface_name = var.interface_name
  117. ip = each.value.ip,
  118. netmask = each.value.netmask,
  119. gw = var.gateway,
  120. dns = var.dns_primary,
  121. ssh_public_keys = var.ssh_public_keys }))
  122. "guestinfo.metadata.encoding" = "base64"
  123. }
  124. }