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.

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