Could people share their experiences of generating Terraform configuration? i.e. rather than writing their terraform configuration by hand, have it generated via a script. I see @eropple created a tool to help with this: Terraframe [1], a ruby DSL (I read he's had difficulties getting this off the ground [2], too). I'd be interested to hear from those that have tried or are following such an approach today, whether with Terraframe, or anything else, and what if any problems they ran into.
I'm an experienced Terraform user. I spent 6 months maintaining a complex AWS infrastructure, writing dozens of modules, refactoring them mercilessly, and maintaining a YAML file alongside it, running rake tasks to read it and inject variables into terraform via the command line. We did all this to manage multiple environments with varying parameters, and to manage the local state files for each (we stored remote state in Atlas). We had a Hashicorp guy come in, and he advised against this approach, and I didn't disagree with him but couldn't see an alternative. I kind of wish I gave the approach I'm asking about today a whirl (didn't cross my mind, perhaps I forgot Terraform supports JSON as well as HCL).
But why not? Something like the following sounds eminently sensible:
Scripts/DSL -> Terraform JSON -> Infrastructure
The scripts are responsible for gathering all the 'data' (all those resources that aren't actually infrastructure, as per #4169), and all the work that necessitates the use of a fully expressive language. That can be control structures (loops, conditional statements), string manipulation functions, traversing data structures, lookups of external data, etc,. The generated Terraform JSON would forgo all of those features, leaving what would instead be a pure specification of your infrastructure. It would be massively redundant, and a wonderful bore to read, being nothing but a catalog of infrastructure components referencing one another. Variables and modules could possible be done away with too.
This isn't very different to how many people build CloudFormation templates. They use one of the myriad DSL's to generate the JSON. They do this because they have to; CloudFormation doesn't have counts or much in the way of string functions like Terraform does. But even if it did, I'm pretty sure those DSL's would continue to thrive, for all the reasons given above.