Skip to content

Commit

Permalink
Merge pull request #7 from akae/master
Browse files Browse the repository at this point in the history
[SREFTP-4698] [BUGFIX] - Fix trimming of name resulting in a trailing hyphen
  • Loading branch information
vicendominguez authored Apr 2, 2024
2 parents 60c77ae + fff7bc6 commit 6aae082
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ data "aws_vpc" "vpc" {

locals {
vpc_name = lookup(data.aws_vpc.vpc.tags, "Name", var.vpc_id)
trimmed_name_env = format("%.20s", "${var.name}-${var.env}") # trim name-env to 20 char
name_env = replace(local.trimmed_name_env, "/-+$/", "") # remove trailing hyphens
major_redis_version = parseint(substr(var.redis_version, 0, 1), 10)
parameter_group_family = local.major_redis_version < 6 ? "redis${replace(var.redis_version, "/\\.[\\d]+$/", "")}" : local.major_redis_version == 6 ? "redis${replace(var.redis_version, "/\\.[\\d|x]+$/", "")}.x" : "redis${local.major_redis_version}"
}
Expand All @@ -16,7 +18,7 @@ resource "random_id" "salt" {
}

resource "aws_elasticache_replication_group" "redis" {
replication_group_id = format("%.20s", "${var.name}-${var.env}")
replication_group_id = local.name_env
description = "Terraform-managed ElastiCache replication group for ${var.name}-${var.env}-${local.vpc_name}"
num_cache_clusters = var.redis_clusters
node_type = var.redis_node_type
Expand Down

0 comments on commit 6aae082

Please sign in to comment.