This is something I’ve only recently discovered but thought it was worth sharing here.
I have a few configurations where I need to pass JSON to Terraform to process. The most used resource where I do this is azurerm_virtual_machine_extension. The example
HashiCorp documentation
still shows the use of Heredoc strings which is probably why I hadn’t picked up on it until now.
I recently discovered a
HashiCorp article
where they tell you that by using the jsonencode and yamlencode functions “Terraform can be responsible for guaranteeing valid JSON or YAML syntax”. This sounded good to me as JSON syntax is not very forgiving, and it is designed to be read and processed by machines (not humans). If you put a comma or a bracket in the wrong place, you will soon be in a whole world of pain. The same is true for YAML and indentations.
Continue Reading...