I know that you can test the syntactic correctness, but are their any tools/projects for automated testing of what gets outputted?
For example, a program we’re building uses CloudFormation templates to spin up a stack of instances/security/etc. when triggered. Is there a good way to verify “This cloudFormation spins up X, Y and Z with these properties”?
You could use the various API endpoints to query the current state of AWS, but I’d say its not worth the effort. Do your QA while developing the template; manually checking that the expected steps are executed. Once you’re sure that the template works, fire and forget.
But… you’re the one who determines whether the setup is valid. I’m not sure how you could automatically validate it without building yet another template to check correctness, and you’d have to validate that template itself.
You’re better off building your template in pieces and testing as you go for correctness.
Any template where it isn’t blindingly obvious that it is correct (e.g. minimally it will be <1 page of json and totally comprehensibe) should probably not head to production.
The problem with wanting to test a cloudformation is inherently complex and wrong. The template can be parser validated, but +1 to what you said. For us the Cloudformation template remains dumb, and should stay that way. We QA the code for the different pieces, make the assumption the CF template is good, then QA the desired state.
ie. Make sure your code is tested, then keep the CF template simple, and have a good QA/UAT process for testing the environment. If your CF template does anything other than create the environment, you’ve got a huge problem.
+1. The CF should ONLY control how to make your pieces connect. Not responsible for any kind of business or code logic. QA the code and end result environment, not the infrastructure goop.
Right, the more I look at this, the more terrible of an idea it becomes. What I really want to do is make sure that if I pass in “smallStack” it builds 3 instances of certain amis in certain VPCs etc. (and “mediumStack” does another, and “largeStack” yet another) I was just hoping there were tools to help accelerate the odious task of hard wiring the test harness to go and find all these resources.
It looks like there’s no way to avoid recording the requirements twice (once in the template, and again in the tests).
And I’m definitely on board with that. Mostly my point was that it’s very easy for a CF template to go way over 1 page of json, even while keeping it light.
I hear you! I’m just the poor QE Dev who has multiple architects who don’t understand that Quality is the entire team’s job. So I’m handed solutions where no one trusts the tools and we need to “verify” that 3d party things work as advertised in an automated way.
I’ve stood up thousands of stacks, the most complex being a 5-LC config across 5 ASGs for cassandra (so they could be migrated to another AZ if necessary, which we ended up doing when the SSD instances became a thing).
My main takeaway is that cloudformation is awful and that the autoscale api should be the control layer, which is why I’ve taken the position I have above.
If you put logic into CFM you’re stuck with some terrible problems. E.g. Not every region has 3 AZs available at all times, but if you need to deploy a template that deals with a highly-available service you need to guarantee that you have e.g. 1 instance per AZ. Some regions launched with only 2 AZs, and us-east-1 has 5. Uggh. So you could go for one template and stack per AZ per region, but you run into limits in your CFM stack count quota - and when you get beyond the limit of 20 you can easily run into hard timeouts (the 5 minute upper bound) that amazon hasn’t fixed since CFM launched, and won’t fix it because this is only a developer tool.
So you’re suggesting I have my program call 3 different CF templates to build 3 different sizes of stacks that contain similar elements, but require marshaling in groups?
Basically, we’re building a service that allocates logging aggregation/compliance infrastructure on-demand for other development groups at a large tech company. We’re not even focusing on HA yet and our CF files are already more complicated than I would like.