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

core: Raise error for old map keys & list members referencing syntax #6932

Closed
radeksimko opened this issue May 30, 2016 · 2 comments
Closed

Comments

@radeksimko
Copy link
Member

As @Djuke mentioned in #6322 (comment) the old syntax for referencing map keys & list members via dots stopped working silently since #6322 was merged.

While I agree that the new syntax w/ square brackets is a lot better and making the old syntax work would be probably waste of time I think many people may have the old, dotted references in many places of their codebase and it will confuse them (and make upgrades painful) if we just silently ignore these in 0.7.

Terraform Version

Built from master (fcc3736e6bb850e51c240fda5c033888f13dcb34).

Terraform Configuration Files

variable "minions" {
    default = ["first", "second"]
}
output "first_minion" {
    value = "${var.minions.0}"
}

variable "colour_codes" {
    default = {
        black = "000"
        white = "FFF"
    }
}
output "black_code" {
    value = "${var.colour_codes.black}"
}

Debug Output

https://gist.github.com/radeksimko/6a2126a75ea08ca2fd3540b6b899c14e

Expected Behavior

Either an error or warning should've been raised about wrong syntax or unknown variable.

Output interpolation "first_minion" failed: 1:3: unknown variable accessed: var.minions.0
Output interpolation "black_code" failed: 1:3: unknown variable accessed: var.colour_codes.black

We are actually able to detect these already, see the attached debug log, search for WARN.

Actual Behavior

$ terraform apply

Apply complete! Resources: 0 added, 0 changed, 0 destroyed.

Steps to Reproduce

  1. terraform apply

References


New syntax w/ square brackets

This works as expected:

variable "minions" {
    default = ["first", "second"]
}
output "first_minion" {
    value = "${var.minions[0]}"
}

variable "colour_codes" {
    default = {
        black = "000"
        white = "FFF"
    }
}
output "black_code" {
    value = "${var.colour_codes["black"]}"
}

cc @jen20

@phinze
Copy link
Contributor

phinze commented Aug 3, 2016

Just confirmed that a nicely specific error is raised in both usages in this example:

Error reading config for output first_minion: Invalid dot index found: 'var.minions.0'. Values in maps and lists can be referenced using square bracket indexing, like: 'var.mymap["key"]' or 'var.mylist[1]'. in:

${var.minions.0}
Error reading config for output black_code: Invalid dot index found: 'var.colour_codes.black'. Values in maps and lists can be referenced using square bracket indexing, like: 'var.mymap["key"]' or 'var.mylist[1]'. in:

${var.colour_codes.black}

@phinze phinze closed this as completed Aug 3, 2016
@ghost
Copy link

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

No branches or pull requests

2 participants