You can use terraform yamlencode() and yamldecode() functions to encode and decode YAML data. yamlencode() encodes a given value to a string using YAML 1.2 block syntax and yamldecode() parses a string as a subset of YAML and produces a representation of its value.
Syntax: yamlencode(string) yamldecode(string)
Example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
## Open terraform console terraform console ## Encode a string into json yamlencode({"name": "debjeet", "skills": ["cloud", "devops"]}) ## returns ## "name": "debjeet" ## "skills": ## - "cloud" ## - "devops" ## Decode a json string yamldecode("{a: &foo [1, 2, 3], b: *foo}") ## returns ## { ## "a" = [ ## 1, ## 2, ## 3, ## ] ## "b" = [ ## 1, ## 2, ## 3, ## ] ## } |