Skip to content

Instantly share code, notes, and snippets.

@jpedro
Forked from josh-padnick/tf-bar.tf
Created December 15, 2021 17:55
Show Gist options
  • Select an option

  • Save jpedro/a89f1941279c95546adcde884fc88a72 to your computer and use it in GitHub Desktop.

Select an option

Save jpedro/a89f1941279c95546adcde884fc88a72 to your computer and use it in GitHub Desktop.
Hack for Terraform Module depends_on
# This file would need to be in its own folder like /tf-bar/main.tf
variable "bar" {
default = "foo"
}
resource "null_resource" "bar" {
triggers {
bar = "${var.bar}"
}
provisioner "local-exec" {
command = "echo 'tf-2.bar sleeping for 5 seconds' && sleep 5"
}
}
output "bar" {
value = "${null_resource.bar.triggers.bar}"
}
# This file would need to be in its own folder like /tf-foo/main.tf
variable "foo" {
default = "foo"
}
resource "null_resource" "foo" {
triggers {
foo = "${var.foo}"
}
provisioner "local-exec" {
command = "echo 'tf-1.foo sleeping for 2 seconds' && sleep 2"
}
}
variable "foo2" {
default = "foo"
}
resource "null_resource" "foo2" {
triggers {
foo2 = "${var.foo2}"
}
provisioner "local-exec" {
command = "echo 'tf-1.foo2 sleeping for 5 seconds' && sleep 5"
}
}
# You must list all resources in the module here, or a resource that depends on an unlisted resource will begin creating
# before the rest of the module's resources have been created.
output "foo" {
value = <<-EOF
${null_resource.foo.triggers.foo}
${null_resource.foo2.triggers.foo2}
EOF
}
# This file would need to be in its own folder like /tf-modules/main.tf
module "foo" {
source = "../tf-foo"
}
module "bar" {
source = "../tf-bar"
bar = "${module.foo.foo}"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment