-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathiam.tf
87 lines (78 loc) · 3.36 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
#### ROLE For CLUSTER ####
data "aws_iam_policy_document" "eks-cluster-role-policy-json" {
statement {
actions = ["sts:AssumeRole"]
principals {
identifiers = ["eks.amazonaws.com"]
type = "Service"
}
}
}
resource "aws_iam_role" "eks-cluster-role" {
name = "${local.env}-${local.project}-eks-cluster-role"
assume_role_policy = data.aws_iam_policy_document.eks-cluster-role-policy-json.json
tags = merge(map("Name", "${local.env}-${local.project}-eks-cluster-role"), map("ResourceType", "IAM"), local.common_tags)
}
resource "aws_iam_instance_profile" "eks-cluster-iamrole-instances-profile" {
name = aws_iam_role.eks-cluster-role.name
role = aws_iam_role.eks-cluster-role.name
}
resource "aws_iam_role_policy_attachment" "eks-cluster-role-policy" {
policy_arn = "arn:aws:iam::aws:policy/AmazonEKSClusterPolicy"
role = aws_iam_role.eks-cluster-role.name
}
resource "aws_iam_role_policy_attachment" "eks-cluster-role-service-policy" {
policy_arn = "arn:aws:iam::aws:policy/AmazonEKSServicePolicy"
role = aws_iam_role.eks-cluster-role.name
}
resource "aws_iam_role_policy_attachment" "eks-cluster-role-cnipolicy" {
policy_arn = "arn:aws:iam::aws:policy/AmazonEKS_CNI_Policy"
role = aws_iam_role.eks-cluster-role.name
}
#### ROLE For WORKER NODE ####
data "aws_iam_policy_document" "eks-worker-role-policy-json" {
statement {
actions = ["sts:AssumeRole"]
principals {
identifiers = ["ec2.amazonaws.com"]
type = "Service"
}
}
}
resource "aws_iam_role" "eks-worker-role" {
name = "${local.env}-${local.project}-eks-worker-role"
assume_role_policy = data.aws_iam_policy_document.eks-worker-role-policy-json.json
tags = merge(map("Name", "${local.env}-${local.project}-eks-worker-role"), map("ResourceType", "IAM"), local.common_tags)
}
resource "aws_iam_instance_profile" "eks-worker-iamrole-instances-profile" {
name = aws_iam_role.eks-worker-role.name
role = aws_iam_role.eks-worker-role.name
}
resource "aws_iam_role_policy_attachment" "eks-worker-role-nodeplicy" {
role = aws_iam_role.eks-worker-role.name
policy_arn = "arn:aws:iam::aws:policy/AmazonEKSWorkerNodePolicy"
}
resource "aws_iam_role_policy_attachment" "eks-worker-role-cnipolicy" {
policy_arn = "arn:aws:iam::aws:policy/AmazonEKS_CNI_Policy"
role = aws_iam_role.eks-worker-role.name
}
resource "aws_iam_role_policy_attachment" "eks-worker-role-servicepolicy" {
policy_arn = "arn:aws:iam::aws:policy/AmazonEKSServicePolicy"
role = aws_iam_role.eks-worker-role.name
}
resource "aws_iam_role_policy_attachment" "eks-worker-role-containerregistry" {
policy_arn = "arn:aws:iam::aws:policy/AmazonEC2ContainerRegistryReadOnly"
role = aws_iam_role.eks-worker-role.name
}
resource "aws_iam_role_policy_attachment" "eks-worker-role-AdministratorAccess" {
policy_arn = "arn:aws:iam::aws:policy/AdministratorAccess"
role = aws_iam_role.eks-worker-role.name
}
resource "aws_iam_role_policy_attachment" "eks-worker-role-AmazonSSMFullAccess" {
policy_arn = "arn:aws:iam::aws:policy/AmazonSSMFullAccess"
role = aws_iam_role.eks-worker-role.name
}
resource "aws_iam_role_policy_attachment" "eks-worker-role-AmazonEC2RoleforSSM" {
policy_arn = "arn:aws:iam::aws:policy/service-role/AmazonEC2RoleforSSM"
role = aws_iam_role.eks-worker-role.name
}