After reading people saying good things about troposphere on here I gave it a try. I’m finding it more awkward than writing cloudformation templates as JSON.
Cloudformation JSON format is extremely well documented by Amazon. Apart from a few incomplete examples troposphere seems entirely undocumented. Normal things like creating an Instance Role with some inline policies seem unreasonably difficult.
Troposphere as an idea is brilliant. The current implementation seems awkward beyond use for any stacks that contain non-trivial resources. Has anyone considered a better approach to this? Maybe the m4 macro preprocessor or a makefile?
Troposphere reminds me of the Mitch Hedberg joke: That Pepperidge Farms bread is fancy man: it’s wrapped twice. I don’t like it though. It’s one more step between me and toast.
The thing is I really like the idea of cloudformation. I don’t want to put the same data in a propriety format in yet another tool that only exposes 80% or so of what cloudformation can do. Plus my configuration management tooling is utterly dependant on cloudformation metadata.
The ability to orchestrate changes between multiple clouds does sound really good though.
Documentation is definitely lacking in troposphere. Where I see real value in it though is in the ability to add logic, which is severely lacking in pure CF.
What kind of logic do you mean? I setup autoscaling groups of variable size in cloudformation all the time. I use conditionals to only specific IOPS for provisioned IOs all the time.
You can do all kinds of weird stuff with conditionals too like only creating resources if certain conditions are met. I know that exists but I’ve never had a need to do it.
What do you do that Conditionals don’t cover? If is it simply a matter that doing it in python is easier?
Primarily for loops, lookups of latest Ami versions, conversions of block device mapping to add volumes appropriately, better ways to interpret comma separated parameters for things like security groups, etc.
Troposphere’s value comes into play when you need to dynamically create a template. For example to my knowledge when making a new SNS topic, you have to hard code the number of subscriptions (the count, not the methods and subscriptions addresses themselves). If I want to reuse the template for another new topic, but I want to subscribe three entities instead of two, I’d have to change the template, which defeats the purpose of making a reusable template.
JSON quickly becomes a nightmare to maintain compared to good code, especially if you have complex cloud init scripts. Embedding scripts in JSON is super messy. You get into this Fn::Join/newline/quote hell that could be avoided by generating the template with code.
I’ve only briefly used Troposphere, but it was when I was first starting up with CF templates and I decided to just do the JSON. I suspect that this was a bad decision.
Edit: if troposphere isn’t up to the task, you could always just write your own custom JSON generator.
Disclaimer: I’m experienced with cfn_pyplates and cfndsl, but I investigated troposphere.
While the CFN DSLs have some documentation gaps, they are generally acting as a direct representation of CFN template elements as class methods. They aren’t rocket surgery - once you figure out how parameters / resources / outputs / implicit functions are defined, they are very straightforward (even for “complicated” CFN JSON shenanigans).
I’m curious what problems you’re running into. But yes I’ve noticed that I’ve had to dig into the source code for pyplates and cfndsl to figure out HOW they were implementing something, so I could generate the JSON I wanted.
I was trying to create a IAM role for instances that contained a few policies. That’s pretty easy in JSON. Following the troposhere examples it turned into a mess of awacs and troposphere calls that made JSON look like a pretty thing in comparison. The only documentation I had was the examples and they contain commented out chunks and notes that say things don’t work.
Both cfn_pyplates and cfndsl look like interesting things. I’ll try them out.
To tag along on this, we have used Troposphere to build a composable bundle system to generate really complex templates with a set of best practices without having to really worry about the complexities that go into each of the elements. Want route53 that adds a param to your template and maps to an ELB? One line of code. Custom lambda backed resources that pull info from other stacks by name? One line of code. ElastiCache, AuroraDB, etc. One line of code.
That said, if you aren’t building and managing a couple templates a day, certainly not worth the level of work it takes to create, document and manage something like this. One of the biggest wins we get from this is being able to make a change in a single bundle and roll it across dozens of templates with a single command to rebuild all the templates depending on that bundle.
Here’s an example using the system that builds an EC2 Container Service cluster with lambda based autoscalers, ElastiCache, Aurora, and hooking to EFS. Minus a few settings blocks and import statements, this generates a 1500 or so line template that is running a few clusters in production right now.