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.

71 lines
2.1 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. loadbalancers = var.loadbalancers
  28. }
  29. #
  30. # Generate ansible inventory
  31. #
  32. data "template_file" "inventory" {
  33. template = file("${path.module}/templates/inventory.tpl")
  34. vars = {
  35. connection_strings_master = join("\n", formatlist("%s ansible_user=ubuntu ansible_host=%s ip=%s etcd_member_name=etcd%d",
  36. keys(module.kubernetes.master_ip),
  37. values(module.kubernetes.master_ip).*.public_ip,
  38. values(module.kubernetes.master_ip).*.private_ip,
  39. range(1, length(module.kubernetes.master_ip) + 1)))
  40. connection_strings_worker = join("\n", formatlist("%s ansible_user=ubuntu ansible_host=%s ip=%s",
  41. keys(module.kubernetes.worker_ip),
  42. values(module.kubernetes.worker_ip).*.public_ip,
  43. values(module.kubernetes.worker_ip).*.private_ip))
  44. list_master = join("\n", formatlist("%s",
  45. keys(module.kubernetes.master_ip)))
  46. list_worker = join("\n", formatlist("%s",
  47. keys(module.kubernetes.worker_ip)))
  48. }
  49. }
  50. resource "null_resource" "inventories" {
  51. provisioner "local-exec" {
  52. command = "echo '${data.template_file.inventory.rendered}' > ${var.inventory_file}"
  53. }
  54. triggers = {
  55. template = data.template_file.inventory.rendered
  56. }
  57. }