Multiple conditions in cloud formation resource creation
Try adding
"MyCondition": {"Fn::Or": [{"Condition": "LinuxPlatform"}, {"Condition": "BothPlatform" }]}
to the bottom of your Conditions
like that:
"Conditions" : {
"LinuxPlatform" : {"Fn::Equals" : [{"Ref" : "Platform"}, "linux"]},
"WindowsPlatform" : {"Fn::Equals" : [{"Ref" : "Platform"}, "windows"]},
"BothPlatform" : {"Fn::Equals" : [{"Ref" : "Platform"}, "both"]},
"MyCondition": {"Fn::Or": [{"Condition": "LinuxPlatform"}, {"Condition": "BothPlatform" }]}
},
I was looking for the same thing with different scenarios in the YAML format. Below is the YAML format for the reference.
CreateResources: !Or [!Equals [!Ref "Environment", prod], !Equals [!Ref "Environment", dev], !Equals [!Ref "Environment", preprod], !Equals [!Ref "Environment", test]]
example
---
AWSTemplateFormatVersion: 2010-09-09
Description: 'AWS cloudformation template bucket. '
Parameters:
Environment:
Description: Enter the environmet name from allowed values
Type: String
AllowedValues:
- qa
- dev
- prod
- stage
Conditions:
Prod: !Equals [ !Ref Environment, production]
dev: !Equals [ !Ref Environment, dev]
stage: !Equals [ !Ref Environment, stage]
qa: !Equals [ !Ref Environment, qa]
CreateResources: !Or [!Equals [!Ref "Environment", prod], !Equals [!Ref "Environment", dev], !Equals [!Ref "Environment", preprod], !Equals [!Ref "Environment", test]]
Resources:
RenderEngineEFSSG:
Type: AWS::EC2::SecurityGroup
Condition: CreateResources
Properties:
GroupDescription: test SG.
GroupName: !Join [ "-", [ !Ref Environment, sgname ] ]
VpcId: vpc-0e4d5cad992b8d65b
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: 2049
ToPort: 2049
CidrIp: 0.0.0.0/0
Description: Ingress Rule for Lambda to access EFS.
SecurityGroupEgress: []