-
Notifications
You must be signed in to change notification settings - Fork 1
/
21-secrets-store-csi-driver.tf
77 lines (63 loc) · 2.01 KB
/
21-secrets-store-csi-driver.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
resource "helm_release" "secrets_csi_driver" {
name = "secrets-store-csi-driver"
repository = "https://kubernetes-sigs.github.io/secrets-store-csi-driver/charts"
chart = "secrets-store-csi-driver"
namespace = "kube-system"
version = "1.4.3"
# MUST be set if you use ENV variables
set {
name = "syncSecret.enabled"
value = true
}
depends_on = [helm_release.efs_csi_driver]
}
resource "helm_release" "secrets_csi_driver_aws_provider" {
name = "secrets-store-csi-driver-provider-aws"
repository = "https://aws.github.io/secrets-store-csi-driver-provider-aws"
chart = "secrets-store-csi-driver-provider-aws"
namespace = "kube-system"
version = "0.3.9"
depends_on = [helm_release.secrets_csi_driver]
}
data "aws_iam_policy_document" "myapp_secrets" {
statement {
actions = ["sts:AssumeRoleWithWebIdentity"]
effect = "Allow"
condition {
test = "StringEquals"
variable = "${replace(aws_iam_openid_connect_provider.eks.url, "https://", "")}:sub"
values = ["system:serviceaccount:12-example:myapp"]
}
principals {
identifiers = [aws_iam_openid_connect_provider.eks.arn]
type = "Federated"
}
}
}
resource "aws_iam_role" "myapp_secrets" {
name = "${aws_eks_cluster.eks.name}-myapp-secrets"
assume_role_policy = data.aws_iam_policy_document.myapp_secrets.json
}
resource "aws_iam_policy" "myapp_secrets" {
name = "${aws_eks_cluster.eks.name}-myapp-secrets"
policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Effect = "Allow"
Action = [
"secretsmanager:GetSecretValue",
"secretsmanager:DescribeSecret"
]
Resource = "*" # "arn:*:secretsmanager:*:*:secret:my-secret-kkargS"
}
]
})
}
resource "aws_iam_role_policy_attachment" "myapp_secrets" {
policy_arn = aws_iam_policy.myapp_secrets.arn
role = aws_iam_role.myapp_secrets.name
}
output "myapp_secrets_role_arn" {
value = aws_iam_role.myapp_secrets.arn
}