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.

100 lines
3.1 KiB

  1. provider "vsphere" {
  2. # Username and password set through env vars VSPHERE_USER and VSPHERE_PASSWORD
  3. user = var.vsphere_user
  4. password = var.vsphere_password
  5. vsphere_server = var.vsphere_server
  6. # If you have a self-signed cert
  7. allow_unverified_ssl = true
  8. }
  9. data "vsphere_datacenter" "dc" {
  10. name = var.vsphere_datacenter
  11. }
  12. data "vsphere_datastore" "datastore" {
  13. name = var.vsphere_datastore
  14. datacenter_id = data.vsphere_datacenter.dc.id
  15. }
  16. data "vsphere_network" "network" {
  17. name = var.network
  18. datacenter_id = data.vsphere_datacenter.dc.id
  19. }
  20. data "vsphere_virtual_machine" "template" {
  21. name = var.template_name
  22. datacenter_id = data.vsphere_datacenter.dc.id
  23. }
  24. data "vsphere_compute_cluster" "compute_cluster" {
  25. name = var.vsphere_compute_cluster
  26. datacenter_id = data.vsphere_datacenter.dc.id
  27. }
  28. resource "vsphere_resource_pool" "pool" {
  29. name = "${var.prefix}-cluster-pool"
  30. parent_resource_pool_id = data.vsphere_compute_cluster.compute_cluster.resource_pool_id
  31. }
  32. module "kubernetes" {
  33. source = "./modules/kubernetes-cluster"
  34. prefix = var.prefix
  35. machines = var.machines
  36. ## Master ##
  37. master_cores = var.master_cores
  38. master_memory = var.master_memory
  39. master_disk_size = var.master_disk_size
  40. ## Worker ##
  41. worker_cores = var.worker_cores
  42. worker_memory = var.worker_memory
  43. worker_disk_size = var.worker_disk_size
  44. ## Global ##
  45. gateway = var.gateway
  46. dns_primary = var.dns_primary
  47. dns_secondary = var.dns_secondary
  48. pool_id = vsphere_resource_pool.pool.id
  49. datastore_id = data.vsphere_datastore.datastore.id
  50. folder = var.folder
  51. guest_id = data.vsphere_virtual_machine.template.guest_id
  52. scsi_type = data.vsphere_virtual_machine.template.scsi_type
  53. network_id = data.vsphere_network.network.id
  54. adapter_type = data.vsphere_virtual_machine.template.network_interface_types[0]
  55. interface_name = var.interface_name
  56. firmware = var.firmware
  57. hardware_version = var.hardware_version
  58. disk_thin_provisioned = data.vsphere_virtual_machine.template.disks.0.thin_provisioned
  59. template_id = data.vsphere_virtual_machine.template.id
  60. vapp = var.vapp
  61. ssh_public_keys = var.ssh_public_keys
  62. }
  63. #
  64. # Generate ansible inventory
  65. #
  66. resource "local_file" "inventory" {
  67. content = templatefile("${path.module}/templates/inventory.tpl", {
  68. connection_strings_master = join("\n", formatlist("%s ansible_user=ubuntu ansible_host=%s etcd_member_name=etcd%d",
  69. keys(module.kubernetes.master_ip),
  70. values(module.kubernetes.master_ip),
  71. range(1, length(module.kubernetes.master_ip) + 1))),
  72. connection_strings_worker = join("\n", formatlist("%s ansible_user=ubuntu ansible_host=%s",
  73. keys(module.kubernetes.worker_ip),
  74. values(module.kubernetes.worker_ip))),
  75. list_master = join("\n", formatlist("%s", keys(module.kubernetes.master_ip))),
  76. list_worker = join("\n", formatlist("%s", keys(module.kubernetes.worker_ip)))
  77. })
  78. filename = var.inventory_file
  79. }