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.

261 lines
5.7 KiB

  1. variable "deploymentName" {
  2. type = "string"
  3. description = "The desired name of your deployment."
  4. }
  5. variable "numControllers"{
  6. type = "string"
  7. description = "Desired # of controllers."
  8. }
  9. variable "numEtcd" {
  10. type = "string"
  11. description = "Desired # of etcd nodes. Should be an odd number."
  12. }
  13. variable "numNodes" {
  14. type = "string"
  15. description = "Desired # of nodes."
  16. }
  17. variable "volSizeController" {
  18. type = "string"
  19. description = "Volume size for the controllers (GB)."
  20. }
  21. variable "volSizeEtcd" {
  22. type = "string"
  23. description = "Volume size for etcd (GB)."
  24. }
  25. variable "volSizeNodes" {
  26. type = "string"
  27. description = "Volume size for nodes (GB)."
  28. }
  29. variable "subnet" {
  30. type = "string"
  31. description = "The subnet in which to put your cluster."
  32. }
  33. variable "securityGroups" {
  34. type = "string"
  35. description = "The sec. groups in which to put your cluster."
  36. }
  37. variable "ami"{
  38. type = "string"
  39. description = "AMI to use for all VMs in cluster."
  40. }
  41. variable "SSHKey" {
  42. type = "string"
  43. description = "SSH key to use for VMs."
  44. }
  45. variable "master_instance_type" {
  46. type = "string"
  47. description = "Size of VM to use for masters."
  48. }
  49. variable "etcd_instance_type" {
  50. type = "string"
  51. description = "Size of VM to use for etcd."
  52. }
  53. variable "node_instance_type" {
  54. type = "string"
  55. description = "Size of VM to use for nodes."
  56. }
  57. variable "terminate_protect" {
  58. type = "string"
  59. default = "false"
  60. }
  61. variable "awsRegion" {
  62. type = "string"
  63. }
  64. provider "aws" {
  65. region = "${var.awsRegion}"
  66. }
  67. variable "iam_prefix" {
  68. type = "string"
  69. description = "Prefix name for IAM profiles"
  70. }
  71. resource "aws_iam_instance_profile" "kubernetes_master_profile" {
  72. name = "${var.iam_prefix}_kubernetes_master_profile"
  73. roles = ["${aws_iam_role.kubernetes_master_role.name}"]
  74. }
  75. resource "aws_iam_role" "kubernetes_master_role" {
  76. name = "${var.iam_prefix}_kubernetes_master_role"
  77. assume_role_policy = <<EOF
  78. {
  79. "Version": "2012-10-17",
  80. "Statement": [
  81. {
  82. "Effect": "Allow",
  83. "Principal": { "Service": "ec2.amazonaws.com"},
  84. "Action": "sts:AssumeRole"
  85. }
  86. ]
  87. }
  88. EOF
  89. }
  90. resource "aws_iam_role_policy" "kubernetes_master_policy" {
  91. name = "${var.iam_prefix}_kubernetes_master_policy"
  92. role = "${aws_iam_role.kubernetes_master_role.id}"
  93. policy = <<EOF
  94. {
  95. "Version": "2012-10-17",
  96. "Statement": [
  97. {
  98. "Effect": "Allow",
  99. "Action": ["ec2:*"],
  100. "Resource": ["*"]
  101. },
  102. {
  103. "Effect": "Allow",
  104. "Action": ["elasticloadbalancing:*"],
  105. "Resource": ["*"]
  106. },
  107. {
  108. "Effect": "Allow",
  109. "Action": "s3:*",
  110. "Resource": "*"
  111. }
  112. ]
  113. }
  114. EOF
  115. }
  116. resource "aws_iam_instance_profile" "kubernetes_node_profile" {
  117. name = "${var.iam_prefix}_kubernetes_node_profile"
  118. roles = ["${aws_iam_role.kubernetes_node_role.name}"]
  119. }
  120. resource "aws_iam_role" "kubernetes_node_role" {
  121. name = "${var.iam_prefix}_kubernetes_node_role"
  122. assume_role_policy = <<EOF
  123. {
  124. "Version": "2012-10-17",
  125. "Statement": [
  126. {
  127. "Effect": "Allow",
  128. "Principal": { "Service": "ec2.amazonaws.com"},
  129. "Action": "sts:AssumeRole"
  130. }
  131. ]
  132. }
  133. EOF
  134. }
  135. resource "aws_iam_role_policy" "kubernetes_node_policy" {
  136. name = "${var.iam_prefix}_kubernetes_node_policy"
  137. role = "${aws_iam_role.kubernetes_node_role.id}"
  138. policy = <<EOF
  139. {
  140. "Version": "2012-10-17",
  141. "Statement": [
  142. {
  143. "Effect": "Allow",
  144. "Action": "s3:*",
  145. "Resource": "*"
  146. },
  147. {
  148. "Effect": "Allow",
  149. "Action": "ec2:Describe*",
  150. "Resource": "*"
  151. },
  152. {
  153. "Effect": "Allow",
  154. "Action": "ec2:AttachVolume",
  155. "Resource": "*"
  156. },
  157. {
  158. "Effect": "Allow",
  159. "Action": "ec2:DetachVolume",
  160. "Resource": "*"
  161. }
  162. ]
  163. }
  164. EOF
  165. }
  166. resource "aws_instance" "master" {
  167. count = "${var.numControllers}"
  168. ami = "${var.ami}"
  169. instance_type = "${var.master_instance_type}"
  170. subnet_id = "${var.subnet}"
  171. vpc_security_group_ids = ["${var.securityGroups}"]
  172. key_name = "${var.SSHKey}"
  173. disable_api_termination = "${var.terminate_protect}"
  174. iam_instance_profile = "${aws_iam_instance_profile.kubernetes_master_profile.id}"
  175. root_block_device {
  176. volume_size = "${var.volSizeController}"
  177. }
  178. tags {
  179. Name = "${var.deploymentName}-master-${count.index + 1}"
  180. }
  181. }
  182. resource "aws_instance" "etcd" {
  183. count = "${var.numEtcd}"
  184. ami = "${var.ami}"
  185. instance_type = "${var.etcd_instance_type}"
  186. subnet_id = "${var.subnet}"
  187. vpc_security_group_ids = ["${var.securityGroups}"]
  188. key_name = "${var.SSHKey}"
  189. disable_api_termination = "${var.terminate_protect}"
  190. root_block_device {
  191. volume_size = "${var.volSizeEtcd}"
  192. }
  193. tags {
  194. Name = "${var.deploymentName}-etcd-${count.index + 1}"
  195. }
  196. }
  197. resource "aws_instance" "minion" {
  198. count = "${var.numNodes}"
  199. ami = "${var.ami}"
  200. instance_type = "${var.node_instance_type}"
  201. subnet_id = "${var.subnet}"
  202. vpc_security_group_ids = ["${var.securityGroups}"]
  203. key_name = "${var.SSHKey}"
  204. disable_api_termination = "${var.terminate_protect}"
  205. iam_instance_profile = "${aws_iam_instance_profile.kubernetes_node_profile.id}"
  206. root_block_device {
  207. volume_size = "${var.volSizeNodes}"
  208. }
  209. tags {
  210. Name = "${var.deploymentName}-minion-${count.index + 1}"
  211. }
  212. }
  213. output "kubernetes_master_profile" {
  214. value = "${aws_iam_instance_profile.kubernetes_master_profile.id}"
  215. }
  216. output "kubernetes_node_profile" {
  217. value = "${aws_iam_instance_profile.kubernetes_node_profile.id}"
  218. }
  219. output "master-ip" {
  220. value = "${join(", ", aws_instance.master.*.private_ip)}"
  221. }
  222. output "etcd-ip" {
  223. value = "${join(", ", aws_instance.etcd.*.private_ip)}"
  224. }
  225. output "minion-ip" {
  226. value = "${join(", ", aws_instance.minion.*.private_ip)}"
  227. }