I'm trying to set up a build pipeline for a web service in AWS. The plan is to have the service run in an Auto Scale Group, and use Jenkins to build a one off EC2 instance, run tests and, on success, image the instance and pass it on to the existing Auto Scale Group.
To create all the necessary resources for this, I've created two CloudFormation templates, one to build the Autoscale Group and surrounding resources, and one to build a one off testable instance.
I've noticed a problem with this though: There are different base images for each region and each EC2 Instance Type. This means, Jenkins needs to know the region and Instance Type to build for.
The ideal solution would be a way of selecting the target CloudFormation stack, and pulling the information (region, instance type, etc) from there. This means if we make any changes to the Auto Scale Group, they would automatically be reflected in the Jenkins build. If we created a second Group, we can copy the Jenkins job and change one parameter to point it at the new Stack. But this doesn't seem to be an option...
These are the potential solutions I can think of but I don't particularly like any of them:
Hard code this information in both templates
This goes against the idea of having CF templates, since I'd ideally like to keep these things flexible.Send the information to an API, then have Jenkins look it up
This is quite a lot of extra work as I have to build and maintain a machine just to store a couple of variables. Not to mention, I'm not sure I can output the information to an API from the script, so would have to wrap it in another script to be take the information from the AWS CLI tool.Categorise the final image
I could allow flexability in all parameters and then categorized the finalised image by those parameters. Then I can make sure the Auto Scale Group only loads images with the correct parameters. This would prevent using an incorrect base image but could result in building with the wrong information (if we change one we must remember to change the other).
It feels like what I want to do shouldn't be that hard but I can't work out the best way to do it.