Terraform: Unable to create dependency in module to another module or resource

Created on 6 Mar 2017  ยท  9Comments  ยท  Source: hashicorp/terraform

Hi there,

Terraform Version

0.8.7

Affected Resource(s)

terraform modules

I created a module for aws vpc

Am unable to create a depends_on on the module

Terraform doesn't support depends_on in the module

Expected Behavior

What should have happened?
The depends_oon supports only in resources currently

Actual Behavior

What actually happened?
if we use that in module it fails saying depends_on not a valid command

Steps to Reproduce

core enhancement

Most helpful comment

If I understand it, you have two modules: module1 and module2 and module2 depend on module1.

To make sure that module2 isn't built first, "import" a value from module1:

module "module1" {
    source = "./module1"
}

module "module2" {
    source = "./module2"
    samevar = "${module.module1.somevar}"
}

Then "export" (i.e., "output") that from module1:

./module1/outputs.tf

output "somevar" {
  value = "nothing"
}

and "import" it into module2:

./module2/variables.tf

variable "somevar" {}

All 9 comments

If I understand it, you have two modules: module1 and module2 and module2 depend on module1.

To make sure that module2 isn't built first, "import" a value from module1:

module "module1" {
    source = "./module1"
}

module "module2" {
    source = "./module2"
    samevar = "${module.module1.somevar}"
}

Then "export" (i.e., "output") that from module1:

./module1/outputs.tf

output "somevar" {
  value = "nothing"
}

and "import" it into module2:

./module2/variables.tf

variable "somevar" {}

Hi Frans

Thanks for your reply, I saw your reply and i can understand that you are asking me to pass the output from module1 as input to module2. If i do this am not sure it will wait for module 1 creation like depends_on works

It should. Because if the export from module1 is a variable in turn, like

output "somevar" {
  value = "${some.thing.value}"
}

then module1 needs to be finished first, so that that variable will be known. It _might_ not work if you're exporting a static, but it should if you export a variable..

Try it and see if that helps.

Hi FransUrbo

Thanks for your help in this, I will try this and let you know. Sorry for the late response

Madhu

Should this be closed in favor of #10462?

+1

Indeed @ketzacoatl, this does seem to be the same as what's being discussed in #10462, so I'm going to close this one as a duplicate. Thanks for pointing that out!

If I understand it, you have two modules: module1 and module2 and module2 depend on module1.

To make sure that module2 isn't built first, "import" a value from module1:

module "module1" {
    source = "./module1"
}

module "module2" {
    source = "./module2"
    samevar = "${module.module1.somevar}"
}

Then "export" (i.e., "output") that from module1:

./module1/outputs.tf

output "somevar" {
  value = "nothing"
}

and "import" it into module2:

./module2/variables.tf

variable "somevar" {}

In line 7 of the code example is "samevar" supposed to be "somevar"? I tried this solution, but I found resources in module2 that weren't dependent on anything still did not wait for the completion of module1 before starting. Does this workaround actually work?

I'm going to lock this issue because it has been closed for _30 days_ โณ. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

Was this page helpful?
0 / 5 - 0 ratings