Reputation: 4582
My CloudFormation conditions are not being evaluated correctly when I set multiple conditions on resources.
I've created a modular CodePipeline template to allow deploying with or without a database. I've placed multiple conditions on some key resources.
Conditions:
HasDatabase: !Equals [ !Ref HasDatabase, true ]
IsECS: !Equals [ !Ref IsECS, true ]
Resources:
MyFakeBucket:
Type: AWS::S3::Bucket
Condition: IsECS
Condition: HasDatabase
I'm expecting MyFakeBucket to be created when BOTH conditions evaluate to true, however it's created when EITHER are.
Upvotes: 1
Views: 306
Reputation: 4582
My solution was to create new conditions that were combinations on existing ones:
Conditions:
HasDatabase: !Equals [ !Ref HasDatabase, true ]
IsECS: !Equals [ !Ref IsECS, true ]
ECSNoDB: !And
- !Condition NoDatabase
- !Condition IsECS
ECSDB: !And
- !Condition HasDatabase
- !Condition IsECS
Now my resources looks like this:
Resources:
MyFakeBucket:
Type: AWS::S3::Bucket
Condition: ECSDB
Upvotes: 2