Not throwing error while giving other data type in list

Given below is list_demo.tf file and list_output.tf file

cat list_demo.tf
variable "list_example" {
description="demo on list data type"
type=list(string)
#default=["Aniket Pant","42","true"]
}
[root@localhost list]# cat list_output.tf
output "list_output" {
value=var.list_example
}

While running terraform plan command it has to give error as list can accept same data type

[root@localhost list]# terraform plan
var.list_example
  demo on list data type

  Enter a value: ["Aniket",28,true]


Changes to Outputs:
  + list_output = [
      + "Aniket",
      + "28",
      + "true",
    ]

You can apply this plan to save these new output values to the Terraform state, without changing any real infrastructure.

I want to understand the behaviour of terraform , is it converting into string ?

Earlier i was using this below file and the input was same and got the same output as i mentioned in above. If i am not providing any type in list , what is the default type ?

cat list_demo.tf
variable "list_example" {
description="demo on list data type"
type=list
#default=["Aniket Pant","42","true"]
}

Please do share the documentation as i am learning.

Hi @aniketpant1,

See the section on Type Conversion in the documentation.

Like you said, the list must consist of a single type, therefor ["Aniket",28,true] could not possibly be a list, so Terraform attempts to convert the elements to a single type and finds that a string is possible. If you were to give something more complex which can’t be converted like: ["a", 1, [2]], you would get a type error as expected.