Skip to content

Commit badb311

Browse files
authored
Bugfixes (#136)
* Fix #134 use only existing security groups * Fix #135, default zone ID
1 parent 42cf8d1 commit badb311

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

main.tf

+5-4
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ module "aws_security_group" {
3434
source = "cloudposse/security-group/aws"
3535
version = "0.4.2"
3636

37+
enabled = local.create_security_group
38+
3739
allow_all_egress = local.allow_all_egress
3840
security_group_name = var.security_group_name
3941
rules_map = local.sg_rules
@@ -61,7 +63,6 @@ module "aws_security_group" {
6163
security_group_delete_timeout = var.security_group_delete_timeout
6264

6365

64-
enabled = local.enabled && local.create_security_group
6566
context = module.this.context
6667
}
6768

@@ -114,10 +115,10 @@ resource "aws_elasticache_replication_group" "default" {
114115
automatic_failover_enabled = var.automatic_failover_enabled
115116
multi_az_enabled = var.multi_az_enabled
116117
subnet_group_name = local.elasticache_subnet_group_name
117-
# It would be nice to remove duplicate security group IDs, if there are any, using `compact`,
118+
# It would be nice to remove null or duplicate security group IDs, if there are any, using `compact`,
118119
# but that causes problems, and having duplicates does not seem to cause problems.
119120
# See https://github.com/hashicorp/terraform/issues/29799
120-
security_group_ids = concat(local.associated_security_group_ids, [module.aws_security_group.id])
121+
security_group_ids = local.create_security_group ? concat(local.associated_security_group_ids, [module.aws_security_group.id]) : local.associated_security_group_ids
121122
maintenance_window = var.maintenance_window
122123
notification_topic_arn = var.notification_topic_arn
123124
engine_version = var.engine_version
@@ -196,7 +197,7 @@ module "dns" {
196197
enabled = module.this.enabled && length(var.zone_id) > 0 ? true : false
197198
dns_name = var.dns_subdomain != "" ? var.dns_subdomain : module.this.id
198199
ttl = 60
199-
zone_id = try(var.zone_id[0], var.zone_id)
200+
zone_id = try(var.zone_id[0], tostring(var.zone_id), "")
200201
records = var.cluster_mode_enabled ? [join("", aws_elasticache_replication_group.default.*.configuration_endpoint_address)] : [join("", aws_elasticache_replication_group.default.*.primary_endpoint_address)]
201202

202203
context = module.this.context

security_group_inputs.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ variable "create_security_group" {
99
}
1010

1111
locals {
12-
create_security_group = var.use_existing_security_groups == null ? var.create_security_group : !var.use_existing_security_groups
12+
create_security_group = local.enabled && (var.use_existing_security_groups == null ? var.create_security_group : !var.use_existing_security_groups)
1313
}
1414

1515
variable "associated_security_group_ids" {

0 commit comments

Comments
 (0)