Terraform: -target does not source child modules

Created on 18 Feb 2016  ยท  14Comments  ยท  Source: hashicorp/terraform

We recently ran into an this issue as discussed in https://github.com/hashicorp/terraform/pull/1820#issuecomment-181475499 by @apparentlymart

... Nested modules don't target in the way I initially expected.

Given the following module tree:

  • root

    • foo

    • bar

    • baz

I initially expected that targeting module.foo would target all of the resources in bar and baz, but it appears that in fact it targets only the resources directly in foo. In my case there was actually nothing in foo except the declarations of bar and baz, so the -target plan appeared to do nothing, just like what is seen in the other examples above.

I suspect that this is at least what's going on for @maxenglander, since his dc0 module seems to have various sub-modules within.

The workaround for me was to target bar and baz explicitly by writing out their full names. This was easy (if annoying) in my case because I had relatively few nested modules, but it'd be more intuitive/consistent if targeting a module would also implicitly target all of its descendant modules, thus working on an entire sub-tree of the module hierarchy.

bug core

Most helpful comment

Thanks for filing this as a separate issue @Mongey - those long-tail threads have valuable details in them that can get lost in the cracks sometimes. :+1:

Agreed that the behavior should definitely be that targeting a module implicitly targets its sub-modules. Treating this as a POLA violation and therefore a bug.

All 14 comments

Thanks for filing this as a separate issue @Mongey - those long-tail threads have valuable details in them that can get lost in the cracks sometimes. :+1:

Agreed that the behavior should definitely be that targeting a module implicitly targets its sub-modules. Treating this as a POLA violation and therefore a bug.

Any updates on this issue? I can confirm it's present in v0.7.0.

@phinze, I am seeing this behavior for top-level modules as well as child-modules. Should I create a separate issue for the top-level modules escaping -target, or leave it all as one here?

Some progress here would be great! Having to script terraform to do this sort of thing is certainly an anti-pattern.

Bug still present in 0.8.7.

Any chance of getting the fix in #9236 reviewed/merged?

I've found a workaround in the meantime: by exporting at least one parameter from the affected resources from a lower-level module, and consuming it from the higher-level module, --target works as expected.

In my case I'm creating TXT records in private DNS of those garbage outputs, but your use case may vary.

@don-code true, but it only works for the resources that have been referenced from the higher level. All the non-referenced lower level resources are skipped in the plan/apply in my experience.

Bug still present in 0.9.4. According to #9236 this will "hopefully" be fixed in 0.10.

Yea, very dangerous bug, we got bitten too. Hope this bug will get some love from the terraform team soon :)

We just experienced this, too

15:21 $ terraform --version
Terraform v0.9.6

In case anyone missed it, looks like this is resolved in #15314, but it constitutes a breaking change so it won't be released until 0.10. So good news and bad news.

Does anyone know when 0.10 is expected to land?

Hey @camjackson we don't have a solid date set for the 0.10 release, but there are a couple beta releases and an RC release out if you wish to test this further!

Looks like this was fixed in #15314, closing.

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

Related issues

c4milo picture c4milo  ยท  3Comments

Seraf picture Seraf  ยท  3Comments

ronnix picture ronnix  ยท  3Comments

rkulagowski picture rkulagowski  ยท  3Comments

franklinwise picture franklinwise  ยท  3Comments