Skip to content

lang/funcs: lookup() can work with maps of lists, maps and objects#22269

Merged
mildwonkey merged 3 commits intomasterfrom
mildwonkey/extend-lookup
Aug 1, 2019
Merged

lang/funcs: lookup() can work with maps of lists, maps and objects#22269
mildwonkey merged 3 commits intomasterfrom
mildwonkey/extend-lookup

Conversation

@mildwonkey
Copy link
Copy Markdown
Contributor

lookup() can already handle arbitrary objects of (whatever) and should
handle maps of (whatever) similarly.

The documentation does not mention any limitation to the types returned, which was inconsistent with the error message when a map of objects, lists or maps was used.

Fixes #22267

lookup() can already handle aribtrary objects of (whatever) and should
handle maps of (whatever) similarly.
@mildwonkey mildwonkey requested a review from a team July 31, 2019 14:20
@mildwonkey mildwonkey closed this Jul 31, 2019
@mildwonkey mildwonkey reopened this Jul 31, 2019
Comment thread lang/funcs/collection.go Outdated
if len(args) == 3 {
_, err = convert.Convert(args[2], ty.ElementType())
if err != nil {
return cty.NilType, function.NewArgErrorf(0, "the default value and map elements must have the same type")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The 0 here indicates that the problem is with the zeroth argument; perhaps it would be clearer to indicate 2 so that Terraform will indicate the default value as the subject of the error when it prints out diagnostics, as a subtle additional indication that it's probably the default value that ought to change to match the map, rather than the other way around.

Comment thread lang/funcs/collection.go Outdated
Comment thread lang/funcs/collection_test.go
Comment thread lang/funcs/collection_test.go Outdated
@apparentlymart
Copy link
Copy Markdown
Contributor

Looking good, thanks! I left some minor notes inline.

Copy link
Copy Markdown
Contributor

@apparentlymart apparentlymart left a comment

Choose a reason for hiding this comment

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

🎉

@mildwonkey mildwonkey merged commit 2b14a6b into master Aug 1, 2019
@mildwonkey mildwonkey deleted the mildwonkey/extend-lookup branch August 1, 2019 19:52
@ghost
Copy link
Copy Markdown

ghost commented Sep 1, 2019

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 Sep 1, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Weird behavior when using the lookup function in terraform 0.12.x

2 participants