Show HN: cfnlite - a simple and sensible CloudFormation generator
github.comTL;DR cfnlite is yet another YAML based config file format, but its the last one, I promise. <insert-relevant-xkcd> I wanted to create a CloudFormation generator with a simple interface and better devUX.
Longer version: So I've recently found myself in a somewhat low code team which is pretty adamant on using CloudFormation for all IaC (we're all in on AWS). My background is mostly in building on-prem data centres and realtime video, so I'd never worked on "the cloud" before now. So, I spent the first two weeks speed running AWS basics and then another two weeks looking into IaC, mostly writing CFN.
Very quickly I realised that working with raw CloudFormation is an PITA. I tried everything to create sensible, reusable, modularised templates - you know the kind of ideals most of our other code is built on - but it just become a pile of parameterised garbage.
Anyways, I then discovered all the options for imperative IaC (CDK, troposphere etc), and had a mess about with those. Heres a hot take: I actually think YAML is better than most of the imperative stuff for at-a-glance debugging/understanding. Regardless, I knew for sure the team was never going to agree with using any of that (they said so lol).
So I decided to build a little library for myself so that I could at least generate CFN for my own work. One thing lead to the other and I decided I could make some kind of CLI tool that takes a small config file and generates the CFN. That way, I wouldn't even need to write custom CDK code for each new CFN template I wanted to make.
And thus the beginnings of cfnlite was born. It kind of started with a series of "What if..." type questions: - What if I could generate CFN from a small config, what would that config look like? - What if I didn't have to actually remember what CFN calls each type of resource? - What if it gave me all the required fields with some defaults? - What if I could validate types without needing to run the template? - what if the library could resolve dependecies and do all the !Ref/DependsOn stuff? - What if it had loops and simple ternary conditions? (haven't answered this one yet)
After a while I realised I could create something in a language agnostic interface, an interface that the team already knew but would also hugely simplify mine - and hopefully my teams lives. I'm also a compiler nerd so I was never going to let the chance to write a code generator pass-up.
I recognise to most I've just recreated a shoddy terraform (although this tool is heavily inspired by Ansible, my fav YAML based IaC) that nobody else will probably ever use but within my constraints, it solved a real problem and more importantly, has been super fun to work on.
How it works
Its basically a wrapper around troposphere: - yaml config comes in, it gets parsed - cfnlite builds a dependancy tree based on ref's and DependsOn - maps user input to troposphere objects for each resource (most of the logic is here) - spits out the template to stdout or a file