Terraform: Module Cannot be Used in depends_on

Created on 12 Jun 2018  ยท  17Comments  ยท  Source: hashicorp/terraform

Terraform Version

v0.11.7

Terraform Configuration Files

Note that the below Terraform configuration file leaves out the actual modules some-module and another-module for sake of readability.

module "first-this" {
  source = "modules/some-module"

  ...
}

module "then-that" {
  source = "modules/another-module"

  depends_on = ["module.first-this"]
  ...
}

resource "azurerm_resource_group" "some-rg" {
  name       = "some-name"
  location   = "West US"

  depends_on = ["module.first-this"]
}

Debug/Crash Output

Error: module "then-that": "depends_on" is not a valid argument

Error: azurerm_resource_group.some-rg: resource depends on non-existent resource 'first-this'

Expected Behavior

Ideally, depends_on for modules would work exactly as for resources, i.e., _create an explicit dependency between resources/modules and modules_.

Actual Behaviour

Terraform exits with above errors

Steps to Reproduce

  1. terraform init

References

A similar report can be found in

  • #10462

Most helpful comment

Wondering what's the official status of this in the soon to be released 0.12 ?
Do modules still not support depends_on ?

All 17 comments

Hi @dumrauf,

Yes, this is a duplicate of #10462. We'll track the progress of this feature there.

@jbardin - #10462 was locked back in March and no updates have been made since. Is this being actively worked on? If the issue is locked, how is the community supposed to build the enhancement?

Hi @gpjonesii,

I understand the concern, but in this case any solution would have to be produced in close concert with the core engineering team so as to not conflict with planned changes. This would happen independently from any single open issue here.

Contrary to what many of the comments suggest, it's not a simple problem, and requires many fundamental changes to be in place before a solution is possible. The foundation for this is in progress, and once that is complete we can proceed with adding this feature. You can read more about the details in issue #17101

Hi @jbardin,

I do understand that it takes time to plan and coordinate changes and I am perfectly fine with that.

However, not being able to use depends_on between modules impacts our Terraform modularisation strategy. There are certain workarounds available but they are essentially hacks which I would like to avoid.

Moreover, not being able to upvote issues like this one does not really help surface and prioritise customer problems in my opinion. I do get the point that you don't want to get spammed with '+1's and upvotes but to me that's what makes customer driven product development. You've got a great product - keep it up!

As for the upcoming changes you touched upon - is there an ETA available?

Thanks!

Hi @dumrauf,

While we don't have an ETA, a large portion of the necessary changes will land in the next major release (0.12). The final roadblock will be handled by #17034 (or something similar), but it's not clear yet if that will have to wait for a later release or not.

Has anyone come up with a viable workaround for this in the meantime?

The only viable workaround, which I've found to work, is to

  1. _output attributes of relevant resources_ created in the upstream module and
  2. _use the outputs as input variables_ in the downstream module/resource.

Here, the _catch_ is that you

  1. have to actually use the variables in the downstream module/resource or they will get "optimised" away
  2. need to get the dependencies between resources in the upstream and downstream module/resource right or you may end up with race conditions (this may may also depend on how modules are implemented under the bonnet which I have no insight into)

It's not the best solution in the world but it does the job for now until this issue gets resolved. Please let me know if anyone has a better solution!

@jbardin Any updates in the meantime? Would love to see that feature make it into the next release.

I've been successfully able to work around the missing explicit depends_on functionality between modules until a recent Terraform release. Unfortunately, using output/input variables between modules to ensure the correct behavior is nothing more than a gamble and the whole dependency graph has been completely unreliable since the very beginning.

I really hope this will be solved in the near future.

@pstadler, where's it exactly falling apart for you? I'm just wondering as the hackaround is working for us alright so far.

Is the dependency graph any different from what you would expect? Could it be that there are implicit race conditions due to the intrinsic parallel nature of Terraform. This has caught us out once or twice before.

In other news: There may be a glimpse of hope in a recent announcement regarding the upcoming Terraform 0.12 release on https://www.hashicorp.com/blog/terraform-0-1-2-preview. The article mentions depends_on but I couldn't find anything that says this problem would definitely get addressed.

Wondering what's the official status of this in the soon to be released 0.12 ?
Do modules still not support depends_on ?

Still no news about this? I'm using Terraform 0.12.1 and I have the same issues that I had before.

I'm also facing this issue - I have a module which creates a N copies of a complex set of Azure resources, keeping the creation of N resource groups outside of this module.

The first time the job runs, it errors, because the module requires the resource group, and there is no way for me to have this dependency since the resource group variable for the module is interpolated rather than a single data source.

Common guys, I'm waiting for this feature more than a year. This is a really major feature that needs to be implemented!

Just ran into this issue as well. So adding a vote for feature here

Please, solve it

still open issue , did not got proper resolution

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