'length of keys in a map in Terraform - odd output
Given:
variable "foo" {
type = map
default = {
lorem = "ipsum"
dolor = "sit"
}
}
then, in Terraform console, why does
[for k, v in var.foo : length(k) ]
give:
[
4,
5,
]
Solution 1:[1]
That's a really odd result. When I run the exact same thing locally, I get the expected result:
> [for k, v in var.foo : length(k) ]
[
5,
5,
]
Do you have a value set for "foo" in a *.auto.tfvars
file somewhere? How about an environment variable called TF_VAR_foo
? My best guess is that there is a different variable defined somewhere called "foo" that is overwriting the default
value specified in the variable declaration.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | logyball |