forked from DNXLabs/terraform-aws-eks-external-secrets
-
Notifications
You must be signed in to change notification settings - Fork 0
/
iam.tf
75 lines (62 loc) · 1.84 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
# Policy
data "aws_iam_policy_document" "kubernetes_external_secrets" {
count = var.enabled ? 1 : 0
statement {
actions = [
"secretsmanager:GetResourcePolicy",
"secretsmanager:GetSecretValue",
"secretsmanager:DescribeSecret",
"secretsmanager:ListSecretVersionIds"
]
resources = [
"*",
]
effect = "Allow"
}
statement {
actions = [
"ssm:GetParameter"
]
resources = [
"*",
]
effect = "Allow"
}
}
resource "aws_iam_policy" "kubernetes_external_secrets" {
depends_on = [var.mod_dependency]
count = var.enabled ? 1 : 0
name = "${var.cluster_name}-external-secrets"
path = "/"
description = "Policy for external secrets service"
policy = data.aws_iam_policy_document.kubernetes_external_secrets[0].json
}
# Role
data "aws_iam_policy_document" "kubernetes_external_secrets_assume" {
count = var.enabled ? 1 : 0
statement {
actions = ["sts:AssumeRoleWithWebIdentity"]
principals {
type = "Federated"
identifiers = [var.cluster_identity_oidc_issuer_arn]
}
condition {
test = "StringEquals"
variable = "${replace(var.cluster_identity_oidc_issuer, "https://", "")}:sub"
values = [
"system:serviceaccount:${var.namespace}:${var.service_account_name}",
]
}
effect = "Allow"
}
}
resource "aws_iam_role" "kubernetes_external_secrets" {
count = var.enabled ? 1 : 0
name = "${var.cluster_name}-external-secrets"
assume_role_policy = data.aws_iam_policy_document.kubernetes_external_secrets_assume[0].json
}
resource "aws_iam_role_policy_attachment" "kubernetes_external_secrets" {
count = var.enabled ? 1 : 0
role = aws_iam_role.kubernetes_external_secrets[0].name
policy_arn = aws_iam_policy.kubernetes_external_secrets[0].arn
}