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.

138 lines
2.8 KiB

  1. #Add AWS Roles for Kubernetes
  2. resource "aws_iam_role" "kube-master" {
  3. name = "kubernetes-${var.aws_cluster_name}-master"
  4. assume_role_policy = <<EOF
  5. {
  6. "Version": "2012-10-17",
  7. "Statement": [
  8. {
  9. "Effect": "Allow",
  10. "Action": "sts:AssumeRole",
  11. "Principal": {
  12. "Service": "ec2.amazonaws.com"
  13. }
  14. }
  15. ]
  16. }
  17. EOF
  18. }
  19. resource "aws_iam_role" "kube-worker" {
  20. name = "kubernetes-${var.aws_cluster_name}-node"
  21. assume_role_policy = <<EOF
  22. {
  23. "Version": "2012-10-17",
  24. "Statement": [
  25. {
  26. "Effect": "Allow",
  27. "Action": "sts:AssumeRole",
  28. "Principal": {
  29. "Service": "ec2.amazonaws.com"
  30. }
  31. }
  32. ]
  33. }
  34. EOF
  35. }
  36. #Add AWS Policies for Kubernetes
  37. resource "aws_iam_role_policy" "kube-master" {
  38. name = "kubernetes-${var.aws_cluster_name}-master"
  39. role = "${aws_iam_role.kube-master.id}"
  40. policy = <<EOF
  41. {
  42. "Version": "2012-10-17",
  43. "Statement": [
  44. {
  45. "Effect": "Allow",
  46. "Action": ["ec2:*"],
  47. "Resource": ["*"]
  48. },
  49. {
  50. "Effect": "Allow",
  51. "Action": ["elasticloadbalancing:*"],
  52. "Resource": ["*"]
  53. },
  54. {
  55. "Effect": "Allow",
  56. "Action": ["route53:*"],
  57. "Resource": ["*"]
  58. },
  59. {
  60. "Effect": "Allow",
  61. "Action": "s3:*",
  62. "Resource": [
  63. "arn:aws:s3:::kubernetes-*"
  64. ]
  65. }
  66. ]
  67. }
  68. EOF
  69. }
  70. resource "aws_iam_role_policy" "kube-worker" {
  71. name = "kubernetes-${var.aws_cluster_name}-node"
  72. role = "${aws_iam_role.kube-worker.id}"
  73. policy = <<EOF
  74. {
  75. "Version": "2012-10-17",
  76. "Statement": [
  77. {
  78. "Effect": "Allow",
  79. "Action": "s3:*",
  80. "Resource": [
  81. "arn:aws:s3:::kubernetes-*"
  82. ]
  83. },
  84. {
  85. "Effect": "Allow",
  86. "Action": "ec2:Describe*",
  87. "Resource": "*"
  88. },
  89. {
  90. "Effect": "Allow",
  91. "Action": "ec2:AttachVolume",
  92. "Resource": "*"
  93. },
  94. {
  95. "Effect": "Allow",
  96. "Action": "ec2:DetachVolume",
  97. "Resource": "*"
  98. },
  99. {
  100. "Effect": "Allow",
  101. "Action": ["route53:*"],
  102. "Resource": ["*"]
  103. },
  104. {
  105. "Effect": "Allow",
  106. "Action": [
  107. "ecr:GetAuthorizationToken",
  108. "ecr:BatchCheckLayerAvailability",
  109. "ecr:GetDownloadUrlForLayer",
  110. "ecr:GetRepositoryPolicy",
  111. "ecr:DescribeRepositories",
  112. "ecr:ListImages",
  113. "ecr:BatchGetImage"
  114. ],
  115. "Resource": "*"
  116. }
  117. ]
  118. }
  119. EOF
  120. }
  121. #Create AWS Instance Profiles
  122. resource "aws_iam_instance_profile" "kube-master" {
  123. name = "kube_${var.aws_cluster_name}_master_profile"
  124. role = "${aws_iam_role.kube-master.name}"
  125. }
  126. resource "aws_iam_instance_profile" "kube-worker" {
  127. name = "kube_${var.aws_cluster_name}_node_profile"
  128. role = "${aws_iam_role.kube-worker.name}"
  129. }