Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Module depends_on #25005

Merged
merged 4 commits into from
May 29, 2020
Merged

Module depends_on #25005

merged 4 commits into from
May 29, 2020

Conversation

jbardin
Copy link
Member

@jbardin jbardin commented May 20, 2020

Allow the use of depends_on for modules.

This PR stands on the existing work already done for module expansion, evaluation, and data source planning. See #24461, #24697, and #24904 for the majority of the work involved in making that happen.

Now that modules can be ordered and referenced as a whole, and data sources will cleanly allow forced ordering by depends_on; all that is left is to enable the feature in the config and add the graph connections for the depends_on references.

Closes #10462
Closes #17101

jbardin added 3 commits May 20, 2020 13:46
Connect references from depends_on in modules calls. This will "just
work" for a lot of cases, but data sources will be read too early in the
case where they require the dependencies to be created. While
data sources will be properly ordered behind the module head node, there
is nothing preventing them from being being evaluated during refresh.
verify a chain of depends_on references through modules execute in the
correct order
@jbardin jbardin requested a review from a team May 20, 2020 19:01
@codecov
Copy link

codecov bot commented May 20, 2020

Codecov Report

Merging #25005 into master will decrease coverage by 0.00%.
The diff coverage is 70.00%.

Impacted Files Coverage Δ
configs/module_call.go 67.56% <ø> (-2.44%) ⬇️
terraform/node_module_expand.go 87.50% <70.00%> (-1.79%) ⬇️
terraform/node_resource_plan.go 91.80% <0.00%> (-1.64%) ⬇️
terraform/evaluate.go 53.60% <0.00%> (+0.90%) ⬆️

Comment on lines +11173 to +11174
// run the plan again to ensure that data sources are not going to be re-read
plan, diags := ctx.Plan()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I might be missing something obvious, but I don't understand this comment. Why does re-planning after apply ensure that the data source isn't re-read?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the data source is read during plan (which is a new ability from #24904), it would show in the plan as a read operation. There should be nothing left to apply at this point, so anything in the plan should be NoOp.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see now, thanks!

@danieldreier danieldreier added this to the v0.13.0 milestone May 21, 2020
Copy link
Contributor

@pselle pselle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm pulling this changeset down to put it through some paces on my machine, but in the meantime, looks like this doesn't include the docs if you want to add them here?

@apparentlymart
Copy link
Contributor

I've not delved deep into this yet because I don't have the necessary context loaded to think about the details, but I wanted to ask: could we make sure there's a test somewhere for the case where module depends_on isn't being used and one of a module's variables depends on its outputs? I'd like to make sure that isn't broken (and stays unbroken, for the time being) for situations where users aren't using any of these new features.

The sort of test case I have in mind would be...

root module:

module "test" {
  source = "./test"

  a = module.test.b
}

output "c" {
  value = module.test.c
}

The ./test module:

variable "a" {}

resource "test" "test" {
}

output "b" {
  value = test.test.id
}

output "c" {
  value = var.a
}

I would expect the above to work and for the root module output c to be whatever test.test.id is in the child module. Based on an initial read of this code I expect this should still work, because without depends_on set in the module block there should not be any additional dependency edges created that would make this be a cycle.

We have so many test fixtures in Terraform Core that I wouldn't be surprised if something like this was there somewhere already, but I'm not sure where it is if so. 😕

@jbardin
Copy link
Member Author

jbardin commented May 27, 2020

Good idea @apparentlymart! While I didn't expect that to be be effected by this PR, I want to make certain we have that test in the corpus.

Copy link
Contributor

@apparentlymart apparentlymart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having now had some extra time to familiarize myself with how the new "expand" nodes fit in with everything else 😄 this looks good to me! I did have a brief play with it to see how it looks and it matched what I was expecting, though I didn't have a deep play with it because @pselle already mentioned doing that. 😀

That this last change ended up being so straightforward and clear is, I think, a testament to all of the other refactoring work y'all have been doing these last few months. Good job! 🎉

Copy link
Contributor

@apparentlymart apparentlymart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🙄 I forgot to select "Approve" when I submitted that, though with that said I don't mean to override @pselle's comment about the docs. Hopefully it's a relatively straightforward docs update and so we could include that in here just to keep this change "atomic".

@jbardin
Copy link
Member Author

jbardin commented May 28, 2020

The docs change is minimal I think. I just have that in another PR since data sources also needed a depends_on update, and then Nick could also review the docs separately.

@jbardin jbardin merged commit 8ba6311 into master May 29, 2020
@jbardin jbardin deleted the jbardin/module-depends-on branch May 29, 2020 01:29
@ozbillwang
Copy link

I think this would be a big change (I mean a lot of codes need be updated), but not.

That's amazing, thanks a lot.

@feliperfmarques
Copy link

Thanks a lot for this feature. Looking forward to this release.

@ghost
Copy link

ghost commented Jun 28, 2020

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.

@ghost ghost locked and limited conversation to collaborators Jun 28, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Module-aware explicit dependencies depends_on cannot be used in a module
7 participants