Description
Use case
Our existing serverless.yml files reference (partial) CloudFormation templates defined separately, as follows:
service: example
provider:
name: aws
[...]
resources:
- Description: CloudFormation stack description
- ${file(./cf-resources/resource1.yml)}
- ${file(./cf-resources/resource2.yml)}
Each resource yml file is a "valid" chunk of CloudFormation template, as follows:
Resources:
Resource1:
Type: AWS:xxx:yyy
Properties:
[etc. etc]
The advantages of the above setup (for us) is we can then configure cfn-lint tool to run against the entire /resources folder and validate the template chunks. With the help of VSCode plugins, we also get Intellisense that is context dependent on the raw resource type + links to relevant AWS docs, both which help a lot.
Problem
I tried to convert the serverless.yml template to TypeScript and I ran into issues with the file references to the raw resource templates. I do not want to convert the resource definitions to TypeScript, because I would lose the cfn-lint support.
The following works (but does not compile with the current @serverless/typescript definitions):
import type { AWS } from '@serverless/typescript';
const serverlessConfig: AWS = {
service: 'example',
provider: {
name: 'aws'
},
resources: [
{
Description: CloudFormation stack description
},
'${file(./cf-resources/resource1.yml)}',
'${file(./cf-resources/resource2.yml)}'
]
}
module.exports = serverlessConfig;
So to summarize, the type of resources should be changed to a union type that acccepts T | T[], where T = (the current type of resources entry + string type).
Obviously, if there is a better way that I did not see, I'm open to suggestions.