-
Notifications
You must be signed in to change notification settings - Fork 0
/
rds_proxy_role.tf
58 lines (52 loc) · 1.48 KB
/
rds_proxy_role.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
data "aws_iam_policy_document" "assume_role" {
count = var.rds_proxy_enabled ? 1 : 0
statement {
effect = "Allow"
actions = ["sts:AssumeRole"]
principals {
type = "Service"
identifiers = ["rds.amazonaws.com"]
}
}
}
data "aws_iam_policy_document" "rds_proxy_policy_document" {
count = var.rds_proxy_enabled ? 1 : 0
statement {
sid = "AllowProxyToGetDbCredsFromSecretsManager"
actions = [
"secretsmanager:GetSecretValue"
]
resources = [
aws_secretsmanager_secret.rds_secret[0].arn
]
}
statement {
sid = "AllowProxyToDecryptDbCredsFromSecretsManager"
actions = [
"kms:Decrypt"
]
resources = [
"*"
]
condition {
test = "StringEquals"
values = ["secretsmanager.${var.aws_region}.amazonaws.com"]
variable = "kms:ViaService"
}
}
}
resource "aws_iam_policy" "rds_proxy_iam_policy" {
count = var.rds_proxy_enabled ? 1 : 0
name = "rds-proxy-policy"
policy = data.aws_iam_policy_document.rds_proxy_policy_document[0].json
}
resource "aws_iam_role_policy_attachment" "rds_proxy_iam_attach" {
count = var.rds_proxy_enabled ? 1 : 0
policy_arn = aws_iam_policy.rds_proxy_iam_policy[0].arn
role = aws_iam_role.rds_proxy_iam_role[0].name
}
resource "aws_iam_role" "rds_proxy_iam_role" {
count = var.rds_proxy_enabled ? 1 : 0
name = "rds-proxy-role"
assume_role_policy = data.aws_iam_policy_document.assume_role[0].json
}