-
Notifications
You must be signed in to change notification settings - Fork 0
/
proxy.tf
58 lines (51 loc) · 1.76 KB
/
proxy.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
resource "aws_db_proxy" "proxy" {
count = var.use_proxy ? 1 : 0
name = local.proxy_name
debug_logging = var.proxy_debug_logging
engine_family = var.proxy_engine_family
idle_client_timeout = var.proxy_idle_client_timeout
require_tls = var.proxy_require_tls
role_arn = aws_iam_role.proxy_role[0].arn
vpc_security_group_ids = [aws_security_group.proxy_sg[0].id]
vpc_subnet_ids = local.private_subnets
auth {
auth_scheme = "SECRETS"
description = "Secrets Manager secret for RDS proxy"
iam_auth = var.proxy_iam_auth
secret_arn = aws_secretsmanager_secret.proxy_secret[0].arn
}
tags = merge(
local.tags,
{
"Name" = "${local.name} DB proxy"
}
)
}
resource "aws_db_proxy_endpoint" "reader" {
count = var.use_proxy ? 1 : 0
db_proxy_name = aws_db_proxy.proxy[0].name
db_proxy_endpoint_name = "${aws_db_proxy.proxy[0].name}-ro"
target_role = "READ_ONLY"
vpc_security_group_ids = [aws_security_group.proxy_sg[0].id]
vpc_subnet_ids = local.private_subnets
tags = merge(
local.tags,
{
"Name" = "${local.name} DB proxy reader endpoint"
}
)
}
resource "aws_db_proxy_default_target_group" "default_target_group" {
count = var.use_proxy ? 1 : 0
db_proxy_name = aws_db_proxy.proxy[0].name
depends_on = [
aws_rds_cluster_instance.writer,
aws_rds_cluster_instance.reader,
]
}
resource "aws_db_proxy_target" "target" {
count = var.use_proxy ? 1 : 0
db_cluster_identifier = aws_rds_cluster.db.id
db_proxy_name = aws_db_proxy.proxy[0].name
target_group_name = aws_db_proxy_default_target_group.default_target_group[0].name
}