I´m using AWS CLI and cloudformation, and I could not find any reference in the documentation.
Anybody knows if it´s possible create a cloudformation template from a current configuration.
Let´s say that I want to get a cloudformation templates from my current security group configuration.
Any idea if it´s possible export that configuration as a template using command line?
Regards.
Based on our experience we found 2 possible ways to translate existing manually deployed (from Web Console UI) AWS infra to Cloudformation (CF).
- Using
aws cliexecute$aws service_name_here describefor each element that make up your stack eg for RDS Database Stack:- RDS Instance ->
Type: AWS::RDS::DBInstance, - RDS (EC2) SG ->
Type: AWS::EC2::SecurityGroup, - RDS Subnet Group ->
Type: AWS::RDS::DBSubnetGroupand - RDS DB Param Group ->
Type: AWS::RDS::DBParameterGroup
- RDS Instance ->
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/).
- Using AWS CloudFormer:
- https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/cfn-using-cloudformer.html
- http://www.tothenew.com/blog/using-aws-cloudformer-to-create-template-of-existing-infrastructure
- NOTE: The resulting templates are not as "neat" as those developed manually under the approach (1), they will have all the IDs and values hard-coded and perhaps the structure of it will not follow the convention that you use for your CF templates, but of course it will provide a good starting point.
Extra points! :)
Using Terraforming (https://github.com/dtan4/terraforming). Considering the new version of Terraform
0.12.0-beta2(already supported in stable release byterraform-provider-aws 2.7.0), with new features and its more friendly syntax, and without ignoring that it is an open source tool and cloud-provider agnostic, I would no dismiss the possibility of generating Terraform code based on existing AWS infra, if possible under the form of modules and sub-modules having as reference -> https://registry.terraform.io/ as an alternative to AWS CF.Some other new alternatives to export your current deployed AWS infra to Cloudformation / Terraform code:
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.
In addition to CloudFormer, you might want to take a look at Bellerophon: https://github.com/arminhammer/bellerophon.
来源:https://stackoverflow.com/questions/38057526/aws-export-configuration-as-cloudformation-template