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

Map lookup still throws missing key error when it is never called. #17974

Closed
MaxFlanders opened this issue Apr 30, 2018 · 2 comments
Closed

Map lookup still throws missing key error when it is never called. #17974

MaxFlanders opened this issue Apr 30, 2018 · 2 comments

Comments

@MaxFlanders
Copy link

Terraform Version

Terraform v0.11.7
+ provider.aws v1.14.0
+ provider.null v1.0.0

Terraform Configuration Files

local_variable = ${ contains( keys(var.constants), "some_key" ) == "true" ? var.constants["some_key"] : "other_default_value" }

Expected Behavior

Terraform does not throw a "key does not exist error" unless the key is actually going to be used, especially when the wrapping conditional checks for the existence of the key.

Actual Behavior

An error is thrown:

* module.mod.local.: local.local_variable: key "some_key" does not exist in map var.constants in:
${ contains( keys(var.constants), "some_key" ) == "true" ? var.constants["some_key"] : "other_default_value" }

Steps to Reproduce

Create a conditional local variable like above, which checks the map for a key before using the key, and run terraform.

@jbardin
Copy link
Member

jbardin commented Apr 30, 2018

Hi @MaxFlanders,

Sorry this is causing you an issue. The index operation does happen in that expression, because conditionals themselves are not short-circuiting.

This is an enhancement we have planned, and there is an open issue at #15605

@jbardin jbardin closed this as completed Apr 30, 2018
@ghost
Copy link

ghost commented Apr 3, 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 Apr 3, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants