Terraform: Show a module's outputs by default at the root level

Created on 22 Nov 2016  ยท  7Comments  ยท  Source: hashicorp/terraform

Our default TF structure is to define a module that defines the infrastructure we want to create with variables to be able to configure in different ways for different environment types. This allows us to easily share configuration between environments while keeping the state of those environments distinctly separate.

Example:

   main.tf
   outputs.tf
   variables.tf
production
   main.tf
dev
   main.tf

Where production/main.tf and dev/main.tf are trivial definitions that look something like this:

module "env" {
  source = "../environment_module"

  some_variable = "prod or dev version of this variable"
}

This has worked very well for us, but it does lead to some redundancies, namely when defining outputs. Really, the outputs we care about can all be defined in environment_module, however by default when running in production/ or dev/, terraform will only output the outputs of the root module. So we either need to get in the habit of running terraform output -module=env, or reiterate all the outputs in both production/ and dev/. We tend to do the latter so that terraform output works consistently everywhere, but it leads to a lot of redundant output definitions.

It would be very useful to have some way for terraform to do this automatically. One option would be to have a display_outputs option that would display that would tell terraform to always show that module's outputs:

module "env" {
  source = "../environment_module"
  display_outputs = true

  some_variable = "prod or dev version of this variable"
}

or perhaps its more of a propagate_outputs option that pulls up that module's outputs into the calling module's outputs. They could then be treated as any other outputs.

config enhancement

Most helpful comment

I've been interested in _something_ along these lines, maybe not _exactly_ what you outlined here but close...

I think we do need some syntax somehow to "propogate" -- as you said -- the outputs through. This is useful in situations like this where you proxy a module, effectively.

All 7 comments

I've been interested in _something_ along these lines, maybe not _exactly_ what you outlined here but close...

I think we do need some syntax somehow to "propogate" -- as you said -- the outputs through. This is useful in situations like this where you proxy a module, effectively.

Along a similar vein #8554

+1 for "export outputs upward" option on modules. Perhaps with a prefix or something.

+1 for output the outputs

+1

Hi all!

This seems to be the same thing being discussed over in #16397. Although this one is older, there's some more discussion on that one and so I'm going to close this one just to consolidate the discussion over there.

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

rnowosielski picture rnowosielski  ยท  3Comments

jrnt30 picture jrnt30  ยท  3Comments

rjinski picture rjinski  ยท  3Comments

franklinwise picture franklinwise  ยท  3Comments

rkulagowski picture rkulagowski  ยท  3Comments