2017-03-01 17:25:58 +00:00
|
|
|
#Add AWS Roles for Kubernetes
|
|
|
|
|
2021-03-24 00:26:05 +00:00
|
|
|
resource "aws_iam_role" "kube_control_plane" {
|
2019-04-08 09:22:24 +00:00
|
|
|
name = "kubernetes-${var.aws_cluster_name}-master"
|
|
|
|
|
|
|
|
assume_role_policy = <<EOF
|
2017-03-01 17:25:58 +00:00
|
|
|
{
|
|
|
|
"Version": "2012-10-17",
|
|
|
|
"Statement": [
|
|
|
|
{
|
|
|
|
"Effect": "Allow",
|
|
|
|
"Action": "sts:AssumeRole",
|
|
|
|
"Principal": {
|
|
|
|
"Service": "ec2.amazonaws.com"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
EOF
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "aws_iam_role" "kube-worker" {
|
2019-04-08 09:22:24 +00:00
|
|
|
name = "kubernetes-${var.aws_cluster_name}-node"
|
|
|
|
|
|
|
|
assume_role_policy = <<EOF
|
2017-03-01 17:25:58 +00:00
|
|
|
{
|
|
|
|
"Version": "2012-10-17",
|
|
|
|
"Statement": [
|
|
|
|
{
|
|
|
|
"Effect": "Allow",
|
|
|
|
"Action": "sts:AssumeRole",
|
|
|
|
"Principal": {
|
|
|
|
"Service": "ec2.amazonaws.com"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
EOF
|
|
|
|
}
|
|
|
|
|
|
|
|
#Add AWS Policies for Kubernetes
|
|
|
|
|
2021-03-24 00:26:05 +00:00
|
|
|
resource "aws_iam_role_policy" "kube_control_plane" {
|
2019-04-08 09:22:24 +00:00
|
|
|
name = "kubernetes-${var.aws_cluster_name}-master"
|
2021-03-24 00:26:05 +00:00
|
|
|
role = aws_iam_role.kube_control_plane.id
|
2019-04-08 09:22:24 +00:00
|
|
|
|
|
|
|
policy = <<EOF
|
2017-03-01 17:25:58 +00:00
|
|
|
{
|
|
|
|
"Version": "2012-10-17",
|
|
|
|
"Statement": [
|
|
|
|
{
|
|
|
|
"Effect": "Allow",
|
|
|
|
"Action": ["ec2:*"],
|
|
|
|
"Resource": ["*"]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"Effect": "Allow",
|
|
|
|
"Action": ["elasticloadbalancing:*"],
|
|
|
|
"Resource": ["*"]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"Effect": "Allow",
|
|
|
|
"Action": ["route53:*"],
|
|
|
|
"Resource": ["*"]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"Effect": "Allow",
|
|
|
|
"Action": "s3:*",
|
|
|
|
"Resource": [
|
|
|
|
"arn:aws:s3:::kubernetes-*"
|
|
|
|
]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
EOF
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "aws_iam_role_policy" "kube-worker" {
|
2019-04-08 09:22:24 +00:00
|
|
|
name = "kubernetes-${var.aws_cluster_name}-node"
|
2020-06-05 07:05:43 +00:00
|
|
|
role = aws_iam_role.kube-worker.id
|
2019-04-08 09:22:24 +00:00
|
|
|
|
|
|
|
policy = <<EOF
|
2017-03-01 17:25:58 +00:00
|
|
|
{
|
|
|
|
"Version": "2012-10-17",
|
|
|
|
"Statement": [
|
|
|
|
{
|
|
|
|
"Effect": "Allow",
|
|
|
|
"Action": "s3:*",
|
|
|
|
"Resource": [
|
|
|
|
"arn:aws:s3:::kubernetes-*"
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"Effect": "Allow",
|
|
|
|
"Action": "ec2:Describe*",
|
|
|
|
"Resource": "*"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"Effect": "Allow",
|
|
|
|
"Action": "ec2:AttachVolume",
|
|
|
|
"Resource": "*"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"Effect": "Allow",
|
|
|
|
"Action": "ec2:DetachVolume",
|
|
|
|
"Resource": "*"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"Effect": "Allow",
|
|
|
|
"Action": ["route53:*"],
|
|
|
|
"Resource": ["*"]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"Effect": "Allow",
|
|
|
|
"Action": [
|
|
|
|
"ecr:GetAuthorizationToken",
|
|
|
|
"ecr:BatchCheckLayerAvailability",
|
|
|
|
"ecr:GetDownloadUrlForLayer",
|
|
|
|
"ecr:GetRepositoryPolicy",
|
|
|
|
"ecr:DescribeRepositories",
|
|
|
|
"ecr:ListImages",
|
|
|
|
"ecr:BatchGetImage"
|
|
|
|
],
|
|
|
|
"Resource": "*"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
EOF
|
|
|
|
}
|
|
|
|
|
|
|
|
#Create AWS Instance Profiles
|
|
|
|
|
2021-03-24 00:26:05 +00:00
|
|
|
resource "aws_iam_instance_profile" "kube_control_plane" {
|
2019-04-08 09:22:24 +00:00
|
|
|
name = "kube_${var.aws_cluster_name}_master_profile"
|
2021-03-24 00:26:05 +00:00
|
|
|
role = aws_iam_role.kube_control_plane.name
|
2017-03-01 17:25:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
resource "aws_iam_instance_profile" "kube-worker" {
|
2019-04-08 09:22:24 +00:00
|
|
|
name = "kube_${var.aws_cluster_name}_node_profile"
|
2020-06-05 07:05:43 +00:00
|
|
|
role = aws_iam_role.kube-worker.name
|
2017-03-01 17:25:58 +00:00
|
|
|
}
|