[英]how do I implement if condition in my cloudformation stack
我的堆栈环境和iamprofileName中有两个属性。 如果我选择非产品环境之一,即“ use1dev”,“ use1qa”。 我应该将MyPlatformEC2NonProd作为“ IAMProfileName”中的默认值
如果选择产品环境之一,即“ useProd1”,“ useProd2”。我必须在“ IAMProfileName”中获取MyPlatformEC2Prod作为默认值。
我该如何实现
"Environment" : {
"Description" : "Environment being deployed to - use1dev, use1qa,
use1sbox etc",
"Type" : "String",
"Default" : "use1sbox",
"AllowedValues" : ["use1dev","use1qa","useProd1","useProd2"]
},
"IAMProfileName" : {
"Default" : "MyPlatformEC2",
"Type" : "String",
"Description" : "Name of IAM profile to attach to created
machines",
"AllowedValues" : ["MyPlatformEC2","MyPlatformEC2NonProd"]
使用CloudFormation条件。 例如,在您的情况下,我将执行以下操作:
Conditions:
"ProdProfileCondition": {
"Fn::Or": [
{"Fn::Equals": ["useProd1", {"Ref": "Environment"}]},
{"Fn::Equals": ["useProd2", {"Ref": "Environment"}]},
]
}
现在,无论您想在哪里使用IAMProfileName值,都可以使用如下所示的内容,
SomeAWSResource:
Properties:
"ProfileName" : [{
"Fn::If" : [
"ProdProfileCondition",
{"Ref" : "MyPlatformEC2"},
{"Ref" : "MyPlatformEC2NonProd"}
]
}]
有关如何使用条件句的更多信息,请查看以下链接。
另外,您可以使用Jinja实现更复杂的条件,只需创建一个模板并根据条件填充值即可。 但我不会对此进行详细介绍,因为您的需求已经可以通过此方式实现。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.