Add imports and exports functionality (Cross-Stack-References)#3475
Add imports and exports functionality (Cross-Stack-References)#3475pmuens wants to merge 2 commits into
Conversation
7c40fed to
d215865
Compare
d215865 to
a4f9c91
Compare
| this.envRefSyntax = RegExp(/^env:/g); | ||
| this.optRefSyntax = RegExp(/^opt:/g); | ||
| this.selfRefSyntax = RegExp(/^self:/g); | ||
| this.importsRefSyntax = RegExp(/^imports:/g); |
There was a problem hiding this comment.
This source is not needed imo. Adds lots of technical debts. Lets just use "self"
There was a problem hiding this comment.
Unfortunately this is not possible (tried it yesterday).
The idea with this PR is that you define imports in your serverless.yml file. Those imports are then translated to Fn::ImportValue statements for AWS which are basically attached to the imports statement in the variable system.
The extension in the variable system only checks if the value is implicitly defined in the imports section so that users can't simply use the imports from the variable system if they are not defined in the service.imports configuration.
Using self here won't help since we're not populating anything.
| return valueToPopulate; | ||
| } | ||
|
|
||
| getValueFromImports(variableString) { |
There was a problem hiding this comment.
We won't need this method at all
There was a problem hiding this comment.
This method checks if the user who want's to use imports via the variable system has explicitly defined what he want's to use in the service.imports config.
|
|
||
| compileImports() { | ||
| const that = this; // save this because of the upcoming scope switch | ||
| traverse(this.serverless.service).forEach(function (propertyParam) { |
There was a problem hiding this comment.
why do we use traverse here instead of following the same style we're using with exports?
-> exports = this.serverless.service.exports?
There was a problem hiding this comment.
We traverse here since the usage for an import (via the variable system) can be everywhere in the serverless.yml file.
You can see an example in the service I posted for the verification (#3475 (comment)).
There was a problem hiding this comment.
gotcha. If we're gonna use the built in variable system via self we won't need that I think
| if (typeof propertyParam === 'string' && propertyParam.match(/imports:.+/)) { | ||
| const removedPrefix = propertyParam.split(':')[1]; | ||
| const parts = removedPrefix.split('.'); | ||
| const stack = parts[0]; |
There was a problem hiding this comment.
Not sure if this would work. Remember that the stack name is not just the service name, but it also includes the stage. This pegs the question whether the user should reference a service (in which case he'd have to choose a stage) or the full stack name.
There was a problem hiding this comment.
This is the part the user defines in the imports config section.
So he needs to explicitly append the stage to the stack name:
imports:
my-service-dev:
- foo
- barThere was a problem hiding this comment.
ah ok so he provides the stack name not service name. Gotcha! 👍
There was a problem hiding this comment.
Yep, exactly! 👍
This way it's possible to e.g. from different stages. Don't know if that's a commonly used feature though...
|
We're now implementing this feature in PR #3575 Closing... |
What did you implement:
Closes #3442
This WIP PR implements the
importsandexportssupport as described in #3442./cc @brianneisler @eahefnawy
How did you implement it:
Imports
Import values can be defined with the help of the
importskeyword.Those values are then translated into Serverless variables and can therefore be placed anywhere in the
serverless.ymlfile.The
AwsCompileImportsplugin checks for the populated variable in theserverless.ymlfile and replaces this value with the correspondingCloudFormationFn::ImportValuestatement. It's furthermore checked if the Serverlessimportsvariable is imported beforehand so that a population is not happening if it's not explicitly imported.Exports
Export values can be specified with the help of the
exportsconfig variable in theserverless.ymlfileThose values are then compiled into corresponding
CloudFormationOutputsby theAwsCompileExportsplugin.How can we verify it:
Here's a
serverless.ymlfile which shows how this looks like:Just run
serverless packageand take a look in the generatedCloudFormationoutput.Todos:
Is this ready for review?: NO
Is it a breaking change?: NO