Skip to content
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

Support referencing resources from yaml files #46

Open
coyoteecd opened this issue Jul 6, 2021 · 4 comments
Open

Support referencing resources from yaml files #46

coyoteecd opened this issue Jul 6, 2021 · 4 comments
Labels
duplicate This issue or pull request already exists

Comments

@coyoteecd
Copy link

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.

@pdecarcer
Copy link

You can wrtie ./cf-resources/resource1.yml on TS and then import. In that case just use TS

@coyoteecd
Copy link
Author

@pdecarcer can you elaborate a bit?

@coyoteecd
Copy link
Author

@fredericbarthelet what's your opinion, would you accept a PR that changes the resource type as suggested above?

@fredericbarthelet
Copy link
Contributor

Thanks for raising this issue @coyoteecd.
The problem you're pointing out actually extend to all definition file properties where serverless variables can be used. This issue was raised in #11
Please bear in mind that types exported from this repository are auto-generated, you cannot modify them manually. The only persistent way to introduce this kind of modification is using a custom compiler pass in the generation library. PR are more than welcome on #11 and #1 which is the first blocker.

@fredericbarthelet fredericbarthelet added the duplicate This issue or pull request already exists label Oct 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

3 participants