-
Notifications
You must be signed in to change notification settings - Fork 4.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(cfn-include): fails to load SAM resources #9442
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
70 changes: 70 additions & 0 deletions
70
packages/@aws-cdk/cloudformation-include/test/serverless-transform.test.ts
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,70 @@ | ||
import * as path from 'path'; | ||
import '@aws-cdk/assert/jest'; | ||
import * as core from '@aws-cdk/core'; | ||
import * as inc from '../lib'; | ||
import * as futils from '../lib/file-utils'; | ||
|
||
/* eslint-disable quote-props */ | ||
/* eslint-disable quotes */ | ||
|
||
describe('CDK Include for templates with SAM transform', () => { | ||
let stack: core.Stack; | ||
|
||
beforeEach(() => { | ||
stack = new core.Stack(); | ||
}); | ||
|
||
test('can ingest a template with only a minimal SAM function using S3Location for CodeUri, and output it unchanged', () => { | ||
includeTestTemplate(stack, 'only-minimal-sam-function-codeuri-as-s3location.yaml'); | ||
|
||
expect(stack).toMatchTemplate( | ||
loadTestFileToJsObject('only-minimal-sam-function-codeuri-as-s3location.yaml'), | ||
); | ||
}); | ||
|
||
test('can ingest a template with only a SAM function using an array with DDB CRUD for Policies, and output it unchanged', () => { | ||
includeTestTemplate(stack, 'only-sam-function-policies-array-ddb-crud.yaml'); | ||
|
||
expect(stack).toMatchTemplate( | ||
loadTestFileToJsObject('only-sam-function-policies-array-ddb-crud.yaml'), | ||
); | ||
}); | ||
|
||
test('can ingest a template with only a minimal SAM function using a parameter for CodeUri, and output it unchanged', () => { | ||
includeTestTemplate(stack, 'only-minimal-sam-function-codeuri-as-param.yaml'); | ||
|
||
expect(stack).toMatchTemplate( | ||
loadTestFileToJsObject('only-minimal-sam-function-codeuri-as-param.yaml'), | ||
); | ||
}); | ||
|
||
test('can ingest a template with only a minimal SAM function using a parameter for CodeUri Bucket property, and output it unchanged', () => { | ||
includeTestTemplate(stack, 'only-minimal-sam-function-codeuri-bucket-as-param.yaml'); | ||
|
||
expect(stack).toMatchTemplate( | ||
loadTestFileToJsObject('only-minimal-sam-function-codeuri-bucket-as-param.yaml'), | ||
); | ||
}); | ||
|
||
test('can ingest a template with only a SAM function using an array with DDB CRUD for Policies with an Fn::If expression, and output it unchanged', () => { | ||
includeTestTemplate(stack, 'only-sam-function-policies-array-ddb-crud-if.yaml'); | ||
|
||
expect(stack).toMatchTemplate( | ||
loadTestFileToJsObject('only-sam-function-policies-array-ddb-crud-if.yaml'), | ||
); | ||
}); | ||
}); | ||
|
||
function includeTestTemplate(scope: core.Construct, testTemplate: string): inc.CfnInclude { | ||
return new inc.CfnInclude(scope, 'MyScope', { | ||
templateFile: _testTemplateFilePath(testTemplate), | ||
}); | ||
} | ||
|
||
function loadTestFileToJsObject(testTemplate: string): any { | ||
return futils.readYamlSync(_testTemplateFilePath(testTemplate)); | ||
} | ||
|
||
function _testTemplateFilePath(testTemplate: string) { | ||
return path.join(__dirname, 'test-templates', 'sam', testTemplate); | ||
} |
13 changes: 13 additions & 0 deletions
13
...formation-include/test/test-templates/sam/only-minimal-sam-function-codeuri-as-param.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,13 @@ | ||
AWSTemplateFormatVersion: '2010-09-09' | ||
Transform: AWS::Serverless-2016-10-31 | ||
Parameters: | ||
CodeLocation: | ||
Type: String | ||
Resources: | ||
MicroserviceHttpEndpoint: | ||
Type: AWS::Serverless::Function | ||
Properties: | ||
Handler: index.handler | ||
Runtime: nodejs12.x | ||
CodeUri: | ||
Ref: CodeLocation |
11 changes: 11 additions & 0 deletions
11
...tion-include/test/test-templates/sam/only-minimal-sam-function-codeuri-as-s3location.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 @@ | ||
AWSTemplateFormatVersion: '2010-09-09' | ||
Transform: AWS::Serverless-2016-10-31 | ||
Resources: | ||
MicroserviceHttpEndpoint: | ||
Type: AWS::Serverless::Function | ||
Properties: | ||
Handler: index.handler | ||
Runtime: nodejs12.x | ||
CodeUri: | ||
Bucket: awsserverlessrepo-changesets-1f9ifp952i9h0 | ||
Key: 123456789012/arn:aws:serverlessrepo:us-east-1:077246666028:applications-microservice-http-endpoint-versions-1.0.4/dc38a8c1-d27f-44f3-b545-4cfff4f8b865 |
15 changes: 15 additions & 0 deletions
15
...on-include/test/test-templates/sam/only-minimal-sam-function-codeuri-bucket-as-param.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 @@ | ||
AWSTemplateFormatVersion: '2010-09-09' | ||
Transform: AWS::Serverless-2016-10-31 | ||
Parameters: | ||
CodeLocation: | ||
Type: String | ||
Resources: | ||
MicroserviceHttpEndpoint: | ||
Type: AWS::Serverless::Function | ||
Properties: | ||
Handler: index.handler | ||
Runtime: nodejs12.x | ||
CodeUri: | ||
Bucket: | ||
Ref: CodeLocation | ||
Key: my-key |
26 changes: 26 additions & 0 deletions
26
...rmation-include/test/test-templates/sam/only-sam-function-policies-array-ddb-crud-if.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,26 @@ | ||
AWSTemplateFormatVersion: '2010-09-09' | ||
Transform: AWS::Serverless-2016-10-31 | ||
Conditions: | ||
SomeCondition: | ||
Fn::Equals: [1, 2] | ||
Parameters: | ||
TableNameParameter: | ||
Type: String | ||
Resources: | ||
MicroserviceHttpEndpoint: | ||
Type: AWS::Serverless::Function | ||
Properties: | ||
Handler: index.handler | ||
Runtime: nodejs12.x | ||
CodeUri: | ||
Bucket: awsserverlessrepo-changesets-1f9ifp952i9h0 | ||
Key: 828671620168/arn:aws:serverlessrepo:us-east-1:077246666028:applications-microservice-http-endpoint-versions-1.0.4/dc38a8c1-d27f-44f3-b545-4cfff4f8b865 | ||
Policies: | ||
- Fn::If: | ||
- SomeCondition | ||
- DynamoDBCrudPolicy: | ||
TableName: | ||
Ref: TableNameParameter | ||
- DynamoDBCrudPolicy: | ||
TableName: | ||
Ref: TableNameParameter |
16 changes: 16 additions & 0 deletions
16
...dformation-include/test/test-templates/sam/only-sam-function-policies-array-ddb-crud.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,16 @@ | ||
AWSTemplateFormatVersion: '2010-09-09' | ||
Transform: AWS::Serverless-2016-10-31 | ||
Parameters: | ||
TableNameParameter: | ||
Type: String | ||
Resources: | ||
MicroserviceHttpEndpoint: | ||
Type: AWS::Serverless::Function | ||
Properties: | ||
Handler: index.handler | ||
Runtime: nodejs12.x | ||
CodeUri: my-code-uri | ||
Policies: | ||
- DynamoDBCrudPolicy: | ||
TableName: | ||
Ref: TableNameParameter |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Accidentally quadratic here. Not sure the set ever grows big enough for it to be an issue, but hope you thought about this and weighed the risk intentionally.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. I don't think this will ever realistically contain more than 2 elements.