将 AWS 配置导出为 CloudFormation 模板

Export AWS configuration as CloudFormation template

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

有谁知道是否可以从当前配置创建 CloudFormation 模板。

假设我想从我当前的安全组配置中获取一个 CloudFormation 模板。

知道是否可以使用 CLI 将该配置导出为模板吗?

无法使用 AWS CLI,但您可以使用 CloudFormer [1] 工具从现有资源创建 CloudFormation 模板。我已经取得了不错的成功。这些模板不像手工制作的模板那样"pretty",但它们提供了一个很好的起点。

[1] http://aws.amazon.com/developertools/6460180344805680

除了 CloudFormer,您可能还想看看 Bellerophon:https://github.com/arminhammer/bellerophon

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

  1. 使用 CloudFormation 本机引入的新功能(自 2019 年 11 月起),允许您Import existing resources into a CloudFormation stack

  2. 使用 aws cli 对构成堆栈的每个元素执行 $aws service_name_here describe 例如 RDS 数据库堆栈:

  • RDS 实例 -> Type: AWS::RDS::DBInstance,
  • RDS (EC2) SG -> Type: AWS::EC2::SecurityGroup,
  • RDS 子网组 -> Type: AWS::RDS::DBSubnetGroup
  • RDS 数据库参数组 -> Type: AWS::RDS::DBParameterGroup

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

  1. 使用 AWS CloudFormer:

加分! :)

  1. 使用 Terraforminghttps://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/ 作为 AWS CF 的替代品。

  2. 将当前部署的 AWS 基础设施导出到 Cloudformation / Terraform 代码的其他一些新方法:


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

我在使用上述传统工具在我们的环境中工作时遇到了一些问题;我们有一个复杂的 API 网关。 Former2 根本没有找到它(尽管对于其他资源来说似乎很理想)

我找到了另一个工具“Terraformer”,它将 AWS 提取到 Terraform 中,然后可以将其转换为 CloudFormation - 或者直接用作 IaC。

https://github.com/GoogleCloudPlatform/terraformer#installation

如果上述工具不起作用,也许这对其他人有用。