0
votes

I've configured the following variable in module/variables.tf

variable "instance_name" {
    type = string
    default = "instance-1"
    description = "Name of the instance."
}

I refer to the variable in the same module module/main.tf as below

resource "google_compute_instance" "cloud_instance" {
    name = var.instance_name
}

However, when I run terraform init, I get the following error-

Error: Error parsing /module/main.tf: At 15:12: Unknown token: 15:12 IDENT var.instance_name

Any idea why this is happening?

2
What version of Terraform are you running? If it's pre 0.12 (just a beta right now) then that should be name = "${var.instance_name}"ydaetskcoR

2 Answers

0
votes

You need to refer variable as below to ensure expansion works correctly -

resource "google_compute_instance" "cloud_instance" {
    name = "${var.instance_name}"
}
-2
votes

Using terraform 0.12.9 - I do not get this error on init or plan or validate, only on 0.12upgrade. Also the documentation shows that if the variable is not in a string, it is possible to pass it without quotation marks and curly braces.

So which is correct?