0

My input.tfvars file has the values for map variable named project as below:

project = {
name = "sampleproject"
team = "Code"
}

The definition for the same variable project for default values in variables.tf file is below:

variable "project"{
type = map(string)
default ={
name = "defaultproject"
team = "defaultteam"
}
}

Is the syntax for defining default variables is correct? or does the key also needs to be provided in quotes as below:

variable "project"{
type = map(string)
default ={
"name" = "defaultproject"
"team" = "defaultteam"
}
}

Google search provided answers with both of the above options for defining default variables for a map, hence I am asking here for clarification.

1 Answer 1

2

Keys in HCL2 Maps and Objects must be strings, and therefore any key is implicitly cast to String, and therefore does not need the explicit syntax for casting/constructing as a string i.e. "".

Note the documentation confirms keys must be String type.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.