简体   繁体   中英

How to define default value for map variable in Terraform?

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.

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 ie "" .

Note the documentation confirms keys must be String type.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM