forked from cloudposse/terraform-aws-eks-cluster
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
cluster_elb_service_role
IAM policy to allow creation of ELB se…
…rvice-linked role (cloudposse#72)
- Loading branch information
Showing
10 changed files
with
121 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,5 +11,7 @@ | |
**/.build-harness | ||
**/build-harness | ||
|
||
**/pkg | ||
|
||
# Rendered yaml config | ||
**/configmap-auth.yaml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
terraform { | ||
required_version = "~> 0.12.0" | ||
required_version = ">= 0.12.0" | ||
|
||
required_providers { | ||
aws = "~> 2.0" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
data "aws_iam_policy_document" "assume_role" { | ||
count = var.enabled ? 1 : 0 | ||
|
||
statement { | ||
effect = "Allow" | ||
actions = ["sts:AssumeRole"] | ||
|
||
principals { | ||
type = "Service" | ||
identifiers = ["eks.amazonaws.com"] | ||
} | ||
} | ||
} | ||
|
||
resource "aws_iam_role" "default" { | ||
count = var.enabled ? 1 : 0 | ||
name = module.label.id | ||
assume_role_policy = join("", data.aws_iam_policy_document.assume_role.*.json) | ||
tags = module.label.tags | ||
} | ||
|
||
resource "aws_iam_role_policy_attachment" "amazon_eks_cluster_policy" { | ||
count = var.enabled ? 1 : 0 | ||
policy_arn = format("arn:%s:iam::aws:policy/AmazonEKSClusterPolicy", join("", data.aws_partition.current.*.partition)) | ||
role = join("", aws_iam_role.default.*.name) | ||
} | ||
|
||
resource "aws_iam_role_policy_attachment" "amazon_eks_service_policy" { | ||
count = var.enabled ? 1 : 0 | ||
policy_arn = format("arn:%s:iam::aws:policy/AmazonEKSServicePolicy", join("", data.aws_partition.current.*.partition)) | ||
role = join("", aws_iam_role.default.*.name) | ||
} | ||
|
||
# AmazonEKSClusterPolicy managed policy doesn't contain all necessary permissions to create | ||
# ELB service-linked role required during LB provisioning by Kubernetes. | ||
# Because of that, on a new AWS account (where load balancers have not been provisioned yet, `nginx-ingress` fails to provision a load balancer | ||
|
||
data "aws_iam_policy_document" "cluster_elb_service_role" { | ||
count = var.enabled ? 1 : 0 | ||
|
||
statement { | ||
effect = "Allow" | ||
actions = [ | ||
"ec2:DescribeAccountAttributes", | ||
"ec2:DescribeAddresses", | ||
"ec2:DescribeInternetGateways", | ||
"elasticloadbalancing:SetIpAddressType", | ||
"elasticloadbalancing:SetSubnets" | ||
] | ||
resources = ["*"] | ||
} | ||
} | ||
|
||
resource "aws_iam_role_policy" "cluster_elb_service_role" { | ||
count = var.enabled ? 1 : 0 | ||
name = module.label.id | ||
role = join("", aws_iam_role.default.*.name) | ||
policy = join("", data.aws_iam_policy_document.cluster_elb_service_role.*.json) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
resource "aws_security_group" "default" { | ||
count = var.enabled ? 1 : 0 | ||
name = module.label.id | ||
description = "Security Group for EKS cluster" | ||
vpc_id = var.vpc_id | ||
tags = module.label.tags | ||
} | ||
|
||
resource "aws_security_group_rule" "egress" { | ||
count = var.enabled ? 1 : 0 | ||
description = "Allow all egress traffic" | ||
from_port = 0 | ||
to_port = 0 | ||
protocol = "-1" | ||
cidr_blocks = ["0.0.0.0/0"] | ||
security_group_id = join("", aws_security_group.default.*.id) | ||
type = "egress" | ||
} | ||
|
||
resource "aws_security_group_rule" "ingress_workers" { | ||
count = var.enabled ? length(var.workers_security_group_ids) : 0 | ||
description = "Allow the cluster to receive communication from the worker nodes" | ||
from_port = 0 | ||
to_port = 65535 | ||
protocol = "-1" | ||
source_security_group_id = var.workers_security_group_ids[count.index] | ||
security_group_id = join("", aws_security_group.default.*.id) | ||
type = "ingress" | ||
} | ||
|
||
resource "aws_security_group_rule" "ingress_security_groups" { | ||
count = var.enabled ? length(var.allowed_security_groups) : 0 | ||
description = "Allow inbound traffic from existing Security Groups" | ||
from_port = 0 | ||
to_port = 65535 | ||
protocol = "-1" | ||
source_security_group_id = var.allowed_security_groups[count.index] | ||
security_group_id = join("", aws_security_group.default.*.id) | ||
type = "ingress" | ||
} | ||
|
||
resource "aws_security_group_rule" "ingress_cidr_blocks" { | ||
count = var.enabled && length(var.allowed_cidr_blocks) > 0 ? 1 : 0 | ||
description = "Allow inbound traffic from CIDR blocks" | ||
from_port = 0 | ||
to_port = 65535 | ||
protocol = "-1" | ||
cidr_blocks = var.allowed_cidr_blocks | ||
security_group_id = join("", aws_security_group.default.*.id) | ||
type = "ingress" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters