简体   繁体   English

如何组织成云模板?

[英]How to organize cloud formation template?

What is the best practice to organize the Cloud Formation templates?组织 Cloud Formation 模板的最佳做法是什么?

For example, imagine that I have a security group that is shared between my other projects.例如,假设我有一个在其他项目之间共享的安全组。 (Eg a sg that only accepts connection on port 80 e 22). (例如,只接受端口 80 e 22 上的连接的 sg)。

Is it a best practice maintain a SG for each project?为每个项目维护一个 SG 是最佳实践吗? OR create a single cloud formation template that only manages SG?还是创建一个仅管理 SG 的单一云形成模板?

Whether to share security groups between projects is a trade off between simplicity and isolation.是否在项目之间共享安全组是简单和隔离之间的权衡。 Having one security group shared between projects allows you to have smaller templates for each project, and to administer them together.在项目之间共享一个安全组允许您为每个项目拥有更小的模板,并一起管理它们。 Having one per stack allows you to change settings for one project without affecting others.每个堆栈一个允许您更改一个项目的设置而不会影响其他项目。

I prefer to have a small number of security groups shared across projects.我更喜欢跨项目共享少量安全组。 I put them in a CloudFormation stack for resources shared across the account.我将它们放在 CloudFormation 堆栈中,用于跨帐户共享的资源。 It includes stuff like:它包括以下内容:

  • EC2 security groups (I have one for SSH only access and one for SSH and HTTP/HTTPS) EC2 安全组(我有一个用于 SSH 仅访问,一个用于 SSH 和 HTTP/HTTPS)
  • a VPC with subnets, routing, gateways具有子网、路由、网关的 VPC
  • an S3 bucket, since many AWS resources require resources in S3 for initialization一个 S3 存储桶,因为许多 AWS 资源需要 S3 中的资源进行初始化
  • IAM roles and policies IAM 角色和策略
  • an SNS topic for alarms用于警报的 SNS 主题
  • CloudTrail configuration CloudTrail 配置

This stack is depended on by everything else and maintained separately.这个堆栈依赖于其他所有东西并单独维护。 When I create a project template, the outputs from the global stack are passed in as parameters.当我创建项目模板时,全局堆栈的输出作为参数传入。

A good resource is the AWS CloudFormation Best Practices [1] guide. AWS CloudFormation 最佳实践 [1] 指南是一个很好的资源。

It is best to create nested stacks as described on that page.最好按照该页面上的说明创建嵌套堆栈。 A security group that is used by multiple projects should exist in a lower-level stack probably along with the VPC, subnets, and routes.多个项目使用的安全组应该与 VPC、子网和路由一起存在于较低级别的堆栈中。 Projects can exist in higher-level stacks that build upon the resources described in the lower stacks.项目可以存在于更高级别的堆栈中,这些堆栈建立在较低堆栈中描述的资源之上。 To help determine this consider the lifecycle of each resource - can resource X exist without resource Y?为了帮助确定这一点,请考虑每个资源的生命周期——资源 X 可以在没有资源 Y 的情况下存在吗? If not, then resource X should probably be defined in a lower-level stack.如果不是,那么资源 X 可能应该在较低级别的堆栈中定义。

If you have multiple teams that's a consideration, too.如果您有多个团队,这也是一个考虑因素。 Your security/network team may need access to resources that the DevOps team does not need.您的安全/网络团队可能需要访问 DevOps 团队不需要的资源。

[1] http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/best-practices.html [1] http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/best-practices.html

Specifically regarding the security groups, it is best to isolate them as much as possible.特别是对于安全组,最好尽可能地隔离它们。

A good example to showcase the risk of having a shared security group would be:展示拥有共享安全组的风险的一个很好的例子是:

Let's assume your Dev and Prod environments share a security group.假设您的 Dev 和 Prod 环境共享一个安全组。 In order to troubleshoot something, you open an insecure port.为了排除故障,您打开了一个不安全的端口。 But this will automatically open your Prod environment too to a huge security risk.但这也会自动打开您的 Prod 环境,从而面临巨大的安全风险。

You can organize your templates with nested stacks and external parameter files.您可以使用嵌套堆栈和外部参数文件来组织模板。 Then you have the flexibility easily add/remove resources as well as replicate the stack in multiple environments just by changing the parameter file:然后,您只需更改参数文件即可灵活地轻松添加/删除资源以及在多个环境中复制堆栈:

You can find more details in the following blog post and the corresponding Git repository.您可以在以下博客文章和相应的 Git 存储库中找到更多详细信息。

https://medium.com/cloud-life/organize-cloudformation-templates-with-external-parameters-file-7998098f1b8d https://medium.com/cloud-life/organize-cloudformation-templates-with-external-parameters-file-7998098f1b8d

https://github.com/thilinaba/eks-cloudformation https://github.com/thilinaba/eks-cloudformation

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM