Skip to content

Commit 8948eeb

Browse files
committed
q!
1 parent e6fec8c commit 8948eeb

11 files changed

+29
-20
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ module "redis" {
3535
redis_port = try(each.value.redis_port, 6379)
3636
redis_snapshot_retention_limit = try(each.value.redis_snapshot_retention_limit, 0)
3737
redis_snapshot_window = try(each.value.redis_snapshot_window, "06:30-07:30") # "The daily time range (in UTC) during which ElastiCache will begin taking a daily snapshot of your cache cluster."
38-
redis_version = try(each.value.redis_version, "3.2.10") # "Whether to enable encryption in transit. Requires 3.2.6 or >=4.0 redis_version"
38+
engine_version = try(each.value.engine_version, "3.2.10") # "Whether to enable encryption in transit. Requires 3.2.6 or >=4.0 engine_version"
3939
snapshot_arns = try(each.value.snapshot_arns, []) # "A single-element string list containing an Amazon Resource Name (ARN) of a Redis RDB snapshot file stored in Amazon S3. Example: arn:aws:s3:::my_bucket/snapshot1.rdb"
4040
snapshot_name = try(each.value.snapshot_name, "") # " The name of a snapshot from which to restore data into the new node group. Changing the snapshot_name forces a new resource"
4141
tags = try(each.value.tags, {})

_locals.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
locals {
2-
major_version = tonumber(replace(var.redis_version, "/\\.[\\d][\\.\\d]*/", ""))
2+
major_version = tonumber(replace(var.engine_version, "/\\.[\\d][\\.\\d]*/", ""))
33
}

outputs.tf

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
output "security_group_id" {
2-
value = aws_security_group.security_group.id
2+
value = aws_security_group.default.id
33
}
44

55
output "parameter_group" {
66
value = aws_elasticache_parameter_group.parameter_group.id
77
}
88

99
output "subnet_group_name" {
10-
value = var.create_subnet_group == true ? aws_elasticache_subnet_group.subnet_group[0].name : ""
10+
value = var.create_subnet_group == true ? aws_elasticache_subnet_group.default[0].name : ""
1111
}
1212

1313
output "id" {
14-
value = aws_elasticache_replication_group.default.id
14+
value = aws_elasticache_replication_group.default[0].id
1515
}
1616

1717
output "port" {
1818
value = var.port
1919
}
2020

2121
output "endpoint" {
22-
value = var.cluster_enabled == true ? aws_elasticache_replication_group.default.configuration_endpoint_address : aws_elasticache_replication_group.default.primary_endpoint_address
22+
value = var.cluster_enabled == true ? aws_elasticache_replication_group.default[0].configuration_endpoint_address : aws_elasticache_replication_group.default[0].primary_endpoint_address
2323
}

parameter_group.tf

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ resource "aws_elasticache_parameter_group" "parameter_group" {
22
name = replace(format("%.255s", lower(replace("tf-elasticache-${var.name}-${var.env}-${var.vpc_id}-${random_id.salt.hex}", "_", "-"))), "/\\s/", "-")
33
description = "Terraform-managed ElastiCache parameter group for ${var.name}-${var.env}-${var.vpc_id}"
44

5-
# Strip the patch version from redis_version var
6-
# family = "redis${replace(var.redis_version, "/\\.[\\d]+$/", "")}"
7-
family = local.major_version >= 7 ? "redis${local.major_version}" : (local.major_version == 6 ? "redis${local.major_version}.x" : "redis${replace(var.redis_version, "/\\.[\\d]+$/", "")}")
5+
# Strip the patch version from engine_version var
6+
# family = "redis${replace(var.engine_version, "/\\.[\\d]+$/", "")}"
7+
family = local.major_version >= 7 ? "redis${local.major_version}" : (local.major_version == 6 ? "redis${local.major_version}.x" : "redis${replace(var.engine_version, "/\\.[\\d]+$/", "")}")
88
dynamic "parameter" {
99
for_each = var.redis_parameters
1010
content {

replicatIon_group.tf replication_group.tf

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ resource "aws_elasticache_replication_group" "default" {
1515
engine_version = var.engine_version
1616
port = var.port
1717
parameter_group_name = aws_elasticache_parameter_group.parameter_group.id
18-
subnet_group_name = try(aws_elasticache_subnet_group.subnet_group[0].id, var.subnet_group_id)
18+
subnet_group_name = try(aws_elasticache_subnet_group.default[0].id, var.subnet_group_id)
1919
security_group_names = var.security_group_names
20-
security_group_ids = [aws_security_group.security_group.id]
20+
security_group_ids = [aws_security_group.default.id]
2121
snapshot_arns = var.snapshot_arns
2222
snapshot_name = var.snapshot_name
2323
apply_immediately = var.apply_immediately

secrets_manager.tf

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ resource "aws_secretsmanager_secret_version" "elasticache" {
88
count = var.secret_method == "secretsmanager" ? 1 : 0
99
secret_id = aws_secretsmanager_secret.elasticache[0].id
1010
secret_string = jsonencode({
11-
"PORT" : aws_elasticache_replication_group.default.port,
12-
"HOST" : aws_elasticache_replication_group.default.cluster_enabled ? aws_elasticache_replication_group.default.configuration_endpoint_address : aws_elasticache_replication_group.default.primary_endpoint_address,
13-
"URL" : "redis${var.transit_encryption_enabled ? "s" : ""}://${aws_elasticache_replication_group.default.cluster_enabled ? aws_elasticache_replication_group.default.configuration_endpoint_address : aws_elasticache_replication_group.default.primary_endpoint_address}:${aws_elasticache_replication_group.default.port}",
11+
"PORT" : aws_elasticache_replication_group.default[0].port,
12+
"HOST" : aws_elasticache_replication_group.default[0].cluster_enabled ? aws_elasticache_replication_group.default[0].configuration_endpoint_address : aws_elasticache_replication_group.default[0].primary_endpoint_address,
13+
"URL" : "redis${var.transit_encryption_enabled ? "s" : ""}://${aws_elasticache_replication_group.default[0].cluster_enabled ? aws_elasticache_replication_group.default[0].configuration_endpoint_address : aws_elasticache_replication_group.default[0].primary_endpoint_address}:${aws_elasticache_replication_group.default[0].port}",
1414
})
1515
}

security_groups.tf

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
resource "aws_security_group" "security_group" {
1+
resource "aws_security_group" "default" {
22
name = format("%.255s", "tf-sg-ec-${var.name}-${var.env}-${var.vpc_id}")
33
description = "Terraform-managed ElastiCache security group for ${var.name}-${var.env}-${var.vpc_id}"
44
vpc_id = var.vpc_id
@@ -15,7 +15,7 @@ resource "aws_security_group_rule" "inbound_from_sg" {
1515
to_port = var.port
1616
protocol = "tcp"
1717
source_security_group_id = each.value.security_group_id
18-
security_group_id = aws_security_group.redis_security_group.id
18+
security_group_id = aws_security_group.default.id
1919
description = try(each.value.description, "From ${each.value.security_group_id}")
2020
}
2121

@@ -26,6 +26,6 @@ resource "aws_security_group_rule" "networks_ingress" {
2626
to_port = var.port
2727
protocol = "tcp"
2828
cidr_blocks = [each.value.cidr]
29-
security_group_id = aws_security_group.redis_security_group.id
29+
security_group_id = aws_security_group.default.id
3030
description = try(each.value.description, "From ${each.value.cidr}")
3131
}

ssm.tf

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ resource "aws_ssm_parameter" "endpoint" {
33
name = "/elasticache/${var.engine}/${var.env}-${var.name}/ENDPOINT"
44
description = "Elasticache Redis Endpoint"
55
type = "String"
6-
value = aws_elasticache_replication_group.default.cluster_enabled ? aws_elasticache_replication_group.default.configuration_endpoint_address : aws_elasticache_replication_group.default.primary_endpoint_address
6+
value = aws_elasticache_replication_group.default[0].cluster_enabled ? aws_elasticache_replication_group.default[0].configuration_endpoint_address : aws_elasticache_replication_group.default[0].primary_endpoint_address
77
}
88

99
resource "aws_ssm_parameter" "port" {
1010
count = var.secret_method == "ssm" ? 1 : 0
1111
name = "/elasticache/${var.engine}/${var.env}-${var.name}/PORT"
1212
description = "Elasticache Redis Port"
1313
type = "String"
14-
value = aws_elasticache_replication_group.default.port
14+
value = aws_elasticache_replication_group.default[0].port
1515
}

variables.tf

+3-1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ variable "name" {
6161
variable "number_clusters" {
6262
description = "Number of Redis cache clusters (nodes) to create"
6363
type = string
64+
default = 0
6465
}
6566

6667
variable "cluster_enabled" {
@@ -178,7 +179,7 @@ variable "kms_key_id" {
178179
}
179180

180181
variable "transit_encryption_enabled" {
181-
description = "Whether to enable encryption in transit. Requires 3.2.6 or >=4.0 redis_version"
182+
description = "Whether to enable encryption in transit. Requires 3.2.6 or >=4.0 engine_version"
182183
type = bool
183184
default = false
184185
}
@@ -234,4 +235,5 @@ variable "create_subnet_group" {
234235
variable "subnet_group_id" {
235236
description = "Subnet group ID to use for the replication group"
236237
type = string
238+
default = null
237239
}

versions.tf

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
11
terraform {
22
required_version = ">= 0.13.0"
3+
required_providers {
4+
aws = {
5+
source = "hashicorp/aws"
6+
version = "> 5.0.0"
7+
}
8+
}
39
}

0 commit comments

Comments
 (0)