Skip to content
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

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

Merged
merged 3 commits into from
Aug 1, 2019

Conversation

mildwonkey
Copy link
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
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
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.

lang/funcs/collection.go Outdated Show resolved Hide resolved
lang/funcs/collection_test.go Show resolved Hide resolved
lang/funcs/collection_test.go Outdated Show resolved Hide resolved
@apparentlymart
Copy link
Contributor

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

Copy link
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

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