Skip to content
This repository was archived by the owner on Mar 29, 2023. It is now read-only.

Commit 24cb0ec

Browse files
author
autero1
authored
Merge pull request #32 from gruntwork-io/module_dependencies
Standardizing dependencies to a list input
2 parents 7367df3 + 2d11fdc commit 24cb0ec

File tree

4 files changed

+25
-10
lines changed

4 files changed

+25
-10
lines changed

examples/mysql-private-ip/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ module "mysql" {
9292
private_network = "${google_compute_network.private_network.self_link}"
9393

9494
# Wait for the vpc connection to complete
95-
wait_for = "${google_service_networking_connection.private_vpc_connection.network}"
95+
dependencies = ["${google_service_networking_connection.private_vpc_connection.network}"]
9696

9797
# Set auto-increment flags to test the
9898
# feature during automated testing

examples/postgres-private-ip/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ module "postgres" {
9292
private_network = "${google_compute_network.private_network.self_link}"
9393

9494
# Wait for the vpc connection to complete
95-
wait_for = "${google_service_networking_connection.private_vpc_connection.network}"
95+
dependencies = ["${google_service_networking_connection.private_vpc_connection.network}"]
9696

9797
custom_labels = {
9898
test-id = "postgres-private-ip-example"

modules/cloud-sql/main.tf

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ locals {
3030
# ------------------------------------------------------------------------------
3131

3232
resource "google_sql_database_instance" "master" {
33-
depends_on = ["null_resource.wait_for"]
33+
depends_on = ["null_resource.dependency_getter"]
3434

3535
provider = "google-beta"
3636
name = "${var.name}"
@@ -111,11 +111,16 @@ resource "google_sql_user" "default" {
111111
}
112112

113113
# ------------------------------------------------------------------------------
114-
# CREATE A NULL RESOURCE TO EMULATE DEPENDENCIES
114+
# SET MODULE DEPENDENCY RESOURCE
115+
# This works around a terraform limitation where we can not specify module dependencies natively.
116+
# See https://github.com/hashicorp/terraform/issues/1178 for more discussion.
117+
# By resolving and computing the dependencies list, we are able to make all the resources in this module depend on the
118+
# resources backing the values in the dependencies list.
115119
# ------------------------------------------------------------------------------
116-
resource "null_resource" "wait_for" {
117-
triggers = {
118-
instance = "${var.wait_for}"
120+
121+
resource "null_resource" "dependency_getter" {
122+
provisioner "local-exec" {
123+
command = "echo ${length(var.dependencies)}"
119124
}
120125
}
121126

modules/cloud-sql/variables.tf

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,17 @@ variable "resource_timeout" {
208208
default = "60m"
209209
}
210210

211-
variable "wait_for" {
212-
description = "By passing a value to this variable, you can effectively tell this module to wait to deploy until the given variable's value is resolved, which is a way to require that this module depend on some other module. Note that the actual value of this variable doesn't matter."
213-
default = ""
211+
# ---------------------------------------------------------------------------------------------------------------------
212+
# MODULE DEPENDENCIES
213+
# Workaround Terraform limitation where there is no module depends_on.
214+
# See https://github.com/hashicorp/terraform/issues/1178 for more details.
215+
# This can be used to make sure the module resources are created after other bootstrapping resources have been created.
216+
# For example:
217+
# dependencies = ["${google_service_networking_connection.private_vpc_connection.network}"]
218+
# ---------------------------------------------------------------------------------------------------------------------
219+
220+
variable "dependencies" {
221+
description = "Create a dependency between the resources in this module to the interpolated values in this list (and thus the source resources). In other words, the resources in this module will now depend on the resources backing the values in this list such that those resources need to be created before the resources in this module, and the resources in this module need to be destroyed before the resources in the list."
222+
type = "list"
223+
default = []
214224
}

0 commit comments

Comments
 (0)