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

command: Add remote state capability to output subcommand #6665

Closed

Conversation

vancluever
Copy link
Contributor

@vancluever vancluever commented May 13, 2016

UPDATE: Moved to terraform remote output - see comments.

This patch provides the ability to view separate remote state via the terraform output sub-command.

Some use cases:

  • You need output variables out-of-band from Terraform, ie: you want to pull the outputs without needing the whole repo or config, or having to run terraform remote config first.
  • You want to use terraform_remote_state, but you need to provide the outputs to variables/parameters that ultimately influence resource counts (my use case). In this instance, you can use this to view the outputs of a separate remote state without affecting your current locally configured remote state.

Command-line usage is similar to terraform remote config, but with some changes to make things semantic for the specific use context.

Also, I've updated the docs and the help a little bit for the -module flag, which only works when you are specifying a certain output to display, due to the fact that command.outputsAsString() only acts on the root module.

I was going to make this a separate project (https://github.com/paybyphone/terraform-remote-env) but that kind of seemed silly. ;)

@vancluever vancluever force-pushed the paybyphone_remote_output branch 3 times, most recently from ef2a077 to ee8bd6e Compare May 13, 2016 18:50
@apparentlymart
Copy link
Contributor

Interesting idea! (Of course, your second use-case should be eliminated by being able to interpolate data resource attributes into count, but still!)

I wonder if this would be more intuitive as a separate command terraform remote output... currently all of the remote-related stuff lives under that prefix, and then it could have exactly the same argument names as terraform remote config and not have confusing conflicts between arguments (-state vs. -remote=true).

Don't feel that strongly about it, though. What do you think?

@vancluever
Copy link
Contributor Author

@apparentlymart, thanks! Yeah this idea mainly came up as a stop-gap idea for me while #4169 is fully hashed out, but I figured there might be value for remote state being readable from Terraform for out-of-band tasks as well.

I was torn too on where exactly in the command tree to put this, but settled on output because it currently seems that remote is more oriented around managing/configuring remote state. One thing that I do see now again after reviewing and mulling it is that a lot of the logic for fetching and display the outputs seems to be hardcoded within the command.OutputCommand.Run() function. Mind you, we could probably move some of that logic to some common functions and just use that.

Let me see what I can do here. :)

@vancluever vancluever changed the title command: Add remote state capability to output subcommand [WIP] command: Add remote state capability to output subcommand May 13, 2016
@vancluever vancluever force-pushed the paybyphone_remote_output branch 3 times, most recently from 1af38bb to 7d60d46 Compare May 16, 2016 19:15
@vancluever
Copy link
Contributor Author

Alright, this is now done. The functionality has been moved to remote output, and the options changed so that they completely reflect that of remote config, with the appropriate bits from the plain output command added in.

In this process I also did a bit of a re-factoring on the output command's functionality so that it could be re-used with remote output, and I fixed it so that all outputs could be dumped when -module is specified, versus the old behaviour of just silently dumping the outputs for the root module.

@vancluever vancluever changed the title [WIP] command: Add remote state capability to output subcommand command: Add remote state capability to output subcommand May 16, 2016
@vancluever vancluever force-pushed the paybyphone_remote_output branch 2 times, most recently from 5a68a97 to ea0ea41 Compare June 15, 2016 19:59
Add the ability to get *separate* remote state via the
"terraform remote output" subcommand. Syntax follows
"terraform remote config", with a couple of additions.

This allows the ability to extract remote state from Terraform in
places were remote state may not be present, without having to
pre-configure remote state.

Also, as part of this work, there has been a re-factoring of the
outputsAsString function to allow both "terraform output" and
"terraform remote output" to print all outputs, even when an optional
module is supplied.
@vancluever
Copy link
Contributor Author

Just a FYI I'm about to close this. There has been some changes and divergences to the way that outputs are handled it looks like (work that @jen20 has been doing to ensure that list and map outputs are properly formatted and handled) which has added some complexity to keeping this up to date. Further to that, I have found that I can replace a good chunk of this functionality with a simple jq filter on the remote state's JSON, so the usefulness of having this sub-command has significantly diminished for me.

@vancluever vancluever closed this Sep 1, 2016
@ghost
Copy link

ghost commented Apr 22, 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 Apr 22, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants