Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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.

>Solution :

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading