-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathidentity.tf
More file actions
83 lines (71 loc) · 2.07 KB
/
identity.tf
File metadata and controls
83 lines (71 loc) · 2.07 KB
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
data "aws_caller_identity" "current" {}
resource "aws_iam_role" "eks_cluster" {
name = "${var.cluster_name}-cluster-role"
assume_role_policy = jsonencode({
Version = "2012-10-17"
Statement = [{
Action = "sts:AssumeRole"
Effect = "Allow"
Principal = {
Service = "eks.amazonaws.com"
}
}]
})
}
resource "aws_iam_role_policy_attachment" "eks_cluster_policy" {
policy_arn = "arn:aws:iam::aws:policy/AmazonEKSClusterPolicy"
role = aws_iam_role.eks_cluster.name
}
resource "aws_iam_role_policy_attachment" "eks_vpc_resource_controller" {
policy_arn = "arn:aws:iam::aws:policy/AmazonEKSVPCResourceController"
role = aws_iam_role.eks_cluster.name
}
resource "aws_iam_role" "fargate_pod_execution" {
name = "${var.cluster_name}-fargate-pod-execution-role"
assume_role_policy = jsonencode({
Version = "2012-10-17"
Statement = [{
Action = "sts:AssumeRole"
Effect = "Allow"
Principal = {
Service = "eks-fargate-pods.amazonaws.com"
}
}]
})
}
resource "aws_iam_role_policy_attachment" "fargate_pod_execution_policy" {
policy_arn = "arn:aws:iam::aws:policy/AmazonEKSFargatePodExecutionRolePolicy"
role = aws_iam_role.fargate_pod_execution.name
}
resource "aws_iam_role" "cluster_admin" {
name = "${var.cluster_name}-admin-role"
assume_role_policy = jsonencode({
Version = "2012-10-17"
Statement = [{
Action = "sts:AssumeRole"
Effect = "Allow"
Principal = {
AWS = "arn:aws:iam::${data.aws_caller_identity.current.account_id}:root"
}
}]
})
}
resource "aws_iam_policy" "cluster_admin" {
name = "${var.cluster_name}-admin-policy"
policy = jsonencode({
Version = "2012-10-17"
Statement = [{
Action = [
"eks:DescribeCluster",
"eks:ListClusters",
"eks:AccessKubernetesApi"
]
Effect = "Allow"
Resource = "*"
}]
})
}
resource "aws_iam_role_policy_attachment" "cluster_admin_policy" {
policy_arn = aws_iam_policy.cluster_admin.arn
role = aws_iam_role.cluster_admin.name
}