Skip to content

Commit 99a3cb0

Browse files
committed
Allow selecting secret method for output
1 parent bec20ec commit 99a3cb0

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

secrets-manager.tf

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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+
}

ssm.tf

+2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
resource "aws_ssm_parameter" "redis_endpoint" {
2+
count = var.secret_method == "ssm" ? 1 : 0
23
name = "/elasticache/redis/${var.env}-${var.name}/ENDPOINT"
34
description = "Elasticache Redis Endpoint"
45
type = "String"
56
value = aws_elasticache_replication_group.redis.cluster_enabled ? aws_elasticache_replication_group.redis.configuration_endpoint_address : aws_elasticache_replication_group.redis.primary_endpoint_address
67
}
78
resource "aws_ssm_parameter" "redis_port" {
9+
count = var.secret_method == "ssm" ? 1 : 0
810
name = "/elasticache/redis/${var.env}-${var.name}/PORT"
911
description = "Elasticache Redis Port"
1012
type = "String"

variables.tf

+6
Original file line numberDiff line numberDiff line change
@@ -198,3 +198,9 @@ variable "notification_topic_arn" {
198198
type = string
199199
default = ""
200200
}
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+
}

0 commit comments

Comments
 (0)