Skip to content
New issue

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

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

Already on GitHub? # to your account

command/console: support root module output #24060

Closed
wants to merge 1 commit into from

Conversation

mildwonkey
Copy link
Contributor

@mildwonkey mildwonkey commented Feb 7, 2020

The terraform console command was unable to print root module outputs, instead only supporting module output (which I suspect won't work in 0.12 at all, since only root module outputs are stored in state).

Addresses some of the concerns in 21516, but possibly not all - as implemented this still requires an initial apply, even if the value is hard-coded in the module.

From a MODIFIED example in this comment:

echo output.stuff | terraform console
{
  "house" = {
    "foo" = "bar"
  }
}

I had to add the output to the root module for the above to work:

output "stuff" {
  value = module.stuff
}

Note that (as currently implemented) this only works after an apply; the value must be in state. If it's intended/expected to work without apply there's more to be done, but I hope this is a sufficient first step.

This works too!

echo output.stuff.house | terraform console
{
  "foo" = "bar"
}

@ghost ghost added the sdkv1 [PRs only] Marks changes that may potentially need to be ported to the plugi nSDK label Feb 7, 2020
@mildwonkey mildwonkey requested a review from a team February 7, 2020 17:46
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.

From digging into outputs last week, I feel like this might not be the right direction (namely, making OutputValue referenceable, when it is noted to explicitly not be) to address this issue.

@@ -13,6 +13,7 @@ import (
// OutputValue is not Referenceable, while ModuleCallOutput is.
type OutputValue struct {
Name string
referenceable
Copy link
Contributor

Choose a reason for hiding this comment

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

// OutputValue is not Referenceable, while ModuleCallOutput is.

The comment right above this would be incorrect from this PR, and as well, I wonder about how this relates to this code's intention.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ah wonderful catch, thanks! The whole point is that it is now referenceable so MILDLY IMPORTANT that the comments match

@@ -128,6 +128,11 @@ func (d analysisData) GetModuleInstance(addrs.ModuleCallInstance, tfdiags.Source
}

func (d analysisData) GetModuleInstanceOutput(addrs.ModuleCallOutput, tfdiags.SourceRange) (cty.Value, tfdiags.Diagnostics) {
// This implementation doesn't use this.
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this comment denoting that this is dead code?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, this function is required so that the interface is implemented, but is not used - I will add to the comment!

@mildwonkey
Copy link
Contributor Author

@pselle thank you, this is really helpful feedback:

(namely, making OutputValue referenceable, when it is noted to explicitly not be)

I was only thinking about the console output needs and had missed the additional implications of making this referenceable. I'll look into alternate ways for the console to access root module outputs, which are not available in the ModuleCallOutput (and awkwardly, ModuleCallOutput is not available for console, so perhaps I can remove that from the console logic while I'm in there).

@mildwonkey mildwonkey closed this Feb 11, 2020
@mildwonkey mildwonkey deleted the mildwonkey/b-console branch March 20, 2020 12:38
@ghost
Copy link

ghost commented Mar 21, 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 Mar 21, 2020
# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
sdkv1 [PRs only] Marks changes that may potentially need to be ported to the plugi nSDK
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants