Terraform 0.12 local variable map

Terraform code:

locals {
  rds_instances_to_cpu_cores = {
    db.m4.large   = 2
    db.m4.xlarge  = 4
    db.m4.4xlarge = 16

The above works fine in Terraform 0.11.x, but when I try to init Terraform 0.12.x I get this error:

$ terraform init
Initializing modules...
There are some problems with the configuration, described below.
The Terraform configuration must be valid before initialization so that
Terraform can determine which modules and providers need to be installed.
Error: Missing key/value separator
  on ../../modules/aws/my_module/rds.tf line 299, in locals:
 299:     db.m4.4xlarge = 16
Expected an equals sign ("=") to mark the beginning of the attribute value. If
you intended to given an attribute name containing periods or spaces, write
the name in quotes to create a string literal.

Anybody know what I’m doing wrong with this map? Thanks.

Putting the key in quotes seems to have worked.

"db.m4.4xlarge" = 16

I just wasn’t used to needing quotes for the map-keys.


Hi @jwr0,

Indeed, Terraform 0.12 requires quotes around any key that isn’t a valid identifier in the language, which in practice means a key that doesn’t start with a letter and consist only of letters, digits, underscores, and dashes.

We added this extra constraint to allow the map keys to be arbitrary expressions rather than just literal strings, with the special case that a standalone identifier is still understood as a literal key to remain mostly compatible with existing usage. We were forced to compromise on full compatibility here to avoid making the language ambiguous with the addition of arbitrary expression keys.

The terraform 0.12upgrade command ought to have fixed this for you automatically, along with the other fixes it does to benefit from 0.12 syntax.