5 Commits

Author SHA1 Message Date
autero1
24cb0ec259 Merge pull request #32 from gruntwork-io/module_dependencies
Standardizing dependencies to a list input
2019-05-04 09:03:41 +03:00
Petri Autero
2d11fdcf21 Revert back to local-exec 2019-05-03 11:50:42 +03:00
Riley Karson
7367df3e1e Update README to match Network module, add root example. (#31)
Update README to match Network module, add root example.
2019-05-02 09:05:25 -07:00
Petri Autero
efe37a1e64 Try to fix test failures 2019-05-02 14:22:52 +03:00
Petri Autero
6312a707c7 Standardizing to a list input 2019-05-02 10:34:20 +03:00
4 changed files with 25 additions and 10 deletions

View File

@@ -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

View File

@@ -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"

View File

@@ -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)}"
}
}

View File

@@ -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 = []
}