Terraform: local variables broken in v0.11.0 - resource variables must be three parts: TYPE.NAME.ATTR

Created on 21 Nov 2017  ยท  11Comments  ยท  Source: hashicorp/terraform

Problem is exhibited with all defined local variables.

Terraform Version

v0.11.0

Terraform Configuration Files

From the terraform documentation for local variables:

```# Define the common tags for all resources
locals {
common_tags = {
Component = "awesome-app"
Environment = "production"
}
}

Create a resource that blends the common tags with instance-specific tags.

resource "aws_instance" "server" {
ami = "ami-123456"
instance_type = "t2.micro"

tags = "${merge(
local.common_tags,
map(
"Name", "awesome-app-server",
"Role", "server"
)
)}"
}

### Expected Behavior

Terraform has been successfully initialized!

### Actual Behavior

```# terraform11 init
Error loading configuration: Error loading /tmp/local2/main.tf: Error reading config for aws_instance[server]: local.common_tags: resource variables must be three parts: TYPE.NAME.ATTR in:

${merge(
    local.common_tags,
    map(
      "Name", "awesome-app-server",
      "Role", "server"
    )
  )}

Steps to Reproduce

Create a .tf file with the above example lines and run terraform init

config

Most helpful comment

For those asking: The issue also happens if the user accidentally uses locals.whatever_key_of_your_choice instead of local.whatever_key_of_your_choice

(note the extraneous S)

All 11 comments

Hi @tburt11,

Are you certain that this is the exact config you used to reproduce the issue? Using that config exactly as written doesn't produce any errors for me.

@jbardin Hmm... I installed the v0.11.0 on a fresh macbook, and it works OK.
Must be something in my working environment. I will do further testing next week.
Thanks!

Closing - User Error..

did you ever figure out what the issue was? I am seeing this same thing and can't figure it out...

@tburt11 What was the issue?

I observed this exact error message when accidentally using a terraform binary older than 0.10.3 (0.9.11, in my case) on a configuration which used locals in resource definitions. /cc @pixelicous @repl-chris @tburt11

@sureshgoli81 thx, it was the same issue here..

FYI in case you didn't know, you can add a required Terraform version configuration to ensure you're always running against a version you expect, e.g.

terraform {
  required_version = ">= 0.10.3"
}

For those asking: The issue also happens if the user accidentally uses locals.whatever_key_of_your_choice instead of local.whatever_key_of_your_choice

(note the extraneous S)

I had this error because I forgot to properly reference the field I wanted.

This failed:

records = ["${aws_alb.my_alb}"]

This worked:

records = ["${aws_alb.my_alb.dns_name}"]

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.

Was this page helpful?
0 / 5 - 0 ratings