Possible to 'export' current AWS configuration into CloudFormation format?

I spent a ton of time building up a set of ansible roles, playbooks, etc to create, initialize and provision AWS services for a project. Then, I read about CloudFormation. Doh.

I plan to use this configuration (or variations thereof) in future projects, so this is quite beneficial.

Is it possible to export the configuration of currently set up services via the AWS CLI/API? Would love to not have to figure out how to write it if I can just export.

Thanks.


Related discussions:

That’s what CloudFormer is for.

First, yes there is. http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/cfn-using-cloudformer.html

Second, what is your reason for switching from Ansible to CloudFormation? Personally, that seems like a downgrade.

Cloudformer is cool, but beware, it’ll pull your configuration exactly. You’ll have to still tweak it if you want to be able to iteratively deploy that template, to say, other regions.
Also, ymmv on getting it to download. I was never able to, but got far enough to copy+paste the template itself.

Hi, thanks for the reply!

I would have thought using ansible’s CloudFormation module (see http://docs.ansible.com/ansible/cloudformation_module.html) to spin up resources detail in a CloudFormation stack JSON config would be better than building up the custom ec2-related resource creation playbooks.

No?

Awesome, thanks!

Thanks for the feedback. I was already aware that it merely gives you a ‘starting’ point, not something immediately reusable. But great feedback and important to note!

Cloudformer works great for me. Good advice is to pre-tag all the stuff you want in the CFT and it will go much easier.

Look at terraform or troposphere to build configuration management of your infrastructure. I personally use troposphere, and haven’t found it to be lacking yet.

I mean, there is no harm in doing that, but it seems like if you already did the work in Ansible, there isn’t much to gain by switching over to CloudFormation. This is just my opinion, but I find Ansible code to be simpler and easier to read.

For provisioning resources into AWS, CloudFormation is a HUGE HUGE HUUUUUUUGE upgrade for a few reasons:

  • Rollback is provided for free,
  • You don’t have to muck with jinja2 (which, if your roles/playbooks get sufficiently complicated, you will need to do eventually), and
  • Stacks are grouped logically, so anything missing from the stack can get rebuilt during an update and any failures will revert the stack.

I hate dealing with the JSON, but I love not having to worry (as much) about provisioning things. Configuration, on the other hand, is something I leave to Ansible.

terraforming (https://github.com/dtan4/terraforming) is something you can use to import existing resources into Terraform, as well.

Fair enough - after using CloudFormer and seeing the output… I’d tend to agree on its legibility compared to ansible playbooks. :slight_smile:

I’m pretty used to jinja2 at this point, but the other points are valid. Maybe I should take another look. Its been a while since I have used CloudFormation.

Good feedback, thanks. As has been mentioned elsewhere, I’ve already got my stack working with custom Ansible playbooks, so there’s little to gain from switching to CF JSON, would you agree?

That depends on your workflow. I could see strong case for and against using either but it again depends on your situation, team, experience, infrastructure as a whole.

I’ve found using both to be beneficial seeing Ansible can retrieve a lot of information about your VPC from the up and coming facts modules. It doesn’t yet support all resources, but there is a lot of work being done in that area at the moment. See ansible/modules-extras PR for examples.

Cloudformation outputs are required for passing state between stacks which can be cumbersome. I submitted a PR for a cloudformation resource/output and parameters lookup plugin and have found it useful. Turns out it’s the wrong way to implement getting this information, should be written as a facts module to take advantage of the ec2 module available with Ansible. Takes care of Assuming roles and authentication issues.

At the moment you might not think so but as your playbook becomes more and more complex, you might think otherwise. I thought Ansible was the way to go as well until I started needing to mess with really complicated security groups and laborious EC2 configurations. Using CloudFormation really simplified those things for me.

visualops as well :wink: free trial!

We write ansible to create our cloudformation stacks, have you seen cfndsl? it’s the tool we use to achieve this: https://github.com/stevenjack/cfndsl

We have been using the cloudformation module for a while and I think it really is the best combination. We had most of our provisioning in ansible alone, but it ended up being much more manageable using cloudformation. Using both together allows us to implement additional checks, pre-cloudfront update backups / snapshots, etc. as part of the provision update process when we need to make modifications to a cloudformation stack. And after provisioning, using ansible for the builds and deployments (via CodeDeploy).