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.

167 lines
5.8 KiB

  1. resource "openstack_networking_floatingip_v2" "k8s_master" {
  2. count = "${var.number_of_k8s_masters}"
  3. pool = "${var.floatingip_pool}"
  4. }
  5. resource "openstack_networking_floatingip_v2" "k8s_node" {
  6. count = "${var.number_of_k8s_nodes}"
  7. pool = "${var.floatingip_pool}"
  8. }
  9. resource "openstack_compute_keypair_v2" "k8s" {
  10. name = "kubernetes-${var.cluster_name}"
  11. public_key = "${file(var.public_key_path)}"
  12. }
  13. resource "openstack_compute_secgroup_v2" "k8s_master" {
  14. name = "${var.cluster_name}-k8s-master"
  15. description = "${var.cluster_name} - Kubernetes Master"
  16. }
  17. resource "openstack_compute_secgroup_v2" "k8s" {
  18. name = "${var.cluster_name}-k8s"
  19. description = "${var.cluster_name} - Kubernetes"
  20. rule {
  21. ip_protocol = "tcp"
  22. from_port = "22"
  23. to_port = "22"
  24. cidr = "0.0.0.0/0"
  25. }
  26. rule {
  27. ip_protocol = "icmp"
  28. from_port = "-1"
  29. to_port = "-1"
  30. cidr = "0.0.0.0/0"
  31. }
  32. rule {
  33. ip_protocol = "tcp"
  34. from_port = "1"
  35. to_port = "65535"
  36. self = true
  37. }
  38. rule {
  39. ip_protocol = "udp"
  40. from_port = "1"
  41. to_port = "65535"
  42. self = true
  43. }
  44. rule {
  45. ip_protocol = "icmp"
  46. from_port = "-1"
  47. to_port = "-1"
  48. self = true
  49. }
  50. }
  51. resource "openstack_compute_instance_v2" "k8s_master" {
  52. name = "${var.cluster_name}-k8s-master-${count.index+1}"
  53. count = "${var.number_of_k8s_masters}"
  54. image_name = "${var.image}"
  55. flavor_id = "${var.flavor_k8s_master}"
  56. key_pair = "${openstack_compute_keypair_v2.k8s.name}"
  57. network {
  58. name = "${var.network_name}"
  59. }
  60. security_groups = [ "${openstack_compute_secgroup_v2.k8s_master.name}",
  61. "${openstack_compute_secgroup_v2.k8s.name}" ]
  62. floating_ip = "${element(openstack_networking_floatingip_v2.k8s_master.*.address, count.index)}"
  63. metadata = {
  64. ssh_user = "${var.ssh_user}"
  65. kubespray_groups = "etcd,kube-master,kube-node,k8s-cluster"
  66. }
  67. }
  68. resource "openstack_compute_instance_v2" "k8s_master_no_floating_ip" {
  69. name = "${var.cluster_name}-k8s-master-nf-${count.index+1}"
  70. count = "${var.number_of_k8s_masters_no_floating_ip}"
  71. image_name = "${var.image}"
  72. flavor_id = "${var.flavor_k8s_master}"
  73. key_pair = "${openstack_compute_keypair_v2.k8s.name}"
  74. network {
  75. name = "${var.network_name}"
  76. }
  77. security_groups = [ "${openstack_compute_secgroup_v2.k8s_master.name}",
  78. "${openstack_compute_secgroup_v2.k8s.name}" ]
  79. metadata = {
  80. ssh_user = "${var.ssh_user}"
  81. kubespray_groups = "etcd,kube-master,kube-node,k8s-cluster"
  82. }
  83. provisioner "local-exec" {
  84. command = "sed s/USER/${var.ssh_user}/ contrib/terraform/openstack/ansible_bastion_template.txt | sed s/BASTION_ADDRESS/${element(openstack_networking_floatingip_v2.k8s_master.*.address, 0)}/ > contrib/terraform/openstack/group_vars/k8s-cluster.yml"
  85. }
  86. }
  87. resource "openstack_compute_instance_v2" "k8s_node" {
  88. name = "${var.cluster_name}-k8s-node-${count.index+1}"
  89. count = "${var.number_of_k8s_nodes}"
  90. image_name = "${var.image}"
  91. flavor_id = "${var.flavor_k8s_node}"
  92. key_pair = "${openstack_compute_keypair_v2.k8s.name}"
  93. network {
  94. name = "${var.network_name}"
  95. }
  96. security_groups = ["${openstack_compute_secgroup_v2.k8s.name}" ]
  97. floating_ip = "${element(openstack_networking_floatingip_v2.k8s_node.*.address, count.index)}"
  98. metadata = {
  99. ssh_user = "${var.ssh_user}"
  100. kubespray_groups = "kube-node,k8s-cluster"
  101. }
  102. }
  103. resource "openstack_compute_instance_v2" "k8s_node_no_floating_ip" {
  104. name = "${var.cluster_name}-k8s-node-nf-${count.index+1}"
  105. count = "${var.number_of_k8s_nodes_no_floating_ip}"
  106. image_name = "${var.image}"
  107. flavor_id = "${var.flavor_k8s_node}"
  108. key_pair = "${openstack_compute_keypair_v2.k8s.name}"
  109. network {
  110. name = "${var.network_name}"
  111. }
  112. security_groups = ["${openstack_compute_secgroup_v2.k8s.name}" ]
  113. metadata = {
  114. ssh_user = "${var.ssh_user}"
  115. kubespray_groups = "kube-node,k8s-cluster"
  116. }
  117. provisioner "local-exec" {
  118. command = "sed s/USER/${var.ssh_user}/ contrib/terraform/openstack/ansible_bastion_template.txt | sed s/BASTION_ADDRESS/${element(openstack_networking_floatingip_v2.k8s_master.*.address, 0)}/ > contrib/terraform/openstack/group_vars/k8s-cluster.yml"
  119. }
  120. }
  121. resource "openstack_blockstorage_volume_v2" "glusterfs_volume" {
  122. name = "${var.cluster_name}-gfs-nephe-vol-${count.index+1}"
  123. count = "${var.number_of_gfs_nodes_no_floating_ip}"
  124. description = "Non-ephemeral volume for GlusterFS"
  125. size = "${var.gfs_volume_size_in_gb}"
  126. }
  127. resource "openstack_compute_instance_v2" "glusterfs_node_no_floating_ip" {
  128. name = "${var.cluster_name}-gfs-node-nf-${count.index+1}"
  129. count = "${var.number_of_gfs_nodes_no_floating_ip}"
  130. image_name = "${var.image_gfs}"
  131. flavor_id = "${var.flavor_gfs_node}"
  132. key_pair = "${openstack_compute_keypair_v2.k8s.name}"
  133. network {
  134. name = "${var.network_name}"
  135. }
  136. security_groups = ["${openstack_compute_secgroup_v2.k8s.name}" ]
  137. metadata = {
  138. ssh_user = "${var.ssh_user_gfs}"
  139. kubespray_groups = "gfs-cluster,network-storage"
  140. }
  141. volume {
  142. volume_id = "${element(openstack_blockstorage_volume_v2.glusterfs_volume.*.id, count.index)}"
  143. }
  144. provisioner "local-exec" {
  145. command = "sed s/USER/${var.ssh_user}/ contrib/terraform/openstack/ansible_bastion_template.txt | sed s/BASTION_ADDRESS/${element(openstack_networking_floatingip_v2.k8s_master.*.address, 0)}/ > contrib/terraform/openstack/group_vars/gfs-cluster.yml"
  146. }
  147. }
  148. #output "msg" {
  149. # value = "Your hosts are ready to go!\nYour ssh hosts are: ${join(", ", openstack_networking_floatingip_v2.k8s_master.*.address )}"
  150. #}