tm_hclencode
Function
tm_hclencode
encodes a given object or map value to a string using HCL file syntax. The top-level object keys and values are encoded as HCL top-level attributes.
The main use case for this function is generating the Terraform/Tofu .tfvars
file.
The top-level object key MUST be a valid HCL identifier or else it fails. Currently, blocks cannot be encoded.
Example:
tm_hclencode({name = "my-instance", size = "10"})
name = "my-instance"
size = 10
Examples
sh
tm_hclencode({image_id = "ami-abc123", availability_zone_names = ["us-east-1a", "us-west-1c"]})
image_id = "ami-abc123"
availability_zone_names = [
"us-east-1a",
"us-west-1c",
]
Related Functions
tm_hcldecode
performs the reverse operation, decoding an HCL file content to obtain its corresponding Terramate value.