Skip to content

Commit 2d9d4d9

Browse files
authored
fix: address invalid count bug (#118)
1 parent 3699e7f commit 2d9d4d9

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

main.tf

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
locals {
22
enabled = module.this.enabled
3-
create_password = local.enabled && length(var.master_password) == 0
3+
create_password = local.enabled && var.master_password == null
4+
5+
master_password = local.create_password ? one(random_password.password[*].result) : var.master_password
46
}
57

68
resource "aws_security_group" "default" {
@@ -56,7 +58,7 @@ resource "aws_security_group_rule" "ingress_cidr_blocks" {
5658
}
5759

5860
resource "random_password" "password" {
59-
count = local.enabled && local.create_password ? 1 : 0
61+
count = local.create_password ? 1 : 0
6062
length = 16
6163
special = false
6264
}
@@ -65,7 +67,7 @@ resource "aws_docdb_cluster" "default" {
6567
count = local.enabled ? 1 : 0
6668
cluster_identifier = module.this.id
6769
master_username = var.master_username
68-
master_password = var.master_password != "" ? var.master_password : random_password.password[0].result
70+
master_password = local.master_password
6971
backup_retention_period = var.retention_period
7072
preferred_backup_window = var.preferred_backup_window
7173
preferred_maintenance_window = var.preferred_maintenance_window
@@ -168,7 +170,7 @@ module "ssm_write_db_password" {
168170
parameter_write = [
169171
{
170172
name = format("%s%s", var.ssm_parameter_path_prefix, module.this.id)
171-
value = var.master_password != "" ? var.master_password : random_password.password[0].result
173+
value = local.master_password
172174
type = "SecureString"
173175
description = "Master password for ${module.this.id} DocumentDB cluster"
174176
}

variables.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ variable "master_username" {
9595

9696
variable "master_password" {
9797
type = string
98-
default = ""
98+
default = null
9999
description = "(Required unless a snapshot_identifier is provided) Password for the master DB user. Note that this may show up in logs, and it will be stored in the state file. Please refer to the DocumentDB Naming Constraints"
100100
}
101101

0 commit comments

Comments
 (0)