2014-07-20 16 views
2

如何避免云形成模板之间的循环引用?如何避免使用安全组的云信息循环引用?

E.g.我有一个模板与我的Web服务器,另一个与我的数据库实例。模板DB将乐,如:

"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"}}] 
    } 
} 

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

回答

0

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

看到http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/quickref-ec2.html#scenario-ec2-security-group-ingress

+0

我知道如何分开使用SecurityGroupIngress一个例子片断。但我不明白它是如何帮助我解决多个模板问题?你介意解释一下吗? – deitch

+0

对不起,我误解了这个问题。一种方法是使用3个模板,一个用于SG的“根”,将它们作为参数传递给Web和DB模板。 –

+0

不用担心,我很欣赏这种努力。我想到了这一点,但希望SecurityGroup与服务器在同一模板中,因为逻辑和规则紧密相关。所以我想出了一个不同的解决方案。 SG标签。它非常整齐。 – deitch