【问题标题】:How to avoid cloudformation circular reference with securitygroups?如何使用安全组避免 cloudformation 循环引用?
【发布时间】:2014-07-21 01:37:19
【问题描述】:

如何避免 cloudformation 模板之间的循环引用?

例如我的 Web 服务器有一个模板,我的数据库实例有另一个模板。模板数据库看起来像:

"Database": {
  "Type":"AWS::RDS::DBInstance",
  "Properties": {
     // lots of other props
     "VPCSecurityGroups": [ {"Ref":"DBSecurityGroup"} ]
  }
},
"DBSecurityGroup" : {
  "Type":"AWS::RDS::DBSecurityGroup",
  "Properties": {
    // lots of other props
    "SecurityGroupIngress": [{... "SourceSecurityGroupId":{"Ref":"WebSecurityGroup"}}]
  }
}

但在我的 Web 服务器模板中,我需要引用 DBSecurityGroup:

"WebServer": {
  "Type":"AWS::EC2::Instance",
  "Properties": {
     // lots of other props
     "SecurityGroups": [ {"Ref":"DBSecurityGroup"} ]
  }
},
"WebSecurityGroup" : {
  "Type":"AWS::EC2::SecurityGroup",
  "Properties": {
    // lots of other props
    "SecurityGroupEgress": [{... "SourceSecurityGroupId":{"Ref":"DBSecurityGroup"}}]
  }
}

如何避免模板之间的这些循环引用?

【问题讨论】:

    标签: amazon-web-services amazon-cloudformation


    【解决方案1】:

    使用单独的 AWS::EC2::SecurityGroupEgress 资源,而不是 SecurityGroupEgress 属性。

    http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/quickref-ec2.html#scenario-ec2-security-group-ingress查看示例 sn-p

    【讨论】:

    • 我知道如何单独使用SecurityGroupIngress。但我不明白它如何帮助我解决多模板问题?你介意解释一下吗?
    • 对不起,我误解了这个问题。一种方法是使用 3 个模板,一个用于 SG 的“根”,将它们作为参数传递给 Web 和 DB 模板。
    • 别担心,我很感激你的努力。我考虑过这一点,但希望 SecurityGroup 与服务器位于同一模板中,因为逻辑和规则紧密相关。所以我想出了一个不同的解决方案。 SG 标记。它很整洁。
    • @deitch 您能否提供有关您提出的 SG 标记方法的详细信息?谢谢
    • @gliptak 抱歉,已经四年了,我只是不记得了。我现在在 terraform 中做所有事情,并且仅用于基本设置。
    猜你喜欢
    • 1970-01-01
    • 2016-11-21
    • 1970-01-01
    • 2015-09-05
    • 2010-11-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多