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 v0.12.0
Standard Module Refs
module "example-module" {
source = "git::ssh://[email protected]/tf/terraform-aws-example?ref=v0.0.2"
region = var.region
account = var.account
account_number = var.account_number
}
N/A
N/A
terraform console
to use remote state or find terraform outputs from modules.
terraform console
seems to always expect terraform apply
to occur despite it succeeding
Go to an existing terraform project/workspace:
terraform console
> module.aws-iam-example.example_output
Error: Result depends on values that cannot be determined until after "terraform apply".
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.
N/A
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.)
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. :)
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.
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.
Are there any workarounds for getting outputs with 0.12 modules?
Edit: Here's what I've tried so far:
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
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".
Any news on this bug ? i have the exact same issue
Any news on this yet? I'm also running into this issue.
Having this issue as well.
I'm also seeing the same issue
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 :+1:, which we _can_ and _do_ report on.
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.
I'm going to close this and consider it resolved because it was resolved in https://github.com/hashicorp/terraform/pull/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.
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.
Most helpful comment
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.