From 3cd7bbf68943d0bf8e507331fda9b40badea2ab4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paulo=20J=C3=BAnior=20do=20Nascimento=20Lima?= Date: Fri, 21 Jan 2022 08:48:52 -0300 Subject: [PATCH] Add elasticache in subnet group instead of creating a new --- main.tf | 3 ++- variables.tf | 7 +++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/main.tf b/main.tf index a2f056e..5881b98 100644 --- a/main.tf +++ b/main.tf @@ -6,7 +6,7 @@ resource "aws_elasticache_replication_group" "default" { engine = "redis" parameter_group_name = aws_elasticache_parameter_group.default.name - subnet_group_name = aws_elasticache_subnet_group.default.name + subnet_group_name = var.subnet_group_name == null ? aws_elasticache_subnet_group.default[0].name : var.subnet_group_name security_group_ids = [aws_security_group.default.id] # The replication group identifier. This parameter is stored as a lowercase string. @@ -104,6 +104,7 @@ resource "aws_elasticache_parameter_group" "default" { # https://www.terraform.io/docs/providers/aws/r/elasticache_subnet_group.html resource "aws_elasticache_subnet_group" "default" { + count = var.subnet_group_name == null ? 1 : 0 name = var.name subnet_ids = var.subnet_ids description = var.description diff --git a/variables.tf b/variables.tf index 5e5883b..5d2459f 100644 --- a/variables.tf +++ b/variables.tf @@ -16,11 +16,18 @@ variable "node_type" { variable "subnet_ids" { type = list(string) description = "List of VPC Subnet IDs for the cache subnet group." + default = [] } variable "vpc_id" { type = string description = "VPC Id to associate with Redis ElastiCache." + default = "" +} + +variable "subnet_group_name" { + type = string + description = "VPC Id to associate with Redis ElastiCache." } variable "source_cidr_blocks" {