Amazon web services 如何避免使用securitygroups进行cloudformation循环引用?

Amazon web services 如何避免使用securitygroups进行cloudformation循环引用?,amazon-web-services,amazon-cloudformation,Amazon Web Services,Amazon Cloudformation,如何避免cloudformation模板之间的循环引用 例如,我的Web服务器上有一个模板,数据库实例上有另一个模板。模板数据库将如下所示: "Database": { "Type":"AWS::RDS::DBInstance", "Properties": { // lots of other props "VPCSecurityGroups": [ {"Ref":"DBSecurityGroup"} ] } }, "DBSecurityGroup" : {

如何避免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"}}]
  }
}

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

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


请参见位于

的示例代码片段,我知道如何单独使用SecurityGroupIngress。但我不明白它如何帮助我解决多模板问题?你介意解释一下吗?对不起,我误解了这个问题。一种方法是有3个模板,一个用于SGs的“根”,将它们作为参数传递给Web和DB模板。不用担心,我感谢您的努力。我考虑过这一点,但希望SecurityGroup与服务器位于同一个模板中,因为逻辑和规则紧密相连。所以我想出了一个不同的解决方案。SG标签。这很好。@deitch您能提供您提出的SG标记方法的详细信息吗?Thanks@gliptak对不起,已经四年了,我只是不记得了。我现在做的每件事都是在地形上进行的,而这只是为了基本的设置。