Skip to content

Commit 26b3848

Browse files
Allow null subnets for Replicas (#142)
* update to allow null value for replicas * Auto Format Co-authored-by: cloudpossebot <[email protected]>
1 parent 1f95684 commit 26b3848

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

.github/auto-release.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ version-resolver:
1717
- 'bugfix'
1818
- 'bug'
1919
- 'hotfix'
20-
- 'no-release'
2120
default: 'minor'
2221

2322
categories:

main.tf

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,14 @@ locals {
1111

1212
subnet_ids_provided = var.subnet_ids != null && length(var.subnet_ids) > 0
1313
db_subnet_group_name_provided = var.db_subnet_group_name != null && var.db_subnet_group_name != ""
14+
is_replica = try(length(var.replicate_source_db), 0) > 0
1415

16+
# Db Subnet group name should equal the name if provided
17+
# we then check if this is a replica, if it is, and no name is provided, this should be null, see https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/db_instance#db_subnet_group_name
18+
# finally, if no name is provided, and it is not a replica, we check if subnets were provided.
1519
db_subnet_group_name = local.db_subnet_group_name_provided ? var.db_subnet_group_name : (
16-
local.subnet_ids_provided ? join("", aws_db_subnet_group.default.*.name) : null
20+
local.is_replica ? null : (
21+
local.subnet_ids_provided ? join("", aws_db_subnet_group.default.*.name) : null)
1722
)
1823

1924
availability_zone = var.multi_az ? null : var.availability_zone
@@ -24,14 +29,14 @@ resource "aws_db_instance" "default" {
2429

2530
identifier = module.this.id
2631
db_name = var.database_name
27-
username = try(length(var.replicate_source_db), 0) == 0 ? var.database_user : null
28-
password = try(length(var.replicate_source_db), 0) == 0 ? var.database_password : null
32+
username = local.is_replica ? null : var.database_user
33+
password = local.is_replica ? null : var.database_password
2934
port = var.database_port
30-
engine = try(length(var.replicate_source_db), 0) == 0 ? var.engine : null
31-
engine_version = try(length(var.replicate_source_db), 0) == 0 ? var.engine_version : null
35+
engine = local.is_replica ? null : var.engine
36+
engine_version = local.is_replica ? null : var.engine_version
3237
character_set_name = var.charset_name
3338
instance_class = var.instance_class
34-
allocated_storage = try(length(var.replicate_source_db), 0) == 0 ? var.allocated_storage : null
39+
allocated_storage = local.is_replica ? null : var.allocated_storage
3540
max_allocated_storage = var.max_allocated_storage
3641
storage_encrypted = var.storage_encrypted
3742
kms_key_id = var.kms_key_arn

0 commit comments

Comments
 (0)