File tree 3 files changed +23
-0
lines changed
3 files changed +23
-0
lines changed Original file line number Diff line number Diff line change
1
+ resource "aws_secretsmanager_secret" "elasticache" {
2
+ count = var. secret_method == " secretsmanager" ? 1 : 0
3
+ name = " /elasticache/${ var . env } -${ var . name } "
4
+ recovery_window_in_days = 0
5
+ }
6
+
7
+ resource "aws_secretsmanager_secret_version" "elasticache" {
8
+ count = var. secret_method == " secretsmanager" ? 1 : 0
9
+ secret_id = aws_secretsmanager_secret. elasticache [0 ]. id
10
+ secret_string = jsonencode ({
11
+ " REDIS_PORT" : aws_elasticache_replication_group.redis.port,
12
+ " REDIS_HOST" : aws_elasticache_replication_group.redis.cluster_enabled ? aws_elasticache_replication_group.redis.configuration_endpoint_address : aws_elasticache_replication_group.redis.primary_endpoint_address,
13
+ " REDIS_URL" : " redis://${ aws_elasticache_replication_group . redis . cluster_enabled ? aws_elasticache_replication_group . redis . configuration_endpoint_address : aws_elasticache_replication_group . redis . primary_endpoint_address } " ,
14
+ })
15
+ }
Original file line number Diff line number Diff line change 1
1
resource "aws_ssm_parameter" "redis_endpoint" {
2
+ count = var. secret_method == " ssm" ? 1 : 0
2
3
name = " /elasticache/redis/${ var . env } -${ var . name } /ENDPOINT"
3
4
description = " Elasticache Redis Endpoint"
4
5
type = " String"
5
6
value = aws_elasticache_replication_group. redis . cluster_enabled ? aws_elasticache_replication_group. redis . configuration_endpoint_address : aws_elasticache_replication_group. redis . primary_endpoint_address
6
7
}
7
8
resource "aws_ssm_parameter" "redis_port" {
9
+ count = var. secret_method == " ssm" ? 1 : 0
8
10
name = " /elasticache/redis/${ var . env } -${ var . name } /PORT"
9
11
description = " Elasticache Redis Port"
10
12
type = " String"
Original file line number Diff line number Diff line change @@ -198,3 +198,9 @@ variable "notification_topic_arn" {
198
198
type = string
199
199
default = " "
200
200
}
201
+
202
+ variable "secret_method" {
203
+ description = " Use ssm for SSM parameters store which is the default option, or secretsmanager for AWS Secrets Manager"
204
+ type = string
205
+ default = " ssm"
206
+ }
You can’t perform that action at this time.
0 commit comments