-
-
Notifications
You must be signed in to change notification settings - Fork 356
/
iam.tf
90 lines (72 loc) · 2.96 KB
/
iam.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
locals {
create_eks_service_role = local.enabled && var.create_eks_service_role
eks_service_role_arn = local.create_eks_service_role ? one(aws_iam_role.default[*].arn) : var.eks_cluster_service_role_arn
}
data "aws_iam_policy_document" "assume_role" {
count = local.create_eks_service_role ? 1 : 0
statement {
effect = "Allow"
actions = ["sts:AssumeRole"]
principals {
type = "Service"
identifiers = ["eks.amazonaws.com"]
}
}
}
resource "aws_iam_role" "default" {
count = local.create_eks_service_role ? 1 : 0
name = module.label.id
assume_role_policy = one(data.aws_iam_policy_document.assume_role[*].json)
tags = module.label.tags
permissions_boundary = var.permissions_boundary
}
resource "aws_iam_role_policy_attachment" "amazon_eks_cluster_policy" {
count = local.create_eks_service_role ? 1 : 0
policy_arn = format("arn:%s:iam::aws:policy/AmazonEKSClusterPolicy", one(data.aws_partition.current[*].partition))
role = one(aws_iam_role.default[*].name)
}
resource "aws_iam_role_policy_attachment" "amazon_eks_service_policy" {
count = local.create_eks_service_role ? 1 : 0
policy_arn = format("arn:%s:iam::aws:policy/AmazonEKSServicePolicy", one(data.aws_partition.current[*].partition))
role = one(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 = local.create_eks_service_role ? 1 : 0
statement {
sid = "AllowElasticLoadBalancer"
effect = "Allow"
#bridgecrew:skip=BC_AWS_IAM_57:There is no workable constraint to add to this policy
actions = [
"ec2:DescribeAccountAttributes",
"ec2:DescribeAddresses",
"ec2:DescribeInternetGateways",
"elasticloadbalancing:SetIpAddressType",
"elasticloadbalancing:SetSubnets"
]
resources = ["*"]
}
# Adding a policy to cluster IAM role that deny permissions to logs:CreateLogGroup
# it is not needed since we create the log group elsewhere in this module, and it is causing trouble during "destroy"
statement {
sid = "DenyCreateLogGroup"
effect = "Deny"
actions = [
"logs:CreateLogGroup"
]
resources = ["*"]
}
}
resource "aws_iam_policy" "cluster_elb_service_role" {
count = local.create_eks_service_role ? 1 : 0
name = "${module.label.id}-ServiceRole"
policy = one(data.aws_iam_policy_document.cluster_elb_service_role[*].json)
tags = module.this.tags
}
resource "aws_iam_role_policy_attachment" "cluster_elb_service_role" {
count = local.create_eks_service_role ? 1 : 0
policy_arn = one(aws_iam_policy.cluster_elb_service_role[*].arn)
role = one(aws_iam_role.default[*].name)
}