Quoting types and identifiers

Working on a configuration recently, I created a resource but forgot to quote the type and name. Eg instead of:

resource "null_resource" "my_resource" { ... }

I typed:

resource null_resource my_resource { ... }

Surprisingly (to me), it worked. No errors or warnings were generated, and the configuration functioned as intended. I carried the experiment further, and eliminated all quoting that wasn’t surrounding string data.

variable my_var {}
provider null { }
resource null_resource my_resource {
  provisioner local-exec { command = "echo my_var is ${my_var}" }
}

I started quote elimination with beta 0.13, but it appears to apply equally well with 0.12.25. The text is significantly easier to read without them. Errors due to unmatched quotes are reduced.
To illustrate, consider this obvious mistake:

resource "TYPE" "NAME {
  something = var.something_else
  another = var.one
  lastvar = "this"
}

Without syntax coloring, it’s easy to overlook:

resource "TYPE" "NAME {
  something = var.something_else
  another = var.one
  lastvar = "this"
}

Is quoting types, variable declaractions, etc theoretically required by the language syntax?

Hi @jeremykatz,

The Terraform documentation has shown the block labels quoted in all examples for many years, so that is the primary, idomatic style. terraform fmt may start doing this automatically in future versions, as it starts to regain some of its more opinionated formatting behaviors that were temporarily removed in Terraform 0.12 because of the switch to a new HCL implementation.

As you’ve seen though, the parser considers them optional mainly for backward compatibility with earlier versions of the language, which have considered quoted and unquoted labels as synonymous going back to the introduction of HCL in a very early Terraform version.

If anyone is taking a poll, my vote is for fewer "s.