What’s the type of local variable default_tags
in the snippet below?
variable "id" {
description = "The id that is used in the name of the resources to be created"
type = string
default = "-1"
}
variable "suffix" {
description = "The suffix that is used in the name of the resources to be created"
type = string
default = "_default"
}
locals {
default_tags = {
BuiltBy = "Terraform"
Id = var.id
Suffix = var.suffix
}
}
Where can I find more about inferring the types of local variables?
With that expression exactly as written, the inferred type will be:
object({
BuiltBy = string
Id = string
Suffix = string
})
The syntax with braces like that is an object constructor expression, so its result type is always an object type.
However, because all of your attributes are strings, this value can automatically convert to map(string)
when used in a context where such a map is expected, like the tags
argument of most AWS provider resources types. You can force that conversion yourself as the declaration point if you wish, by passing the object constructor expression to the tomap
function.