-
Notifications
You must be signed in to change notification settings - Fork 9.6k
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
Weird behavior when using the lookup function in terraform 0.12.x #22267
Comments
Hi @manniche ! Thank you for reporting this unexpected behavior and inconsistent documentation. Under the hood, As a workaround, you can declare your variable an object (this might not be useful depending on what your "real" configuration looks like):
Here's the relevant code, under the hood. terraform/lang/funcs/collection.go Lines 684 to 687 in 1c556c0
Argument is a Map of type terraform/lang/funcs/collection.go Lines 690 to 700 in 1c556c0
|
As a workaround until the fix lands in a version, I do this in my test_elem1_object = {for k, v in var.test_elem1: k => v} and now the result in the > lookup(local.test_elem1_object, "instance-01")
{
"name" = "foo"
} thanks for the quick reply, clarification and not least the PR! |
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. |
Description of the issue
I am trying to use the
lookup
function with avariable
, which fails. At the same time, using the function on alocal
with similar characteristics succeeds. The error message given seems to imply different semantics than what is described in the documentationTerraform version
0.12.2
and0.12.5
Minimal example
Files to reproduce the issue
terraform.tfvars
:main.tf
Commands to reproduce the issue
Expected output
I was expecting the lookup on the variable to behave in the same way as the lookup on the local.
As an aside (and as mentioned in the top of this issue), I am puzzled by the error message coming from terraform:
lookup() can only be used with flat lists.
, which to me differs in explanation to that of the documentation:The text was updated successfully, but these errors were encountered: