From 304bc40c2c89c6268f56e3d9ba4469d1bdff744b Mon Sep 17 00:00:00 2001 From: torz Date: Fri, 4 Oct 2019 15:42:11 +0100 Subject: [PATCH 01/17] updated syntax to 0.12 --- cloudwatch.tf | 1 - main.tf | 86 +++++++++++++++++++++++++++++++++++----------- outputs.tf | 13 +++---- security_groups.tf | 28 ++++++++------- variables.tf | 9 ++--- versions.tf | 4 +++ 6 files changed, 98 insertions(+), 43 deletions(-) create mode 100644 versions.tf diff --git a/cloudwatch.tf b/cloudwatch.tf index 75bbea9..5ec7a4d 100644 --- a/cloudwatch.tf +++ b/cloudwatch.tf @@ -45,4 +45,3 @@ resource "aws_cloudwatch_metric_alarm" "cache_memory" { alarm_actions = ["${var.alarm_actions}"] } */ - diff --git a/main.tf b/main.tf index 40ebd3c..7c06d0f 100644 --- a/main.tf +++ b/main.tf @@ -1,5 +1,5 @@ data "aws_vpc" "vpc" { - id = "${var.vpc_id}" + id = var.vpc_id } resource "random_id" "salt" { @@ -7,31 +7,64 @@ resource "random_id" "salt" { } resource "aws_elasticache_replication_group" "redis" { - replication_group_id = "${format("%.20s","${var.name}-${var.env}")}" + replication_group_id = format("%.20s", "${var.name}-${var.env}") replication_group_description = "Terraform-managed ElastiCache replication group for ${var.name}-${var.env}-${data.aws_vpc.vpc.tags["Name"]}" - number_cache_clusters = "${var.redis_clusters}" - node_type = "${var.redis_node_type}" - automatic_failover_enabled = "${var.redis_failover}" - engine_version = "${var.redis_version}" - port = "${var.redis_port}" - parameter_group_name = "${aws_elasticache_parameter_group.redis_parameter_group.id}" - subnet_group_name = "${aws_elasticache_subnet_group.redis_subnet_group.id}" - security_group_ids = ["${aws_security_group.redis_security_group.id}"] - apply_immediately = "${var.apply_immediately}" - maintenance_window = "${var.redis_maintenance_window}" - snapshot_window = "${var.redis_snapshot_window}" - snapshot_retention_limit = "${var.redis_snapshot_retention_limit}" - tags = "${merge(map("Name", format("tf-elasticache-%s-%s", var.name, lookup(data.aws_vpc.vpc.tags,"Name",""))), var.tags)}" + number_cache_clusters = var.redis_clusters + node_type = var.redis_node_type + automatic_failover_enabled = var.redis_failover + engine_version = var.redis_version + port = var.redis_port + parameter_group_name = aws_elasticache_parameter_group.redis_parameter_group.id + subnet_group_name = aws_elasticache_subnet_group.redis_subnet_group.id + security_group_ids = [aws_security_group.redis_security_group.id] + apply_immediately = var.apply_immediately + maintenance_window = var.redis_maintenance_window + snapshot_window = var.redis_snapshot_window + snapshot_retention_limit = var.redis_snapshot_retention_limit + tags = merge( + { + "Name" = format( + "tf-elasticache-%s-%s", + var.name, + lookup(data.aws_vpc.vpc.tags, "Name", ""), + ) + }, + var.tags, + ) } resource "aws_elasticache_parameter_group" "redis_parameter_group" { - name = "${replace(format("%.255s", lower(replace("tf-redis-${var.name}-${var.env}-${data.aws_vpc.vpc.tags["Name"]}-${random_id.salt.hex}", "_", "-"))), "/\\s/", "-")}" + name = replace( + format( + "%.255s", + lower( + replace( + "tf-redis-${var.name}-${var.env}-${data.aws_vpc.vpc.tags["Name"]}-${random_id.salt.hex}", + "_", + "-", + ), + ), + ), + "/\\s/", + "-", + ) description = "Terraform-managed ElastiCache parameter group for ${var.name}-${var.env}-${data.aws_vpc.vpc.tags["Name"]}" # Strip the patch version from redis_version var - family = "redis${replace(var.redis_version, "/\\.[\\d]+$/","")}" - parameter = "${var.redis_parameters}" + family = "redis${replace(var.redis_version, "/\\.[\\d]+$/", "")}" + dynamic "parameter" { + for_each = var.redis_parameters + content { + # TF-UPGRADE-TODO: The automatic upgrade tool can't predict + # which keys might be set in maps assigned here, so it has + # produced a comprehensive set here. Consider simplifying + # this after confirming which keys can be set in practice. + + name = parameter.value.name + value = parameter.value.value + } + } lifecycle { create_before_destroy = true @@ -39,6 +72,19 @@ resource "aws_elasticache_parameter_group" "redis_parameter_group" { } resource "aws_elasticache_subnet_group" "redis_subnet_group" { - name = "${replace(format("%.255s", lower(replace("tf-redis-${var.name}-${var.env}-${data.aws_vpc.vpc.tags["Name"]}", "_", "-"))), "/\\s/", "-")}" - subnet_ids = ["${var.subnets}"] + name = replace( + format( + "%.255s", + lower( + replace( + "tf-redis-${var.name}-${var.env}-${data.aws_vpc.vpc.tags["Name"]}", + "_", + "-", + ), + ), + ), + "/\\s/", + "-", + ) + subnet_ids = var.subnets } diff --git a/outputs.tf b/outputs.tf index da6df54..8ccbbd4 100644 --- a/outputs.tf +++ b/outputs.tf @@ -1,23 +1,24 @@ output "redis_security_group_id" { - value = "${aws_security_group.redis_security_group.id}" + value = aws_security_group.redis_security_group.id } output "parameter_group" { - value = "${aws_elasticache_parameter_group.redis_parameter_group.id}" + value = aws_elasticache_parameter_group.redis_parameter_group.id } output "redis_subnet_group_name" { - value = "${aws_elasticache_subnet_group.redis_subnet_group.name}" + value = aws_elasticache_subnet_group.redis_subnet_group.name } output "id" { - value = "${aws_elasticache_replication_group.redis.id}" + value = aws_elasticache_replication_group.redis.id } output "port" { - value = "${var.redis_port}" + value = var.redis_port } output "endpoint" { - value = "${aws_elasticache_replication_group.redis.primary_endpoint_address}" + value = aws_elasticache_replication_group.redis.primary_endpoint_address } + diff --git a/security_groups.tf b/security_groups.tf index 9b86875..a2d498b 100644 --- a/security_groups.tf +++ b/security_groups.tf @@ -1,28 +1,32 @@ resource "aws_security_group" "redis_security_group" { - name = "${format("%.255s", "tf-sg-ec-${var.name}-${var.env}-${data.aws_vpc.vpc.tags["Name"]}")}" + name = format( + "%.255s", + "tf-sg-ec-${var.name}-${var.env}-${data.aws_vpc.vpc.tags["Name"]}", + ) description = "Terraform-managed ElastiCache security group for ${var.name}-${var.env}-${data.aws_vpc.vpc.tags["Name"]}" - vpc_id = "${data.aws_vpc.vpc.id}" + vpc_id = data.aws_vpc.vpc.id - tags { + tags = { Name = "tf-sg-ec-${var.name}-${var.env}-${data.aws_vpc.vpc.tags["Name"]}" } } resource "aws_security_group_rule" "redis_ingress" { - count = "${length(var.allowed_security_groups)}" + count = length(var.allowed_security_groups) type = "ingress" - from_port = "${var.redis_port}" - to_port = "${var.redis_port}" + from_port = var.redis_port + to_port = var.redis_port protocol = "tcp" - source_security_group_id = "${element(var.allowed_security_groups, count.index)}" - security_group_id = "${aws_security_group.redis_security_group.id}" + source_security_group_id = element(var.allowed_security_groups, count.index) + security_group_id = aws_security_group.redis_security_group.id } resource "aws_security_group_rule" "redis_networks_ingress" { type = "ingress" - from_port = "${var.redis_port}" - to_port = "${var.redis_port}" + from_port = var.redis_port + to_port = var.redis_port protocol = "tcp" - cidr_blocks = ["${var.allowed_cidr}"] - security_group_id = "${aws_security_group.redis_security_group.id}" + cidr_blocks = var.allowed_cidr + security_group_id = aws_security_group.redis_security_group.id } + diff --git a/variables.tf b/variables.tf index 9da1683..49d0df0 100644 --- a/variables.tf +++ b/variables.tf @@ -20,13 +20,13 @@ variable "apply_immediately" { } variable "allowed_cidr" { - type = "list" + type = list(string) default = ["127.0.0.1/32"] description = "A list of Security Group ID's to allow access to." } variable "allowed_security_groups" { - type = "list" + type = list(string) default = [] description = "A list of Security Group ID's to allow access to." } @@ -57,7 +57,7 @@ variable "redis_port" { } variable "subnets" { - type = "list" + type = list(string) description = "List of VPC Subnet IDs for the cache subnet group" } @@ -72,7 +72,7 @@ variable "vpc_id" { } variable "redis_parameters" { - type = "list" + type = list(string) description = "additional parameters modifyed in parameter group" default = [] } @@ -96,3 +96,4 @@ variable "tags" { description = "Tags for redis nodes" default = {} } + diff --git a/versions.tf b/versions.tf new file mode 100644 index 0000000..ac97c6a --- /dev/null +++ b/versions.tf @@ -0,0 +1,4 @@ + +terraform { + required_version = ">= 0.12" +} From 85f4acabc158387501dbea8a492060fcfe459257 Mon Sep 17 00:00:00 2001 From: torz Date: Wed, 9 Oct 2019 10:38:13 +0100 Subject: [PATCH 02/17] ignore changes to resrouce description --- main.tf | 1 + 1 file changed, 1 insertion(+) diff --git a/main.tf b/main.tf index 7c06d0f..0e0b3fb 100644 --- a/main.tf +++ b/main.tf @@ -68,6 +68,7 @@ resource "aws_elasticache_parameter_group" "redis_parameter_group" { lifecycle { create_before_destroy = true + ignore_changes = ["description"] } } From 3b380334723555e91a2685cf2e562c298815915b Mon Sep 17 00:00:00 2001 From: torz Date: Wed, 9 Oct 2019 10:45:33 +0100 Subject: [PATCH 03/17] set name to simple format --- main.tf | 37 ++++++------------------------------- 1 file changed, 6 insertions(+), 31 deletions(-) diff --git a/main.tf b/main.tf index 0e0b3fb..b38ced2 100644 --- a/main.tf +++ b/main.tf @@ -8,7 +8,7 @@ resource "random_id" "salt" { resource "aws_elasticache_replication_group" "redis" { replication_group_id = format("%.20s", "${var.name}-${var.env}") - replication_group_description = "Terraform-managed ElastiCache replication group for ${var.name}-${var.env}-${data.aws_vpc.vpc.tags["Name"]}" + replication_group_description = "Terraform-managed ElastiCache replication group for ${var.name}-${var.env}" number_cache_clusters = var.redis_clusters node_type = var.redis_node_type automatic_failover_enabled = var.redis_failover @@ -34,22 +34,11 @@ resource "aws_elasticache_replication_group" "redis" { } resource "aws_elasticache_parameter_group" "redis_parameter_group" { - name = replace( - format( - "%.255s", - lower( - replace( - "tf-redis-${var.name}-${var.env}-${data.aws_vpc.vpc.tags["Name"]}-${random_id.salt.hex}", - "_", - "-", - ), - ), - ), - "/\\s/", - "-", - ) - description = "Terraform-managed ElastiCache parameter group for ${var.name}-${var.env}-${data.aws_vpc.vpc.tags["Name"]}" + # tf-redis-sc-api-queue-dev + name = "tf-redis-${var.name}-${var.env}" + + description = "Terraform-managed ElastiCache parameter group for ${var.name}-${var.env}" # Strip the patch version from redis_version var family = "redis${replace(var.redis_version, "/\\.[\\d]+$/", "")}" @@ -68,24 +57,10 @@ resource "aws_elasticache_parameter_group" "redis_parameter_group" { lifecycle { create_before_destroy = true - ignore_changes = ["description"] } } resource "aws_elasticache_subnet_group" "redis_subnet_group" { - name = replace( - format( - "%.255s", - lower( - replace( - "tf-redis-${var.name}-${var.env}-${data.aws_vpc.vpc.tags["Name"]}", - "_", - "-", - ), - ), - ), - "/\\s/", - "-", - ) + name = "tf-redis-${var.name}-${var.env}" subnet_ids = var.subnets } From 977ded169bd22dcd0579bae0f8fedc951be9609f Mon Sep 17 00:00:00 2001 From: torz Date: Wed, 9 Oct 2019 10:54:56 +0100 Subject: [PATCH 04/17] changed default redis version --- variables.tf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/variables.tf b/variables.tf index 49d0df0..910abf3 100644 --- a/variables.tf +++ b/variables.tf @@ -63,8 +63,8 @@ variable "subnets" { # might want a map variable "redis_version" { - description = "Redis version to use, defaults to 3.2.10" - default = "3.2.10" + description = "Redis version to use, defaults to 3.2.4" + default = "3.2.4" } variable "vpc_id" { From 51b298b4ebfa2af9dc1088b88e2ac2246f9797c2 Mon Sep 17 00:00:00 2001 From: torz Date: Wed, 9 Oct 2019 11:01:00 +0100 Subject: [PATCH 05/17] sg names changed to simple version --- security_groups.tf | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/security_groups.tf b/security_groups.tf index a2d498b..49d3f0c 100644 --- a/security_groups.tf +++ b/security_groups.tf @@ -1,13 +1,10 @@ resource "aws_security_group" "redis_security_group" { - name = format( - "%.255s", - "tf-sg-ec-${var.name}-${var.env}-${data.aws_vpc.vpc.tags["Name"]}", - ) - description = "Terraform-managed ElastiCache security group for ${var.name}-${var.env}-${data.aws_vpc.vpc.tags["Name"]}" + name = "tf-sg-ec-${var.name}-${var.env}" + description = "Terraform-managed ElastiCache security group for ${var.name}-${var.env}" vpc_id = data.aws_vpc.vpc.id tags = { - Name = "tf-sg-ec-${var.name}-${var.env}-${data.aws_vpc.vpc.tags["Name"]}" + Name = "tf-sg-ec-${var.name}-${var.env}" } } @@ -29,4 +26,3 @@ resource "aws_security_group_rule" "redis_networks_ingress" { cidr_blocks = var.allowed_cidr security_group_id = aws_security_group.redis_security_group.id } - From 220b997ea18d23313b5d25335bcd2a7c9b0791ae Mon Sep 17 00:00:00 2001 From: torz Date: Wed, 9 Oct 2019 11:10:25 +0100 Subject: [PATCH 06/17] set default vars to old value --- security_groups.tf | 2 +- variables.tf | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/security_groups.tf b/security_groups.tf index 49d3f0c..e4f6de5 100644 --- a/security_groups.tf +++ b/security_groups.tf @@ -1,5 +1,5 @@ resource "aws_security_group" "redis_security_group" { - name = "tf-sg-ec-${var.name}-${var.env}" + name = "tf-sg-ec-${var.name}-${var.env}" description = "Terraform-managed ElastiCache security group for ${var.name}-${var.env}" vpc_id = data.aws_vpc.vpc.id diff --git a/variables.tf b/variables.tf index 910abf3..541b993 100644 --- a/variables.tf +++ b/variables.tf @@ -79,12 +79,12 @@ variable "redis_parameters" { variable "redis_maintenance_window" { description = "Specifies the weekly time range for when maintenance on the cache cluster is performed. The format is ddd:hh24:mi-ddd:hh24:mi (24H Clock UTC). The minimum maintenance window is a 60 minute period" - default = "fri:08:00-fri:09:00" + default = "tue:23:30-wed:00:30" } variable "redis_snapshot_window" { description = "The daily time range (in UTC) during which ElastiCache will begin taking a daily snapshot of your cache cluster. The minimum snapshot window is a 60 minute period" - default = "06:30-07:30" + default = "04:00-05:00" } variable "redis_snapshot_retention_limit" { From 9ac845b74d21cd307d147283324351c2f05e027d Mon Sep 17 00:00:00 2001 From: torz Date: Fri, 11 Oct 2019 10:14:04 +0100 Subject: [PATCH 07/17] change names of resources --- main.tf | 10 +++++----- security_groups.tf | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/main.tf b/main.tf index b38ced2..723922c 100644 --- a/main.tf +++ b/main.tf @@ -7,8 +7,8 @@ resource "random_id" "salt" { } resource "aws_elasticache_replication_group" "redis" { - replication_group_id = format("%.20s", "${var.name}-${var.env}") - replication_group_description = "Terraform-managed ElastiCache replication group for ${var.name}-${var.env}" + replication_group_id = format("%.20s", "${var.name}") + replication_group_description = "Terraform-managed ElastiCache replication group for ${var.name}" number_cache_clusters = var.redis_clusters node_type = var.redis_node_type automatic_failover_enabled = var.redis_failover @@ -36,9 +36,9 @@ resource "aws_elasticache_replication_group" "redis" { resource "aws_elasticache_parameter_group" "redis_parameter_group" { # tf-redis-sc-api-queue-dev - name = "tf-redis-${var.name}-${var.env}" + name = "tf-redis-${var.name}" - description = "Terraform-managed ElastiCache parameter group for ${var.name}-${var.env}" + description = "Terraform-managed ElastiCache parameter group for ${var.name}" # Strip the patch version from redis_version var family = "redis${replace(var.redis_version, "/\\.[\\d]+$/", "")}" @@ -61,6 +61,6 @@ resource "aws_elasticache_parameter_group" "redis_parameter_group" { } resource "aws_elasticache_subnet_group" "redis_subnet_group" { - name = "tf-redis-${var.name}-${var.env}" + name = "tf-redis-${var.name}" subnet_ids = var.subnets } diff --git a/security_groups.tf b/security_groups.tf index e4f6de5..81e0c6f 100644 --- a/security_groups.tf +++ b/security_groups.tf @@ -1,6 +1,6 @@ resource "aws_security_group" "redis_security_group" { - name = "tf-sg-ec-${var.name}-${var.env}" - description = "Terraform-managed ElastiCache security group for ${var.name}-${var.env}" + name = "tf-sg-ec-${var.name}" + description = "Terraform-managed ElastiCache security group for ${var.name}" vpc_id = data.aws_vpc.vpc.id tags = { From e00cfcd6fcf4db83cc39986322985e3c752c9e2c Mon Sep 17 00:00:00 2001 From: torz Date: Fri, 11 Oct 2019 10:40:52 +0100 Subject: [PATCH 08/17] revert name changes --- main.tf | 10 +++++----- security_groups.tf | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/main.tf b/main.tf index 723922c..b38ced2 100644 --- a/main.tf +++ b/main.tf @@ -7,8 +7,8 @@ resource "random_id" "salt" { } resource "aws_elasticache_replication_group" "redis" { - replication_group_id = format("%.20s", "${var.name}") - replication_group_description = "Terraform-managed ElastiCache replication group for ${var.name}" + replication_group_id = format("%.20s", "${var.name}-${var.env}") + replication_group_description = "Terraform-managed ElastiCache replication group for ${var.name}-${var.env}" number_cache_clusters = var.redis_clusters node_type = var.redis_node_type automatic_failover_enabled = var.redis_failover @@ -36,9 +36,9 @@ resource "aws_elasticache_replication_group" "redis" { resource "aws_elasticache_parameter_group" "redis_parameter_group" { # tf-redis-sc-api-queue-dev - name = "tf-redis-${var.name}" + name = "tf-redis-${var.name}-${var.env}" - description = "Terraform-managed ElastiCache parameter group for ${var.name}" + description = "Terraform-managed ElastiCache parameter group for ${var.name}-${var.env}" # Strip the patch version from redis_version var family = "redis${replace(var.redis_version, "/\\.[\\d]+$/", "")}" @@ -61,6 +61,6 @@ resource "aws_elasticache_parameter_group" "redis_parameter_group" { } resource "aws_elasticache_subnet_group" "redis_subnet_group" { - name = "tf-redis-${var.name}" + name = "tf-redis-${var.name}-${var.env}" subnet_ids = var.subnets } diff --git a/security_groups.tf b/security_groups.tf index 81e0c6f..e4f6de5 100644 --- a/security_groups.tf +++ b/security_groups.tf @@ -1,6 +1,6 @@ resource "aws_security_group" "redis_security_group" { - name = "tf-sg-ec-${var.name}" - description = "Terraform-managed ElastiCache security group for ${var.name}" + name = "tf-sg-ec-${var.name}-${var.env}" + description = "Terraform-managed ElastiCache security group for ${var.name}-${var.env}" vpc_id = data.aws_vpc.vpc.id tags = { From 2340e56a178296f62a847904cf9290af6956a6a4 Mon Sep 17 00:00:00 2001 From: torz Date: Fri, 11 Oct 2019 12:30:34 +0100 Subject: [PATCH 09/17] longer name --- main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.tf b/main.tf index b38ced2..4c2ab19 100644 --- a/main.tf +++ b/main.tf @@ -7,7 +7,7 @@ resource "random_id" "salt" { } resource "aws_elasticache_replication_group" "redis" { - replication_group_id = format("%.20s", "${var.name}-${var.env}") + replication_group_id = format("%.32s", "${var.name}-${var.env}") replication_group_description = "Terraform-managed ElastiCache replication group for ${var.name}-${var.env}" number_cache_clusters = var.redis_clusters node_type = var.redis_node_type From 3177150399586f7e551f49ca0445cf68256ba471 Mon Sep 17 00:00:00 2001 From: torz Date: Mon, 14 Oct 2019 14:45:47 +0100 Subject: [PATCH 10/17] name fix --- main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.tf b/main.tf index 4c2ab19..b38ced2 100644 --- a/main.tf +++ b/main.tf @@ -7,7 +7,7 @@ resource "random_id" "salt" { } resource "aws_elasticache_replication_group" "redis" { - replication_group_id = format("%.32s", "${var.name}-${var.env}") + replication_group_id = format("%.20s", "${var.name}-${var.env}") replication_group_description = "Terraform-managed ElastiCache replication group for ${var.name}-${var.env}" number_cache_clusters = var.redis_clusters node_type = var.redis_node_type From 10cfaeb5717852eea200b9e5eb7fa4c0fadd3798 Mon Sep 17 00:00:00 2001 From: torz Date: Mon, 14 Oct 2019 15:06:36 +0100 Subject: [PATCH 11/17] remove trailing special char --- main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.tf b/main.tf index b38ced2..802bd37 100644 --- a/main.tf +++ b/main.tf @@ -7,7 +7,7 @@ resource "random_id" "salt" { } resource "aws_elasticache_replication_group" "redis" { - replication_group_id = format("%.20s", "${var.name}-${var.env}") + replication_group_id = replace(format("%.20s", "${var.name}-${var.env}"), "-$", "") replication_group_description = "Terraform-managed ElastiCache replication group for ${var.name}-${var.env}" number_cache_clusters = var.redis_clusters node_type = var.redis_node_type From 0eb6c46c62fc38f76cb019771b6b7f952a82fd74 Mon Sep 17 00:00:00 2001 From: torz Date: Mon, 14 Oct 2019 15:10:16 +0100 Subject: [PATCH 12/17] fix regex --- main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.tf b/main.tf index 802bd37..3456f99 100644 --- a/main.tf +++ b/main.tf @@ -7,7 +7,7 @@ resource "random_id" "salt" { } resource "aws_elasticache_replication_group" "redis" { - replication_group_id = replace(format("%.20s", "${var.name}-${var.env}"), "-$", "") + replication_group_id = replace(format("%.20s", "${var.name}-${var.env}"), "\-$\", "") replication_group_description = "Terraform-managed ElastiCache replication group for ${var.name}-${var.env}" number_cache_clusters = var.redis_clusters node_type = var.redis_node_type From b48eec496e9e12f5573818d382654f44549e368c Mon Sep 17 00:00:00 2001 From: torz Date: Mon, 14 Oct 2019 15:11:57 +0100 Subject: [PATCH 13/17] wrong slashes --- main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.tf b/main.tf index 3456f99..ee581ad 100644 --- a/main.tf +++ b/main.tf @@ -7,7 +7,7 @@ resource "random_id" "salt" { } resource "aws_elasticache_replication_group" "redis" { - replication_group_id = replace(format("%.20s", "${var.name}-${var.env}"), "\-$\", "") + replication_group_id = replace(format("%.20s", "${var.name}-${var.env}"), "/-$/", "") replication_group_description = "Terraform-managed ElastiCache replication group for ${var.name}-${var.env}" number_cache_clusters = var.redis_clusters node_type = var.redis_node_type From 534bd81f2649e60d0f5ed4069497577f5ef16a2f Mon Sep 17 00:00:00 2001 From: Jignesh Shah <36189390+rspljignesh@users.noreply.github.com> Date: Thu, 21 Dec 2023 12:32:19 +0530 Subject: [PATCH 14/17] Changed deprecated parameters to support latest AWS provide --- main.tf | 6 ++++-- variables.tf | 5 +++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/main.tf b/main.tf index ee581ad..26208c6 100644 --- a/main.tf +++ b/main.tf @@ -8,8 +8,8 @@ resource "random_id" "salt" { resource "aws_elasticache_replication_group" "redis" { replication_group_id = replace(format("%.20s", "${var.name}-${var.env}"), "/-$/", "") - replication_group_description = "Terraform-managed ElastiCache replication group for ${var.name}-${var.env}" - number_cache_clusters = var.redis_clusters + description = "Terraform-managed ElastiCache replication group for ${var.name}-${var.env}" + num_cache_clusters = var.redis_clusters node_type = var.redis_node_type automatic_failover_enabled = var.redis_failover engine_version = var.redis_version @@ -21,6 +21,8 @@ resource "aws_elasticache_replication_group" "redis" { maintenance_window = var.redis_maintenance_window snapshot_window = var.redis_snapshot_window snapshot_retention_limit = var.redis_snapshot_retention_limit + security_group_names = [] # This is needed to fix bug in AWS provider 5.30.0 - see https://github.com/hashicorp/terraform-provider-aws/issues/32835 + preferred_cache_cluster_azs = var.availability_zones tags = merge( { "Name" = format( diff --git a/variables.tf b/variables.tf index 541b993..5f23b4b 100644 --- a/variables.tf +++ b/variables.tf @@ -97,3 +97,8 @@ variable "tags" { default = {} } +variable "availability_zones" { + description = "A list of EC2 availability zones in which the replication group's cache clusters will be created. The order of the availability zones in the list is not important" + type = list(string) + default = [] +} \ No newline at end of file From 58a101d080e7deffa92a1d8de1e43297c374aec0 Mon Sep 17 00:00:00 2001 From: parthrspl Date: Thu, 25 Jan 2024 06:50:41 +0000 Subject: [PATCH 15/17] Updated code to accomodate dynamic block change --- outputs.tf | 4 ++-- variables.tf | 15 ++++++++++++--- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/outputs.tf b/outputs.tf index 8ccbbd4..462e67b 100644 --- a/outputs.tf +++ b/outputs.tf @@ -19,6 +19,6 @@ output "port" { } output "endpoint" { - value = aws_elasticache_replication_group.redis.primary_endpoint_address + value = var.cluster_mode_enabled ? join("", compact(aws_elasticache_replication_group.redis[*].configuration_endpoint_address)) : join("", compact(aws_elasticache_replication_group.redis[*].primary_endpoint_address)) + description = "Redis primary or configuration endpoint, whichever is appropriate for the given cluster mode" } - diff --git a/variables.tf b/variables.tf index 5f23b4b..af38037 100644 --- a/variables.tf +++ b/variables.tf @@ -72,9 +72,12 @@ variable "vpc_id" { } variable "redis_parameters" { - type = list(string) - description = "additional parameters modifyed in parameter group" - default = [] + description = "additional parameters modified in parameter group" + type = list(object({ + name = string + value= string + })) + default = [] } variable "redis_maintenance_window" { @@ -101,4 +104,10 @@ variable "availability_zones" { description = "A list of EC2 availability zones in which the replication group's cache clusters will be created. The order of the availability zones in the list is not important" type = list(string) default = [] +} + +variable "cluster_mode_enabled" { + type = bool + description = "Flag to enable/disable creation of a native redis cluster. `automatic_failover_enabled` must be set to `true`. Only 1 `cluster_mode` block is allowed" + default = false } \ No newline at end of file From 27f6f93379e5cf391d559d722f4554e3bc3d93a9 Mon Sep 17 00:00:00 2001 From: Jignesh Shah <36189390+rspljignesh@users.noreply.github.com> Date: Tue, 17 Dec 2024 11:01:17 +0530 Subject: [PATCH 16/17] Fixed Redis 7 Parameter group selection issue --- main.tf | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/main.tf b/main.tf index 26208c6..d2e8391 100644 --- a/main.tf +++ b/main.tf @@ -1,3 +1,7 @@ +locals { + parameter_group_family = substr(var.redis_version, 0,1) < 6 ? "redis${replace(var.redis_version, "/\\.[\\d]+$/", "")}": (substr(var.redis_version, 0,1) == "6" ? "redis${substr(var.redis_version, 0,1)}.x": "redis${substr(var.redis_version, 0,1)}") +} + data "aws_vpc" "vpc" { id = var.vpc_id } @@ -43,7 +47,7 @@ resource "aws_elasticache_parameter_group" "redis_parameter_group" { description = "Terraform-managed ElastiCache parameter group for ${var.name}-${var.env}" # Strip the patch version from redis_version var - family = "redis${replace(var.redis_version, "/\\.[\\d]+$/", "")}" + family = local.parameter_group_family dynamic "parameter" { for_each = var.redis_parameters content { From 5d9ec35899573e4c81b1ff3c4e5febf6cd5c9cc4 Mon Sep 17 00:00:00 2001 From: Jignesh Shah <36189390+rspljignesh@users.noreply.github.com> Date: Tue, 17 Dec 2024 16:52:15 +0530 Subject: [PATCH 17/17] Added info for change --- main.tf | 3 +++ 1 file changed, 3 insertions(+) diff --git a/main.tf b/main.tf index d2e8391..68d5521 100644 --- a/main.tf +++ b/main.tf @@ -1,3 +1,6 @@ +# Added support for Redis 7. You need to use redis_version value as below for different version +# Redis < 6.x, need to enter redis_version value like 3.2.1 Means Major.Minor.patch +# Redis >= 6.x need to enter redis_version value like 6.x Means Major.x locals { parameter_group_family = substr(var.redis_version, 0,1) < 6 ? "redis${replace(var.redis_version, "/\\.[\\d]+$/", "")}": (substr(var.redis_version, 0,1) == "6" ? "redis${substr(var.redis_version, 0,1)}.x": "redis${substr(var.redis_version, 0,1)}") }