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

Terraform Console Unable to Output Module Outputs #21516

Closed
jvasallo opened this issue May 30, 2019 · 14 comments · Fixed by #24808
Closed

Terraform Console Unable to Output Module Outputs #21516

jvasallo opened this issue May 30, 2019 · 14 comments · Fixed by #24808
Labels
bug cli enhancement v0.12 Issues (primarily bugs) reported against v0.12 releases
Milestone

Comments

@jvasallo
Copy link

jvasallo commented May 30, 2019

After upgrading to Terraform v0.12, it appears Terraform console no longer is able to access module outputs from a remote state (or state in general). It always seems to expect a terraform apply to occur. Terraform operations (such as plan and apply) work fine, as well as module output references in resource blocks as well. Only terraform console seems to be impacted. Not sure if this is an intended change or not.

Happy to share anything I can. Looking at the TF_LOG I see it crawling ok, and it even finds references and such.

Terraform Version

Terraform v0.12.0

Terraform Configuration Files

Standard Module Refs

module "example-module" {
  source = "git::ssh://git@examplegithub.heygears.com/tf/terraform-aws-example?ref=v0.0.2"

  region         = var.region
  account        = var.account
  account_number = var.account_number
}

Debug Output

N/A

Crash Output

N/A

Expected Behavior

terraform console to use remote state or find terraform outputs from modules.

Actual Behavior

terraform console seems to always expect terraform apply to occur despite it succeeding

Steps to Reproduce

Go to an existing terraform project/workspace:

  1. terraform console
  2. > module.aws-iam-example.example_output
  3. Error: Result depends on values that cannot be determined until after "terraform apply".

Additional Context

Upgraded from 0.11.4 to 0.12.0 recently, and post upgrade it seems to not be able to evaluate state in terraform console. We use a remote state in S3 and DynamoDB for Locking.

References

N/A

@apparentlymart
Copy link
Contributor

Thanks for reporting this, @jvasallo.

The intended design here is that terraform console will do a simple state-only graph walk before showing the prompt so it can recalculate all of the local values and output values that are otherwise retained only in memory during a graph walk. It seems like perhaps that isn't working as intended.

I have a different theory to check first, though: I see you're passing a few input variables from the root module into the child module. We've seen in #21483 that terraform console isn't accepting -var and -var-file anymore, which suggests that all of the input variables in the root module would evaluate to an unknown value in the terraform console context right now. Is the value of this example_output output derived from one or more of those input variables? If that is true, then the unknown will spread to those too, thus causing this message. (Console shows this any time the expression results in an unknown value, which is usually due to referring to a resource that hasn't been created yet, hence the wording used in the message.)

@jvasallo
Copy link
Author

jvasallo commented May 30, 2019

Thanks for the quick response! The example_output is just outputting an AWS resource attribute such as arn, name, etc. Below is what I am seeing when I check my outputs of local vars via terraform console.

Terraform Console Output:

[joel.vasallo@localhost us-east-2]$ terraform console
> var.region
us-east-2
> var.account
production
> var.account_number
1234567891234
> module.example-module.example_output

>
Error: Result depends on values that cannot be determined until after "terraform apply".

Seems to evaluate local outputs fine?

The resource created is:

resource "aws_iam_user" "example_user" {
    name = "example_user"
    path = "/user-example/"
}

The output from the module is:

output "example_output" {
  value = "${aws_iam_user.example_user.arn}"
}

If we feel this is related to #21483 let me know. Sorry if this is a duplicate issue. :)

@apparentlymart
Copy link
Contributor

Thanks for sharing that additional context, @jvasallo.

Indeed it does seem like this is a separate problem, so we'll keep it as a separate issue for now until we can investigate further and understand what's going on here. The intended behavior is that terraform console would, before showing the first prompt, load the latest state snapshot and use it to evaluate that aws_iam_user.example_user.arn reference to a specific known value, but apparently something isn't working quite right there and it's instead behaving as if the resource instance hasn't been created at all yet.

@hashibot hashibot added the v0.12 Issues (primarily bugs) reported against v0.12 releases label Aug 22, 2019
@mhvelplund
Copy link

Any news on this bug? It makes it very hard to create modules that "bake" configuration. If I want to see my state, I have to either inline the code in the parent, or make the module able to stand alone, if I want to inspect the results.

@ebunassar
Copy link

ebunassar commented Nov 25, 2019

Are there any workarounds for getting outputs with 0.12 modules?

Edit: Here's what I've tried so far:

  • Used Output {} only in the module, this obviously didn't work
  • Added an Output block to the root main.tf that uses value = module.moduleName.outputName, still no output returned.

2nd edit: I'm an idiot. Completely missed that the actual root tf file contained a module that referenced another module. What ended up working for me is defining an output at each module and then chaining them like so:
├── main.tf # Add output here (output "exampleRootOutput" {value = module.storage.exampleModuleOutput})
├── storage
│ └── main.tf # Add output here (output "exampleModuleOutput"{value = module.moduleName.example})
├── templates
│ └── storageAccounts
│ ├── main.tf # Add output here (output "example" {value = resource.name.value})
│ └── var.tf

@HighwayofLife
Copy link

HighwayofLife commented Dec 11, 2019

You can easily reproduce this bug with the following code:

Module:

locals {
  stuff = {
    foo = "bar"
  }
}

output "house" {
  value = local.stuff
}

Import...

module "stuff" {
  source = "../stuff"
}

terraform console...

module.stuff.house

>  
Error: Result depends on values that cannot be determined until after "terraform apply".

@Frederic-de-Lavenne

This comment has been minimized.

@OllionDavidCunliffe

This comment has been minimized.

@robins35

This comment has been minimized.

@cbumstead

This comment has been minimized.

@teamterraform
Copy link
Contributor

Hi all,

Please do not post "me too" comments here, since it creates noise for others watching the issue and ultimately doesn't influence our prioritization because we can't actually report on these. Instead, react to the original issue comment with 👍, which we can and do report on.

@mildwonkey
Copy link
Contributor

Sorry for the labeling noise! After some internal discussion related to the closed PR above I wanted to make a note that terraform console is not designed to return root module outputs, so adding that is a feature request.

@danieldreier
Copy link
Contributor

I'm going to close this and consider it resolved because it was resolved in #24808, in order to keep the GH issue listing only showing unresolved issues. Please file a new bug and reference this one if it doesn't work for you in 0.13.0.

@ghost
Copy link

ghost commented Jul 13, 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 Jul 13, 2020
# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
bug cli enhancement v0.12 Issues (primarily bugs) reported against v0.12 releases
Projects
None yet
Development

Successfully merging a pull request may close this issue.