Skip to content

Commit 880cbb9

Browse files
authored
fix: add count guard to random suffix resource (#30)
1 parent 2ec666a commit 880cbb9

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

main.tf

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,17 @@ resource "aws_neptune_cluster_instance" "read_replicas" {
116116
resource "aws_neptune_cluster_snapshot" "this" {
117117
count = var.create_neptune_cluster_snapshot ? 1 : 0
118118

119-
db_cluster_identifier = try(aws_neptune_cluster.this[0].id, var.db_cluster_identifier)
119+
db_cluster_identifier = (var.create_neptune_cluster
120+
? aws_neptune_cluster.this[0].id
121+
: var.db_cluster_identifier
122+
)
123+
120124
db_cluster_snapshot_identifier = coalesce(
121125
var.db_cluster_snapshot_identifier,
122-
format("%s-%s", aws_neptune_cluster.this[0].id, random_id.snapshot_suffix.hex)
126+
format("%s-%s",
127+
aws_neptune_cluster.this[0].id,
128+
random_id.snapshot_suffix[0].hex
129+
)
123130
)
124131

125132
dynamic "timeouts" {
@@ -308,6 +315,8 @@ resource "aws_iam_role_policy_attachment" "this" {
308315
######################
309316

310317
resource "random_id" "snapshot_suffix" {
318+
count = var.create_neptune_cluster_snapshot && var.create_neptune_cluster ? 1 : 0
319+
311320
keepers = {
312321
cluster_identifier = aws_neptune_cluster.this[0].id
313322
}

0 commit comments

Comments
 (0)