Skip to content

Commit fbd4290

Browse files
committed
add new outputs for valkey, update existing output names and their descriptions
1 parent 66a75fa commit fbd4290

File tree

5 files changed

+112
-36
lines changed

5 files changed

+112
-36
lines changed

examples/valkey/example.tf

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ module "secrets_manager" {
5454
name = "aws/elasticache/auth-tokens"
5555
description = "Elasticache AUTH Token"
5656
recovery_window_in_days = 7
57-
secret_string = "{ \"auth_token\": \"UseSomethingSecure*1234\"}"
57+
secret_string = "{ \"auth_token\": \"UseSomethingSecure*1234\"}" # -- The Secret can be changed with any DUMMY_VALUE after `terraform apply`. Terraform will not show any changes for `secret_string` in future plans.
5858
}
5959
]
6060
}
@@ -97,7 +97,8 @@ module "valkey" {
9797
maintenance_window = "sat:03:30-sat:04:30"
9898
}
9999
az_mode = "single-az"
100-
kms_key_id = null # -- AWS Owned KMS Key
100+
kms_key_id = null # -- AWS Owned KMS Key
101+
auto_generate_auth_token = false # -- To Provide your own auth_token
101102
auth_token = jsondecode(data.aws_secretsmanager_secret_version.auth_token.secret_string)["auth_token"]
102103
auth_token_update_strategy = "SET"
103104
sg_ids = [module.vpc.vpc_default_security_group_id]

examples/valkey/outputs.tf

Lines changed: 45 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,45 @@
1-
# output "id" {
2-
# value = module.valkey[*].id
3-
# description = "memcached id."
4-
# }
5-
6-
# output "tags" {
7-
# value = module.memcached.tags
8-
# description = "A mapping of tags to assign to the resource."
9-
# }
10-
11-
# output "memcached_endpoint" {
12-
# value = module.memcached.memcached_endpoint
13-
# description = "Memcached endpoint address."
14-
# }
15-
16-
# output "hostname" {
17-
# value = module.memcached.hostname
18-
# description = "DNS hostname"
19-
# }
20-
21-
# output "redis_ssm_arn" {
22-
# value = module.memcached.Memcached_ssm_name
23-
# description = "A map of the names and ARNs created"
24-
# }
1+
### ---------- aws_elasticache_replication_group --------------------
2+
output "valkey_elasticache_arn" {
3+
description = "ARN of the created ElastiCache Replication Group."
4+
value = module.valkey.elasticache_arn
5+
}
6+
7+
output "valkey_elasticache_engine_version" {
8+
description = "Running version of the cache engine."
9+
value = module.valkey.elasticache_engine_version
10+
}
11+
12+
output "valkey_elasticache_cluster_enabled" {
13+
description = "Indicates if cluster mode is enabled."
14+
value = module.valkey.elasticache_cluster_enabled
15+
}
16+
17+
output "valkey_elasticache_configuration_endpoint_address" {
18+
description = "Address of the replication group configuration endpoint when cluster mode is enabled."
19+
value = module.valkey.elasticache_configuration_endpoint_address
20+
}
21+
22+
output "valkey_elasticache_id" {
23+
description = "ID of the ElastiCache Replication Group."
24+
value = module.valkey.id
25+
}
26+
27+
output "valkey_elasticache_member_clusters" {
28+
description = "Identifiers of all the nodes that are part of this replication group."
29+
value = module.valkey.elasticache_member_clusters
30+
}
31+
32+
output "valkey_elasticache_primary_endpoint_address" {
33+
description = "Address of the endpoint for the primary node in the replication group, if cluster mode is disabled."
34+
value = module.valkey.elasticache_endpoint
35+
}
36+
37+
output "valkey_elasticache_reader_endpoint_address" {
38+
description = "Address of the endpoint for the reader node in the replication group, if cluster mode is disabled."
39+
value = module.valkey.elasticache_reader_endpoint_address
40+
}
41+
42+
output "valkey_elasticache_tags_all" {
43+
description = "Map of tags assigned to the resource, including inherited ones."
44+
value = module.valkey.elasticache_tags_all
45+
}

main.tf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ resource "aws_elasticache_subnet_group" "default" {
142142
##----------------------------------------------------------------------------------
143143

144144
resource "random_password" "auth_token" {
145-
count = var.enable && var.auth_token_enable && var.auth_token == null ? 1 : 0
145+
count = var.enable && var.auth_token_enable && var.auto_generate_auth_token ? 1 : 0
146146
length = var.length
147147
special = var.special
148148
}
@@ -178,7 +178,7 @@ resource "aws_elasticache_replication_group" "cluster" {
178178
multi_az_enabled = lookup(var.replication_group, "multi_az_enabled", false)
179179
network_type = var.network_type
180180

181-
auth_token = var.auth_token_enable ? (var.auth_token == null ? random_password.auth_token[0].result : var.auth_token) : ""
181+
auth_token = var.auth_token_enable ? (var.auto_generate_auth_token ? random_password.auth_token[0].result : var.auth_token) : ""
182182
auth_token_update_strategy = var.auth_token_enable ? var.auth_token_update_strategy : null
183183
kms_key_id = var.kms_key_id == "" ? join("", aws_kms_key.default[*].arn) : var.kms_key_id
184184
tags = module.labels.tags
@@ -247,7 +247,7 @@ resource "aws_ssm_parameter" "secret" {
247247
name = format("/%s/%s/auth-token", var.environment, var.name)
248248
description = var.ssm_parameter_description
249249
type = var.ssm_parameter_type
250-
value = var.auth_token == null ? random_password.auth_token[0].result : var.auth_token
250+
value = var.auto_generate_auth_token ? random_password.auth_token[0].result : var.auth_token
251251
key_id = var.kms_key_id == "" ? join("", aws_kms_key.default[*].arn) : var.kms_key_id
252252
}
253253

outputs.tf

Lines changed: 55 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# Description : Terraform module to create Elasticache Cluster and replica for Redis.
33
output "id" {
44
value = var.cluster_enabled ? "" : (var.cluster_replication_enabled ? join("", aws_elasticache_replication_group.cluster[*].id) : join("", aws_elasticache_replication_group.cluster[*].id))
5-
description = "Redis cluster id."
5+
description = "Elasticache cluster id."
66
}
77

88
output "port" {
@@ -16,14 +16,14 @@ output "tags" {
1616
description = "A mapping of tags to assign to the resource."
1717
}
1818

19-
output "redis_endpoint" {
19+
output "elasticache_endpoint" {
2020
value = var.cluster_replication_enabled ? "" : (var.cluster_replication_enabled ? join("", aws_elasticache_replication_group.cluster[*].primary_endpoint_address) : join("", aws_elasticache_cluster.default[*].configuration_endpoint))
21-
description = "Redis endpoint address."
21+
description = "Elasticache endpoint address."
2222
}
2323

24-
output "redis_arn" {
24+
output "elasticache_arn" {
2525
value = var.enable && length(aws_elasticache_replication_group.cluster) > 0 ? aws_elasticache_replication_group.cluster[0].arn : length(aws_elasticache_replication_group.cluster) > 0 ? aws_elasticache_replication_group.cluster[0].arn : null
26-
description = "Redis arn"
26+
description = "Elasticache arn"
2727
}
2828

2929
output "memcached_endpoint" {
@@ -61,7 +61,55 @@ output "Memcached_ssm_name" {
6161
}
6262

6363
output "auth_token" {
64-
value = var.enable && var.auth_token_enable && var.auth_token == null ? random_password.auth_token[0].result : null
64+
value = var.enable && var.auth_token_enable && var.auto_generate_auth_token ? random_password.auth_token[0].result : null
6565
sensitive = true
6666
description = "Auth token generated value"
67-
}
67+
}
68+
69+
### ---------- aws_elasticache_cluster ------------------------------
70+
output "elasticache_engine_version_actual" {
71+
value = try(aws_elasticache_cluster.default[0].engine_version_actual, null)
72+
description = "Running version of the cache engine"
73+
}
74+
75+
output "elasticache_cache_nodes" {
76+
value = try(aws_elasticache_cluster.default[0].cache_nodes, [])
77+
description = "List of node objects"
78+
}
79+
80+
output "elasticache_cluster_address" {
81+
value = try(aws_elasticache_cluster.default[0].cluster_address, null)
82+
description = "(Memcached only) DNS name of the cache cluster"
83+
}
84+
85+
### ---------- aws_elasticache_replication_group --------------------
86+
87+
output "elasticache_engine_version" {
88+
description = "Running version of the cache engine."
89+
value = try(aws_elasticache_replication_group.cluster[0].engine_version_actual, null)
90+
}
91+
92+
output "elasticache_cluster_enabled" {
93+
description = "Indicates if cluster mode is enabled."
94+
value = try(aws_elasticache_replication_group.cluster[0].cluster_enabled, null)
95+
}
96+
97+
output "elasticache_configuration_endpoint_address" {
98+
description = "Address of the replication group configuration endpoint when cluster mode is enabled."
99+
value = try(aws_elasticache_replication_group.cluster[0].configuration_endpoint_address, null)
100+
}
101+
102+
output "elasticache_member_clusters" {
103+
description = "Identifiers of all the nodes that are part of this replication group."
104+
value = try([for c in aws_elasticache_replication_group.cluster[0].member_clusters : c], null)
105+
}
106+
107+
output "elasticache_reader_endpoint_address" {
108+
description = "Address of the endpoint for the reader node in the replication group, if cluster mode is disabled."
109+
value = try(aws_elasticache_replication_group.cluster[0].reader_endpoint_address, null)
110+
}
111+
112+
output "elasticache_tags_all" {
113+
description = "Map of tags assigned to the resource, including inherited ones."
114+
value = try(aws_elasticache_replication_group.cluster[0].tags_all, null)
115+
}

variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,12 @@ variable "auth_token_enable" {
9393
description = "Flag to specify whether to create auth token (password) protected cluster. Can be specified only if transit_encryption_enabled = true."
9494
}
9595

96+
variable "auto_generate_auth_token" {
97+
type = bool
98+
default = true
99+
description = "Whether to automatically generate the authentication token using Terraform. If set to false, you must provide your own token via the 'auth_token' variable."
100+
}
101+
96102
variable "auth_token" {
97103
type = string
98104
default = null

0 commit comments

Comments
 (0)