Files
terraform-aws-eks/workers.tf

76 lines
2.9 KiB
HCL

module "worker_groups" {
source = "./modules/worker_groups"
aws_region = "{data.aws_region.current.name}"
cluster_name = "${var.cluster_name}"
certificate_authority = "${aws_eks_cluster.this.certificate_authority.0.data}"
endpoint = "${aws_eks_cluster.this.endpoint}"
iam_instance_profile = "${aws_iam_instance_profile.workers.name}"
security_group_id = "${aws_security_group.workers.id}"
subnets = "${var.subnets}"
tags = "${var.tags}"
worker_groups = "${var.worker_groups}"
}
resource "aws_security_group" "workers" {
name_prefix = "${var.cluster_name}"
description = "Security group for all nodes in the cluster."
vpc_id = "${var.vpc_id}"
tags = "${merge(var.tags, map("Name", "${var.cluster_name}-eks_worker_sg", "kubernetes.io/cluster/${var.cluster_name}", "owned"
))}"
}
resource "aws_security_group_rule" "workers_egress_internet" {
description = "Allow nodes all egress to the Internet."
protocol = "-1"
security_group_id = "${aws_security_group.workers.id}"
cidr_blocks = ["0.0.0.0/0"]
from_port = 0
to_port = 0
type = "egress"
}
resource "aws_security_group_rule" "workers_ingress_self" {
description = "Allow node to communicate with each other."
protocol = "-1"
security_group_id = "${aws_security_group.workers.id}"
source_security_group_id = "${aws_security_group.workers.id}"
from_port = 0
to_port = 65535
type = "ingress"
}
resource "aws_security_group_rule" "workers_ingress_cluster" {
description = "Allow workers Kubelets and pods to receive communication from the cluster control plane."
protocol = "tcp"
security_group_id = "${aws_security_group.workers.id}"
source_security_group_id = "${aws_security_group.cluster.id}"
from_port = 1025
to_port = 65535
type = "ingress"
}
resource "aws_iam_role" "workers" {
name_prefix = "${var.cluster_name}"
assume_role_policy = "${data.aws_iam_policy_document.workers_assume_role_policy.json}"
}
resource "aws_iam_instance_profile" "workers" {
name_prefix = "${var.cluster_name}"
role = "${aws_iam_role.workers.name}"
}
resource "aws_iam_role_policy_attachment" "workers_AmazonEKSWorkerNodePolicy" {
policy_arn = "arn:aws:iam::aws:policy/AmazonEKSWorkerNodePolicy"
role = "${aws_iam_role.workers.name}"
}
resource "aws_iam_role_policy_attachment" "workers_AmazonEKS_CNI_Policy" {
policy_arn = "arn:aws:iam::aws:policy/AmazonEKS_CNI_Policy"
role = "${aws_iam_role.workers.name}"
}
resource "aws_iam_role_policy_attachment" "workers_AmazonEC2ContainerRegistryReadOnly" {
policy_arn = "arn:aws:iam::aws:policy/AmazonEC2ContainerRegistryReadOnly"
role = "${aws_iam_role.workers.name}"
}