My team does something similar to this. We write our Terraform configuration as Python literals with list comprehensions, conditional expressions, etc., then use a script to dump it to JSON which the Terraform command line can parse.
Here's an example: https://github.com/DataBiosphere/azul/blob/develop/terraform...