Skip to content

Commit 371e8da

Browse files
authored
fix(cfn-include): short form for Condition (#9865)
Add YAML support for the short form of Condition: `!Condition`. fixes #9785 ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 7ec598e commit 371e8da

File tree

3 files changed

+64
-0
lines changed

3 files changed

+64
-0
lines changed

packages/@aws-cdk/cloudformation-include/lib/file-utils.ts

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ const shortForms: yaml_types.Schema.CustomTag[] = [
3535
'Select', 'Split', 'Transform', 'And', 'Equals', 'If', 'Not', 'Or',
3636
].map(name => makeTagForCfnIntrinsic(name)).concat(
3737
makeTagForCfnIntrinsic('Ref', false),
38+
makeTagForCfnIntrinsic('Condition', false),
3839
makeTagForCfnIntrinsic('GetAtt', true, (_doc: yaml.Document, cstNode: yaml_cst.CST.Node): any => {
3940
// The position of the leftmost period and opening bracket tell us what syntax is being used
4041
// If no brackets are found, then the dot notation is being used; the leftmost dot separates the
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
Conditions:
2+
AlwaysTrueCond:
3+
!Not [ !Equals [ !Ref "AWS::Region", completely-made-up-region1 ] ]
4+
AnotherAlwaysTrueCond:
5+
!Not [ !Equals [ !Ref "AWS::Region", completely-made-up-region2 ] ]
6+
ThirdAlwaysTrueCond:
7+
!Not [ !Equals [ !Ref "AWS::Region", completely-made-up-region3 ] ]
8+
CombinedCond:
9+
!Or [!Condition AlwaysTrueCond, !Condition AnotherAlwaysTrueCond, !Condition ThirdAlwaysTrueCond]
10+
Resources:
11+
Bucket:
12+
Type: AWS::S3::Bucket
13+
Properties:
14+
BucketName:
15+
!If
16+
- CombinedCond
17+
- MyBucketName
18+
- !Ref AWS::NoValue

packages/@aws-cdk/cloudformation-include/test/yaml-templates.test.ts

+45
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,51 @@ describe('CDK Include', () => {
316316
});
317317
});
318318

319+
test('can ingest a template with the short form Conditions', () => {
320+
includeTestTemplate(stack, 'short-form-conditions.yaml');
321+
322+
expect(stack).toMatchTemplate({
323+
"Conditions": {
324+
"AlwaysTrueCond": {
325+
"Fn::Not": [
326+
{ "Fn::Equals": [{ "Ref": "AWS::Region" }, "completely-made-up-region1"] },
327+
],
328+
},
329+
"AnotherAlwaysTrueCond": {
330+
"Fn::Not": [
331+
{ "Fn::Equals": [{ "Ref": "AWS::Region" }, "completely-made-up-region2"] },
332+
],
333+
},
334+
"ThirdAlwaysTrueCond": {
335+
"Fn::Not": [
336+
{ "Fn::Equals": [{ "Ref": "AWS::Region" }, "completely-made-up-region3"] },
337+
],
338+
},
339+
"CombinedCond": {
340+
"Fn::Or": [
341+
{ "Condition": "AlwaysTrueCond" },
342+
{ "Condition": "AnotherAlwaysTrueCond" },
343+
{ "Condition": "ThirdAlwaysTrueCond" },
344+
],
345+
},
346+
},
347+
"Resources": {
348+
"Bucket": {
349+
"Type": "AWS::S3::Bucket",
350+
"Properties": {
351+
"BucketName": {
352+
"Fn::If": [
353+
"CombinedCond",
354+
"MyBucketName",
355+
{ "Ref": "AWS::NoValue" },
356+
],
357+
},
358+
},
359+
},
360+
},
361+
});
362+
});
363+
319364
test('can ingest a yaml with long-form functions and output it unchanged', () => {
320365
includeTestTemplate(stack, 'long-form-subnet.yaml');
321366

0 commit comments

Comments
 (0)