AWS Export配置为cloudformation模板 [英] AWS Export configuration as cloudformation template

查看:78
本文介绍了AWS Export配置为cloudformation模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用AWS CLI和cloudformation,但是我在文档中找不到任何参考。

I´m using AWS CLI and cloudformation, and I could not find any reference in the documentation.

任何人都知道是否有可能通过以下方式创建cloudformation模板:

Anybody knows if it´s possible create a cloudformation template from a current configuration.

假设我想从当前安全组配置中获取cloudformation模板。

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?

问候。

推荐答案

根据我们的经验,我们发现了3种可能的方法将现有的手动部署(从Web控制台UI)的AWS infra转换为Cloudformation(CF)。

Based on our experience we found 3 possible ways to translate existing manually deployed (from Web Console UI) AWS infra to Cloudformation (CF).


  1. 使用新的CloudFormaiton本机引入的功能(自2019年11月开始),该功能允许将现有资源导入CloudFormation堆栈以获取更多信息,请检查-> https://aws.amazon.com/blogs / aws / new-import-existing-resources-to-a-cloudformation-stack /

使用 aws cli 对组成堆栈的每个元素执行 $ aws service_name_here描述,例如 RDS数据库堆栈

Using aws cli execute $aws service_name_here describe for each element that make up your stack eg for RDS Database Stack:


  • RDS实例-> 类型:AWS :: RDS :: DBInstance

  • RDS(EC2)SG-> 类型:AWS :: EC2 :: SecurityGroup

  • RDS子网组-> 类型:AWS :: RDS :: DBSubnetGroup

  • RDS数据库参数组-> 类型: AWS :: RDS :: DBParameterGroup

  • RDS Instance -> Type: AWS::RDS::DBInstance,
  • RDS (EC2) SG -> Type: AWS::EC2::SecurityGroup,
  • RDS Subnet Group -> Type: AWS::RDS::DBSubnetGroup and
  • RDS DB Param Group -> Type: AWS::RDS::DBParameterGroup

并根据每个组件从 aws cli 获得的输出手动转换为CF 。这种方法通常需要在AWS和CF方面都有更多的经验,但是您可以在良好实践的基础上对要创建的模板进行结构化和设计,并对其进行完全参数化( Sub,Ref,Join,Fn :: GetAtt:,Fn: :ImportValue ),模块化,应用 conditions ,在第一次迭代中,结果可能接近模板的最终状态(有趣的参考示例: https://github.com/widdix/aws-cf-templates/ )。

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/).


  1. 使用 AWS CloudFormer

  1. 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.

加分! :)


  1. 使用 Terraforming https://github.com/dtan4/terraforming )。考虑新版本的Terraform 0.12.0-beta2 terraform-provider-aws 2.7.0 ),具有新功能及其更友好的语法,并且在不忽略它是一个开源工具且与云提供商无关的情况下,如果有可能,我绝不会拒绝基于现有AWS基础设施生成Terraform代码的可能性,形式如下作为参考的模块和子模块-> https://registry.terraform.io/ 作为

  1. Using Terraforming (https://github.com/dtan4/terraforming). Considering the new version of Terraform 0.12.0-beta2 (already supported in stable release by terraform-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.

一些其他新的替代方法,可以将当前已部署的AWS基础设施导出到Cloudformation / Terraform代码中:

Some other new alternatives to export your current deployed AWS infra to Cloudformation / Terraform code:

  • https://former2.com
  • https://modules.tf






相关文章: https://medium.com /@exequiel.barrirero/aws-export-configuration-as-code-cloudformation-terraform-b​​1bca8949bca

这篇关于AWS Export配置为cloudformation模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆