Merge pull request #32 from gruntwork-io/module_dependencies
Standardizing dependencies to a list input
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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}"
|
||||
@@ -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)}"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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 = []
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user