diff --git a/main.tf b/main.tf index 7d9f44b..d8f6c6b 100644 --- a/main.tf +++ b/main.tf @@ -19,6 +19,7 @@ module "labels" { # Module : Elasticache Subnet Group # Description : Terraform module which creates Subnet Group for Elasticache. resource "aws_elasticache_subnet_group" "default" { + count = var.enable ? 1 : 0 name = module.labels.id subnet_ids = var.subnet_ids description = "Managed by Clouddrove" @@ -27,7 +28,7 @@ resource "aws_elasticache_subnet_group" "default" { # Module : Elasticache Replication Group # Description : Terraform module which creates standalone instance for Elasticache Redis. resource "aws_elasticache_replication_group" "default" { - count = var.replication_enabled ? 1 : 0 + count = var.enable && var.replication_enabled ? 1 : 0 engine = var.engine replication_group_id = module.labels.id replication_group_description = module.labels.id @@ -36,7 +37,7 @@ resource "aws_elasticache_replication_group" "default" { parameter_group_name = "default.redis5.0" node_type = var.node_type automatic_failover_enabled = var.automatic_failover_enabled - subnet_group_name = aws_elasticache_subnet_group.default.name + subnet_group_name = join("", aws_elasticache_subnet_group.default.*.name) security_group_ids = var.security_group_ids security_group_names = var.security_group_names snapshot_arns = var.snapshot_arns @@ -58,7 +59,7 @@ resource "aws_elasticache_replication_group" "default" { # Module : Elasticache Replication Group # Description : Terraform module which creates cluster for Elasticache Redis. resource "aws_elasticache_replication_group" "cluster" { - count = var.cluster_replication_enabled ? 1 : 0 + count = var.enable && var.cluster_replication_enabled ? 1 : 0 engine = var.engine replication_group_id = module.labels.id replication_group_description = module.labels.id @@ -67,7 +68,7 @@ resource "aws_elasticache_replication_group" "cluster" { parameter_group_name = "default.redis5.0.cluster.on" node_type = var.node_type automatic_failover_enabled = var.automatic_failover_enabled - subnet_group_name = aws_elasticache_subnet_group.default.name + subnet_group_name = join("", aws_elasticache_subnet_group.default.*.name) security_group_ids = var.security_group_ids security_group_names = var.security_group_names snapshot_arns = var.snapshot_arns @@ -92,7 +93,7 @@ resource "aws_elasticache_replication_group" "cluster" { # Module : Elasticache Cluster # Description : Terraform module which creates cluster for Elasticache Memcached. resource "aws_elasticache_cluster" "default" { - count = var.cluster_enabled ? 1 : 0 + count = var.enable && var.cluster_enabled ? 1 : 0 engine = var.engine cluster_id = module.labels.id engine_version = var.engine_version @@ -101,7 +102,7 @@ resource "aws_elasticache_cluster" "default" { az_mode = var.az_mode parameter_group_name = "default.memcached1.5" node_type = var.node_type - subnet_group_name = aws_elasticache_subnet_group.default.name + subnet_group_name = join("", aws_elasticache_subnet_group.default.*.name) security_group_ids = var.security_group_ids security_group_names = var.security_group_names snapshot_arns = var.snapshot_arns diff --git a/outputs.tf b/outputs.tf index b411558..91b8306 100644 --- a/outputs.tf +++ b/outputs.tf @@ -5,11 +5,6 @@ output "id" { description = "Redis cluster id." } -//output "cache_nodes" { -//value = var.cluster_enabled ? "" : aws_elasticache_replication_group.default.*.cache_nodes -//description = "Redis cluster id." -//} - output "port" { value = var.port description = "Redis port." diff --git a/variables.tf b/variables.tf index f9472ca..a4e02f6 100644 --- a/variables.tf +++ b/variables.tf @@ -36,6 +36,13 @@ variable "tags" { description = "Additional tags (e.g. map(`BusinessUnit`,`XYZ`)." } +variable "enable" { + type = bool + default = true + description = "Enable or disable of elasticache" +} + + # Module : Replication Group # Description : Terraform Replication group module variables. variable "engine" {