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.

74 lines
2.3 KiB

  1. terraform {
  2. required_version = ">= 0.13.0"
  3. }
  4. provider "upcloud" {
  5. # Your UpCloud credentials are read from environment variables:
  6. username = var.UPCLOUD_USERNAME
  7. password = var.UPCLOUD_PASSWORD
  8. }
  9. module "kubernetes" {
  10. source = "./modules/kubernetes-cluster"
  11. prefix = var.prefix
  12. zone = var.zone
  13. template_name = var.template_name
  14. username = var.username
  15. private_network_cidr = var.private_network_cidr
  16. machines = var.machines
  17. ssh_public_keys = var.ssh_public_keys
  18. firewall_enabled = var.firewall_enabled
  19. firewall_default_deny_in = var.firewall_default_deny_in
  20. firewall_default_deny_out = var.firewall_default_deny_out
  21. master_allowed_remote_ips = var.master_allowed_remote_ips
  22. k8s_allowed_remote_ips = var.k8s_allowed_remote_ips
  23. master_allowed_ports = var.master_allowed_ports
  24. worker_allowed_ports = var.worker_allowed_ports
  25. loadbalancer_enabled = var.loadbalancer_enabled
  26. loadbalancer_plan = var.loadbalancer_plan
  27. loadbalancer_outbound_proxy_protocol = var.loadbalancer_proxy_protocol ? "v2" : ""
  28. loadbalancers = var.loadbalancers
  29. server_groups = var.server_groups
  30. }
  31. #
  32. # Generate ansible inventory
  33. #
  34. data "template_file" "inventory" {
  35. template = file("${path.module}/templates/inventory.tpl")
  36. vars = {
  37. connection_strings_master = join("\n", formatlist("%s ansible_user=ubuntu ansible_host=%s ip=%s etcd_member_name=etcd%d",
  38. keys(module.kubernetes.master_ip),
  39. values(module.kubernetes.master_ip).*.public_ip,
  40. values(module.kubernetes.master_ip).*.private_ip,
  41. range(1, length(module.kubernetes.master_ip) + 1)))
  42. connection_strings_worker = join("\n", formatlist("%s ansible_user=ubuntu ansible_host=%s ip=%s",
  43. keys(module.kubernetes.worker_ip),
  44. values(module.kubernetes.worker_ip).*.public_ip,
  45. values(module.kubernetes.worker_ip).*.private_ip))
  46. list_master = join("\n", formatlist("%s",
  47. keys(module.kubernetes.master_ip)))
  48. list_worker = join("\n", formatlist("%s",
  49. keys(module.kubernetes.worker_ip)))
  50. }
  51. }
  52. resource "null_resource" "inventories" {
  53. provisioner "local-exec" {
  54. command = "echo '${data.template_file.inventory.rendered}' > ${var.inventory_file}"
  55. }
  56. triggers = {
  57. template = data.template_file.inventory.rendered
  58. }
  59. }