terraform icon indicating copy to clipboard operation
terraform copied to clipboard

tomap is not evaluated on console

Open jamesmudd opened this issue 2 years ago • 3 comments

Terraform Version

Terraform v1.2.6
on linux_amd64

Terraform Configuration Files

none

Expected Behavior

tomap should have been evaluated

Actual Behavior

It was not and was printed to the console

Steps to Reproduce

$ terraform console
> tomap({"a" = 1, "b" = 2})
tomap({
  "a" = 1
  "b" = 2
})

Example is take from docs https://www.terraform.io/language/functions/tomap

jamesmudd avatar Aug 11 '22 09:08 jamesmudd

Hi @jamesmudd,

Thanks for filing the issue. The tomap function is evaluated, but the output in the docs does not reflect the map type, which is differentiated from an object type using tomap to mirror the syntax one would use the configuration. The behavior you see is correct.

Thanks!

jbardin avatar Aug 11 '22 12:08 jbardin

Oh yes, indeed... when we originally wrote these docs Terraform CLI was written to present a map using the object syntax with no extra annotation, because that's how people typically produce a map value in situations where Terraform can infer an automatic conversion to a map. However, we learned over time that it was confusing because it made it hard to tell from the terraform console output exactly what type of value was being returned, and so we changed the value renderer to include explicit tomap(...), tolist(...), and toset(...) wrappers as a way to explicitly say "this value is a map, not an object" even though the Terraform language has no separate syntax for constructing maps.

Given that, I think what we have here is just outdated documentation: we changed the presentation in the UI without changing the examples in the docs that illustrate that behavior.

apparentlymart avatar Aug 11 '22 19:08 apparentlymart

@apparentlymart @jbardin please let me fix this

RobertShan2000 avatar Sep 22 '22 02:09 RobertShan2000

Hi @RobertShan2000, I would recommend checking out the good first issue tag in the terraform-provider-aws repository. They are soliciting new user contributions. Thanks for your interest!

crw avatar Sep 24 '22 00:09 crw