Skip to content

Commit d9ba622

Browse files
committed
Ensure tf_dependency label is only set when required
On Postgres instances that are not passed the peering_completed ordering variable, there's no reason to set a label. This only sets the label (which is a necessary evil to ensure dependency ordering) in scenarios where it's required.
1 parent 934aaa1 commit d9ba622

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

modules/postgresql/main.tf

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,13 @@ locals {
2121
enabled = "${var.ip_configuration}"
2222
disabled = "${map()}"
2323
}
24+
25+
peering_completed_enabled = "${var.peering_completed != "" ? true : false}"
26+
27+
user_labels_including_tf_dependency = {
28+
enabled = "${merge(map("tf_dependency", var.peering_completed), var.user_labels)}"
29+
disabled = "${var.user_labels}"
30+
}
2431
}
2532

2633
resource "google_sql_database_instance" "default" {
@@ -46,9 +53,7 @@ resource "google_sql_database_instance" "default" {
4653
// Define a label to force a dependency to the creation of the network peering.
4754
// Substitute this with a module dependency once the module is migrated to
4855
// Terraform 0.12
49-
user_labels = "${merge(
50-
map("tf_dependency", var.peering_completed),
51-
var.user_labels)}"
56+
user_labels = "${local.user_labels_including_tf_dependency["${local.peering_completed_enabled ? "enabled" : "disabled"}"]}"
5257

5358
location_preference {
5459
zone = "${var.region}-${var.zone}"

0 commit comments

Comments
 (0)