You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Mentioning in the documentation map -> object map conversions can be lossy.
Proposal
It is a confusing as i haven't find any example on the internet and on the documentation where map to object conversion can be failed or lossy. Even though we should have a object function where it can convert map to object. If we have simple example on this . It would be easier for the users also.
References
No response
The text was updated successfully, but these errors were encountered:
Hi @aniketpant1, here's a potential example of a lossy conversion from map to object.
# ./main.tfvariable"map" {
type=map(string)
default={
a ="a"
b ="b"
c ="c"
}
}
module"mod" {
source="./module"object=var.map
}
output"map" {
value=var.map
}
output"object" {
value=module.mod.object
}
# ./module/main.tfvariable"object" {
type=object({
a =string
b =string
})
}
output"object" {
value=var.object
}
If you execute the above Terraform files, you can see from the outputs that the c value from the map has been automatically stripped from the returned object. This is the conversion being lossy - as values from the map have been silently removed in order to make the type match the type required by the object variable.
map = tomap({
"a" = "a"
"b" = "b"
"c" = "c"
})
object = {
"a" = "a"
"b" = "b"
}
Terraform Version
Affected Pages
https://developer.hashicorp.com/terraform/language/expressions/type-constraints#conversion-of-complex-types
What is the docs issue?
Mentioning in the documentation map -> object map conversions can be lossy.
Proposal
It is a confusing as i haven't find any example on the internet and on the documentation where map to object conversion can be failed or lossy. Even though we should have a object function where it can convert map to object. If we have simple example on this . It would be easier for the users also.
References
No response
The text was updated successfully, but these errors were encountered: