Both of the YAML examples you included at the end of your message seem equivalent to me. YAML is a flexible language that has many different ways to write the same data structure, but for a correct YAML parser there should be no difference in result between the style Terraform is generating (“block style”) and the style you suggested that you want it to generate (“flow style”).
There is no way to generate flow style with the yamlencode function. It always uses block style, unless generating empty collections.
I’ve seen cloud-init work with what yamlencode generates before, so I believe cloud-init correctly supports YAML and should be able to parse this. Are you sure that there isn’t some other problems occuring to make this fail? Do you see any specific errors in cloud-init’s logs?