Skip to content
This repository was archived by the owner on Mar 29, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/mysql-private-ip/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ module "mysql" {
private_network = "${google_compute_network.private_network.self_link}"

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

# Set auto-increment flags to test the
# feature during automated testing
Expand Down
2 changes: 1 addition & 1 deletion examples/postgres-private-ip/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ module "postgres" {
private_network = "${google_compute_network.private_network.self_link}"

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

custom_labels = {
test-id = "postgres-private-ip-example"
Expand Down
15 changes: 10 additions & 5 deletions modules/cloud-sql/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ locals {
# ------------------------------------------------------------------------------

resource "google_sql_database_instance" "master" {
depends_on = ["null_resource.wait_for"]
depends_on = ["null_resource.dependency_getter"]

provider = "google-beta"
name = "${var.name}"
Expand Down Expand Up @@ -111,11 +111,16 @@ resource "google_sql_user" "default" {
}

# ------------------------------------------------------------------------------
# CREATE A NULL RESOURCE TO EMULATE DEPENDENCIES
# SET MODULE DEPENDENCY RESOURCE
# This works around a terraform limitation where we can not specify module dependencies natively.
# See https://github.com/hashicorp/terraform/issues/1178 for more discussion.
# By resolving and computing the dependencies list, we are able to make all the resources in this module depend on the
# resources backing the values in the dependencies list.
# ------------------------------------------------------------------------------
resource "null_resource" "wait_for" {
triggers = {
instance = "${var.wait_for}"

resource "null_resource" "dependency_getter" {
provisioner "local-exec" {
command = "echo ${length(var.dependencies)}"
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you run into issues with the triggers approach? Should I switch back to this method too?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ended up using the local-exec eventually. Switching back and forth was just trying to see if that made the tests more stable. Turned out it didn't make a difference - root cause was most likely just instability with the GCP APIs.

}

Expand Down
16 changes: 13 additions & 3 deletions modules/cloud-sql/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,17 @@ variable "resource_timeout" {
default = "60m"
}

variable "wait_for" {
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."
default = ""
# ---------------------------------------------------------------------------------------------------------------------
# MODULE DEPENDENCIES
# Workaround Terraform limitation where there is no module depends_on.
# See https://github.com/hashicorp/terraform/issues/1178 for more details.
# This can be used to make sure the module resources are created after other bootstrapping resources have been created.
# For example:
# dependencies = ["${google_service_networking_connection.private_vpc_connection.network}"]
# ---------------------------------------------------------------------------------------------------------------------

variable "dependencies" {
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."
type = "list"
default = []
}