-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmain.tf
72 lines (65 loc) · 2 KB
/
main.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
resource "aws_iam_policy" "s3_policy" {
name = "${var.eks_cluster_name}-s3-access-policy"
description = "IAM policy for S3 access"
policy = jsonencode({
Version = "2012-10-17",
Statement = [
{
Sid = "MountpointFullBucketAccess",
Effect = "Allow",
Action = [
"s3:ListBucket"
],
Resource = [
"arn:aws:s3:::${var.s3_bucket_name}"
],
},
{
Sid = "MountpointFullObjectAccess",
Effect = "Allow",
Action = [
"s3:GetObject",
"s3:PutObject",
"s3:AbortMultipartUpload",
"s3:DeleteObject",
],
Resource = [
"arn:aws:s3:::${var.s3_bucket_name}/*"
],
},
],
})
}
resource "aws_iam_role" "s3_role" {
name = "${var.eks_cluster_name}-s3-csi-access-role"
assume_role_policy = jsonencode({
Version = "2012-10-17",
Statement = [
{
Effect = "Allow",
Principal = {
Federated = data.aws_iam_openid_connect_provider.this.arn
},
Action = "sts:AssumeRoleWithWebIdentity",
Condition = {
StringLike = {
"${replace(data.aws_eks_cluster.eks_cluster.identity[0].oidc[0].issuer, "https://", "")}:sub" = "system:serviceaccount:kube-system:s3-csi-*",
"${replace(data.aws_eks_cluster.eks_cluster.identity[0].oidc[0].issuer, "https://", "")}:aud" = "sts.amazonaws.com",
},
},
},
],
})
}
resource "aws_iam_role_policy_attachment" "s3_role_attachment" {
policy_arn = aws_iam_policy.s3_policy.arn
role = aws_iam_role.s3_role.name
}
resource "aws_eks_addon" "s3_csi" {
cluster_name = data.aws_eks_cluster.eks_cluster.id
addon_name = "aws-mountpoint-s3-csi-driver"
addon_version = data.aws_eks_addon_version.s3_csi.version
resolve_conflicts_on_create = "OVERWRITE"
resolve_conflicts_on_update = "OVERWRITE"
service_account_role_arn = aws_iam_role.s3_role.arn
}