Reputation: 13481
I´m using AWS CLI and CloudFormation, and I could not find any reference in the documentation.
Does anybody know if it´s possible to create a CloudFormation template from a current configuration.
Let´s say that I want to get a CloudFormation template from my current security group configuration.
Any idea if it´s possible to export that configuration as a template using CLI?
Upvotes: 48
Views: 38771
Reputation: 5868
Based on our experience we found 3 possible ways to translate existing manually deployed (from Web Console UI) AWS infra to Cloudformation (CF).
Using a new CloudFormation native introduced feature (since Nov 2019) that allows you to Import existing resources into a CloudFormation stack
Using aws cli
execute $aws service_name_here describe
for each element that make up your stack eg for RDS Database Stack:
Type: AWS::RDS::DBInstance
,Type: AWS::EC2::SecurityGroup
,Type: AWS::RDS::DBSubnetGroup
andType: AWS::RDS::DBParameterGroup
And manually translate to CF based on the outputs obtained from the aws cli
for each of the components. This approach usually requires more experience in both AWS and CF but the templates that you are creating can be structured and designed under good practices, fully parameterized (Sub, Ref, Join, Fn::GetAtt:, Fn::ImportValue
), modular, applying conditions
and in a 1st iteration the result would probably be close to the final state of the templates (interesting reference examples: https://github.com/widdix/aws-cf-templates/).
Extra points! :)
Related Article: https://medium.com/@exequiel.barrirero/aws-export-configuration-as-code-cloudformation-terraform-b1bca8949bca
Upvotes: 31
Reputation: 1577
I had some problems getting the tradidtional tools - mentioned above - working in our environment; we have a complicated API Gateway. Former2 didnt' find it at all (although seemed ideal for other resources)
I found another tool, "Terraformer" which extracts AWS into Terraform, which can then be turned into CloudFormation -or used directly as IaC.
https://github.com/GoogleCloudPlatform/terraformer#installation
Maybe that will work for others if the above tools don't.
Upvotes: 2
Reputation: 66109
In addition to CloudFormer, you might want to take a look at Bellerophon: https://github.com/arminhammer/bellerophon.
Upvotes: 6
Reputation: 3414
It's not possible using the AWS CLI but you can use the CloudFormer [1] tool to create a CloudFormation template from existing resources. I've had decent success with it. The templates aren't as "pretty" as hand-made templates but they provide a good starting point.
[1] http://aws.amazon.com/developertools/6460180344805680
Upvotes: 15