github.com/terramate-io/tf@v0.0.0-20230830114523-fce866b4dfcd/website/docs/language/functions/type.mdx (about) 1 --- 2 page_title: type - Functions - Configuration Language 3 description: 'The type function returns the type of a given value. ' 4 --- 5 6 # `type` Function 7 8 -> **Note:** This function is available only in Terraform 1.0 and later. 9 10 `type` returns the type of a given value. 11 12 Sometimes a Terraform configuration can result in confusing errors regarding 13 inconsistent types. This function displays terraform's evaluation of a given 14 value's type, which is useful in understanding this error message. 15 16 This is a special function which is only available in the `terraform console` 17 command. It can only be used to examine the type of a given value, and should 18 not be used in more complex expressions. 19 20 ## Examples 21 22 Here we have a conditional `output` which prints either the value of `var.list` or a local named `default_list`: 23 24 ```hcl 25 variable "list" { 26 default = [] 27 } 28 29 locals { 30 default_list = [ 31 { 32 foo = "bar" 33 map = { bleep = "bloop" } 34 }, 35 { 36 beep = "boop" 37 }, 38 ] 39 } 40 41 output "list" { 42 value = var.list != [] ? var.list : local.default_list 43 } 44 ``` 45 46 Applying this configuration results in the following error: 47 48 ``` 49 Error: Inconsistent conditional result types 50 51 on main.tf line 18, in output "list": 52 18: value = var.list != [] ? var.list : local.default_list 53 |---------------- 54 | local.default_list is tuple with 2 elements 55 | var.list is empty tuple 56 57 The true and false result expressions must have consistent types. The given 58 expressions are tuple and tuple, respectively. 59 ``` 60 61 While this error message does include some type information, it can be helpful 62 to inspect the exact type that Terraform has determined for each given input. 63 Examining both `var.list` and `local.default_list` using the `type` function 64 provides more context for the error message: 65 66 ``` 67 > type(var.list) 68 tuple 69 > type(local.default_list) 70 tuple([ 71 object({ 72 foo: string, 73 map: object({ 74 bleep: string, 75 }), 76 }), 77 object({ 78 beep: string, 79 }), 80 ]) 81 ```