Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cfn-include): add support for the Fn::Sub function (#9275)
---- Closes #9228 *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
- Loading branch information
Showing
21 changed files
with
415 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
packages/@aws-cdk/cloudformation-include/test/test-templates/fn-sub-brace-edges.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
{ | ||
"Resources": { | ||
"Bucket": { | ||
"Type": "Custom::ManyStrings", | ||
"Properties": { | ||
"SymbolsOnly": { | ||
"DollarSign": { | ||
"Fn::Sub": "$" | ||
}, | ||
"OpeningBrace": { | ||
"Fn::Sub": "{" | ||
}, | ||
"ClosingBrace": { | ||
"Fn::Sub": "}" | ||
}, | ||
"DollarOpeningBrace": { | ||
"Fn::Sub": "${" | ||
}, | ||
"DollarClosingBrace": { | ||
"Fn::Sub": "$}" | ||
}, | ||
"OpeningBraceDollar": { | ||
"Fn::Sub": "{$" | ||
}, | ||
"ClosingBraceDollar": { | ||
"Fn::Sub": "}$" | ||
} | ||
}, | ||
"SymbolsAndResources": { | ||
"DollarSign": { | ||
"Fn::Sub": "DoesNotExist$DoesNotExist" | ||
}, | ||
"OpeningBrace": { | ||
"Fn::Sub": "DoesNotExist{DoesNotExist" | ||
}, | ||
"ClosingBrace": { | ||
"Fn::Sub": "DoesNotExist}DoesNotExist" | ||
}, | ||
"DollarOpeningBrace": { | ||
"Fn::Sub": "DoesNotExist${DoesNotExist" | ||
}, | ||
"DollarClosingBrace": { | ||
"Fn::Sub": "DoesNotExist$}DoesNotExist" | ||
}, | ||
"OpeningBraceDollar": { | ||
"Fn::Sub": "DoesNotExist{$DoesNotExist" | ||
}, | ||
"ClosingBraceDollar": { | ||
"Fn::Sub": "DoesNotExist}$DoesNotExist" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
packages/@aws-cdk/cloudformation-include/test/test-templates/fn-sub-escaping.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"Resources": { | ||
"Bucket": { | ||
"Type": "AWS::S3::Bucket", | ||
"Properties": { | ||
"BucketName": { "Fn::Sub": "some-bucket${!AWS::AccountId}7896${ ! DoesNotExist}${!Immediate}234" } | ||
} | ||
} | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
...ges/@aws-cdk/cloudformation-include/test/test-templates/fn-sub-map-dotted-attributes.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"Resources": { | ||
"Bucket": { | ||
"Type": "AWS::S3::Bucket", | ||
"Properties": { | ||
"BucketName": { | ||
"Fn::Sub": "${ELB.SourceSecurityGroup.GroupName}" | ||
} | ||
} | ||
}, | ||
"ELB": { | ||
"Type": "AWS::ElasticLoadBalancing::LoadBalancer", | ||
"Properties": { | ||
"AvailabilityZones": [ | ||
"us-east-1a" | ||
], | ||
"Listeners": [{ | ||
"LoadBalancerPort": "80", | ||
"InstancePort": "80", | ||
"Protocol": "HTTP" | ||
}] | ||
} | ||
} | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
packages/@aws-cdk/cloudformation-include/test/test-templates/fn-sub-override.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"Resources": { | ||
"Bucket": { | ||
"Type": "AWS::S3::Bucket", | ||
"Properties": { | ||
"BucketName": "bucket" | ||
} | ||
}, | ||
"AnotherBucket": { | ||
"Type": "AWS::S3::Bucket", | ||
"Properties": { | ||
"BucketName": { "Fn::Sub": "${Bucket}-${!Bucket}-${Bucket.DomainName}" } | ||
} | ||
} | ||
} | ||
} |
Empty file.
20 changes: 20 additions & 0 deletions
20
packages/@aws-cdk/cloudformation-include/test/test-templates/fn-sub-shadow-attribute.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"Resources": { | ||
"Bucket": { | ||
"Type": "AWS::S3::Bucket", | ||
"Properties": { | ||
"BucketName": { | ||
"Fn::Sub": [ | ||
"${AnotherBucket.DomainName}", | ||
{ | ||
"AnotherBucket": "whatever" | ||
} | ||
] | ||
} | ||
} | ||
}, | ||
"AnotherBucket": { | ||
"Type": "AWS::S3::Bucket" | ||
} | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
packages/@aws-cdk/cloudformation-include/test/test-templates/fn-sub-shadow.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"Resources": { | ||
"Bucket": { | ||
"Type": "AWS::S3::Bucket", | ||
"Properties": { | ||
"BucketName": { | ||
"Fn::Sub": [ | ||
"${AnotherBucket}", | ||
{ | ||
"AnotherBucket": { "Ref" : "AnotherBucket" } | ||
} | ||
] | ||
} | ||
} | ||
}, | ||
"AnotherBucket": { | ||
"Type": "AWS::S3::Bucket" | ||
} | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
packages/@aws-cdk/cloudformation-include/test/test-templates/fn-sub-string.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"Resources": { | ||
"Bucket": { | ||
"Type": "AWS::S3::Bucket", | ||
"Properties": { | ||
"BucketName": "bucket" | ||
} | ||
}, | ||
"AnotherBucket": { | ||
"Type": "AWS::S3::Bucket", | ||
"Properties": { | ||
"BucketName": { "Fn::Sub": "1-${AWS::Region}-foo-${Bucket}-${!Literal}-${Bucket.DomainName}-${AWS::Region}" } | ||
} | ||
} | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
packages/@aws-cdk/cloudformation-include/test/test-templates/invalid/fn-sub-${}-only.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"Resources": { | ||
"Bucket": { | ||
"Type": "AWS::S3::Bucket", | ||
"Properties": { | ||
"BucketName": { | ||
"Fn::Sub": "${}" | ||
} | ||
} | ||
} | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
...cloudformation-include/test/test-templates/invalid/fn-sub-key-not-in-template-string.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"Resources": { | ||
"Bucket": { | ||
"Type": "AWS::S3::Bucket", | ||
"Properties": { | ||
"AccessControl": { "Fn::Sub": "${AFakeResource}" } | ||
} | ||
} | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
...ws-cdk/cloudformation-include/test/test-templates/yaml/invalid/short-form-import-sub.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Resources: | ||
Bucket: | ||
Type: AWS::S3::Bucket | ||
Properties: | ||
BucketName: | ||
!ImportValue | ||
!Sub ${AWS::Region} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
...ges/@aws-cdk/cloudformation-include/test/test-templates/yaml/short-form-fnsub-string.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
Resources: | ||
Bucket: | ||
Type: AWS::S3::Bucket | ||
Properties: | ||
BucketName: | ||
Fn::Sub: some-bucket${!AWS::AccountId}7896${ ! AWS::Region}1-1${!Immediate}234 | ||
AnotherBucket: | ||
Type: AWS::S3::Bucket | ||
Properties: | ||
BucketName: | ||
!Sub 1-${AWS::Region}-foo-${Bucket}-${!Literal}-${Bucket.DomainName}-${AWS::Region} |
15 changes: 15 additions & 0 deletions
15
packages/@aws-cdk/cloudformation-include/test/test-templates/yaml/short-form-sub-map.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
Resources: | ||
Bucket: | ||
Type: AWS::S3::Bucket | ||
Properties: | ||
BucketName: | ||
!Sub | ||
- "${Region}-foo-${!Immediate}-foo-${AnotherBucket}-${AnotherBucket.DomainName}-${Name}" | ||
- Name: | ||
Ref: AnotherBucket | ||
Region: | ||
Fn::Base64: AWS::Region | ||
AnotherBucket: | ||
Type: AWS::S3::Bucket | ||
Properties: | ||
BucketName: another-bucket |
Oops, something went wrong.