github.com/muratcelep/terraform@v1.1.0-beta2-not-internal-4/website/docs/language/functions/yamldecode.html.md (about) 1 --- 2 layout: "language" 3 page_title: "yamldecode - Functions - Configuration Language" 4 sidebar_current: "docs-funcs-encoding-yamldecode" 5 description: |- 6 The yamldecode function decodes a YAML string into a representation of its 7 value. 8 --- 9 10 # `yamldecode` Function 11 12 `yamldecode` parses a string as a subset of YAML, and produces a representation 13 of its value. 14 15 This function supports a subset of [YAML 1.2](https://yaml.org/spec/1.2/spec.html), 16 as described below. 17 18 This function maps YAML values to 19 [Terraform language values](/docs/language/expressions/types.html) 20 in the following way: 21 22 | YAML type | Terraform type | 23 | ------------- | ------------------------------------------------------------------ | 24 | `!!str` | `string` | 25 | `!!float` | `number` | 26 | `!!int` | `number` | 27 | `!!bool` | `bool` | 28 | `!!map` | `object(...)` with attribute types determined per this table | 29 | `!!seq` | `tuple(...)` with element types determined per this table | 30 | `!!null` | The Terraform language `null` value | 31 | `!!timestamp` | `string` in [RFC 3339](https://tools.ietf.org/html/rfc3339) format | 32 | `!!binary` | `string` containing base64-encoded representation | 33 34 The Terraform language automatic type conversion rules mean that you don't 35 usually need to worry about exactly what type is produced for a given value, 36 and can just use the result in an intuitive way. 37 38 Note though that the mapping above is ambiguous -- several different source 39 types map to the same target type -- and so round-tripping through `yamldecode` 40 and then `yamlencode` cannot produce an identical result. 41 42 YAML is a complex language and it supports a number of possibilities that the 43 Terraform language's type system cannot represent. Therefore this YAML decoder 44 supports only a subset of YAML 1.2, with restrictions including the following: 45 46 - Although aliases to earlier anchors are supported, cyclic data structures 47 (where a reference to a collection appears inside that collection) are not. 48 If `yamldecode` detects such a structure then it will return an error. 49 50 - Only the type tags shown in the above table (or equivalent alternative 51 representations of those same tags) are supported. Any other tags will 52 result in an error. 53 54 - Only one YAML document is permitted. If multiple documents are present in 55 the given string then this function will return an error. 56 57 ## Examples 58 59 ``` 60 > yamldecode("hello: world") 61 { 62 "hello" = "world" 63 } 64 65 > yamldecode("true") 66 true 67 68 > yamldecode("{a: &foo [1, 2, 3], b: *foo}") 69 { 70 "a" = [ 71 1, 72 2, 73 3, 74 ] 75 "b" = [ 76 1, 77 2, 78 3, 79 ] 80 } 81 82 > yamldecode("{a: &foo [1, *foo, 3]}") 83 84 Error: Error in function call 85 86 Call to function "yamldecode" failed: cannot refer to anchor "foo" from inside 87 its own definition. 88 89 > yamldecode("{a: !not-supported foo}") 90 91 Error: Error in function call 92 93 Call to function "yamldecode" failed: unsupported tag "!not-supported". 94 ``` 95 96 ## Related Functions 97 98 - [`jsondecode`](./jsondecode.html) is a similar operation using JSON instead 99 of YAML. 100 - [`yamlencode`](./yamlencode.html) performs the opposite operation, _encoding_ 101 a value as YAML.