Skip to content

Commit 9f2f0e7

Browse files
authored
Merge pull request #3 from clouddrove/CD-90
add bool option
2 parents f0e0845 + 3fdc09a commit 9f2f0e7

File tree

3 files changed

+14
-11
lines changed

3 files changed

+14
-11
lines changed

main.tf

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ module "labels" {
1919
# Module : Elasticache Subnet Group
2020
# Description : Terraform module which creates Subnet Group for Elasticache.
2121
resource "aws_elasticache_subnet_group" "default" {
22+
count = var.enable ? 1 : 0
2223
name = module.labels.id
2324
subnet_ids = var.subnet_ids
2425
description = "Managed by Clouddrove"
@@ -27,7 +28,7 @@ resource "aws_elasticache_subnet_group" "default" {
2728
# Module : Elasticache Replication Group
2829
# Description : Terraform module which creates standalone instance for Elasticache Redis.
2930
resource "aws_elasticache_replication_group" "default" {
30-
count = var.replication_enabled ? 1 : 0
31+
count = var.enable && var.replication_enabled ? 1 : 0
3132
engine = var.engine
3233
replication_group_id = module.labels.id
3334
replication_group_description = module.labels.id
@@ -36,7 +37,7 @@ resource "aws_elasticache_replication_group" "default" {
3637
parameter_group_name = "default.redis5.0"
3738
node_type = var.node_type
3839
automatic_failover_enabled = var.automatic_failover_enabled
39-
subnet_group_name = aws_elasticache_subnet_group.default.name
40+
subnet_group_name = join("", aws_elasticache_subnet_group.default.*.name)
4041
security_group_ids = var.security_group_ids
4142
security_group_names = var.security_group_names
4243
snapshot_arns = var.snapshot_arns
@@ -58,7 +59,7 @@ resource "aws_elasticache_replication_group" "default" {
5859
# Module : Elasticache Replication Group
5960
# Description : Terraform module which creates cluster for Elasticache Redis.
6061
resource "aws_elasticache_replication_group" "cluster" {
61-
count = var.cluster_replication_enabled ? 1 : 0
62+
count = var.enable && var.cluster_replication_enabled ? 1 : 0
6263
engine = var.engine
6364
replication_group_id = module.labels.id
6465
replication_group_description = module.labels.id
@@ -67,7 +68,7 @@ resource "aws_elasticache_replication_group" "cluster" {
6768
parameter_group_name = "default.redis5.0.cluster.on"
6869
node_type = var.node_type
6970
automatic_failover_enabled = var.automatic_failover_enabled
70-
subnet_group_name = aws_elasticache_subnet_group.default.name
71+
subnet_group_name = join("", aws_elasticache_subnet_group.default.*.name)
7172
security_group_ids = var.security_group_ids
7273
security_group_names = var.security_group_names
7374
snapshot_arns = var.snapshot_arns
@@ -92,7 +93,7 @@ resource "aws_elasticache_replication_group" "cluster" {
9293
# Module : Elasticache Cluster
9394
# Description : Terraform module which creates cluster for Elasticache Memcached.
9495
resource "aws_elasticache_cluster" "default" {
95-
count = var.cluster_enabled ? 1 : 0
96+
count = var.enable && var.cluster_enabled ? 1 : 0
9697
engine = var.engine
9798
cluster_id = module.labels.id
9899
engine_version = var.engine_version
@@ -101,7 +102,7 @@ resource "aws_elasticache_cluster" "default" {
101102
az_mode = var.az_mode
102103
parameter_group_name = "default.memcached1.5"
103104
node_type = var.node_type
104-
subnet_group_name = aws_elasticache_subnet_group.default.name
105+
subnet_group_name = join("", aws_elasticache_subnet_group.default.*.name)
105106
security_group_ids = var.security_group_ids
106107
security_group_names = var.security_group_names
107108
snapshot_arns = var.snapshot_arns

outputs.tf

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,6 @@ output "id" {
55
description = "Redis cluster id."
66
}
77

8-
//output "cache_nodes" {
9-
//value = var.cluster_enabled ? "" : aws_elasticache_replication_group.default.*.cache_nodes
10-
//description = "Redis cluster id."
11-
//}
12-
138
output "port" {
149
value = var.port
1510
description = "Redis port."

variables.tf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@ variable "tags" {
3636
description = "Additional tags (e.g. map(`BusinessUnit`,`XYZ`)."
3737
}
3838

39+
variable "enable" {
40+
type = bool
41+
default = true
42+
description = "Enable or disable of elasticache"
43+
}
44+
45+
3946
# Module : Replication Group
4047
# Description : Terraform Replication group module variables.
4148
variable "engine" {

0 commit comments

Comments
 (0)