Skip to content
This repository has been archived by the owner on Feb 14, 2023. It is now read-only.

Variables not working #13

Open
sunshineo opened this issue May 21, 2021 · 5 comments
Open

Variables not working #13

sunshineo opened this issue May 21, 2021 · 5 comments

Comments

@sunshineo
Copy link

sunshineo commented May 21, 2021

I have this:

forwarderArn: arn:aws:lambda:us-west-2:${self:custom.awsAccountId.${env:CI_COMMIT_BRANCH}}:function:datadog-forwarder

Works totally fine in one file but if I try to move this to another file and import it using this plugin it does not work

Could not perform GetFunction on arn:aws:lambda:us-west-2:${self:custom.awsAccountId.${env:CI_COMMIT_BRANCH}}:function:datadog-forwarder

The variables are no longer resolved

@ValorMorgan
Copy link

Based on my understanding of what seems to be happening, this plugin is performing all of it's merge logic AFTER serverless already populated variables. Thus if you expect self:custom.awsAccountId... in fileB to properly resolve to something you defined in fileA, you won't see much success as that resolution already happened.

Though I don't have the best knowledge on this front, I think this plugin needs to utilize the serverless hooks to perform BEFORE the variable resolution happens. This "may" break things though if one expects a value in fileB to be used but is not because that same value is defined in fileA and thus not overriden on merge.

@sunshineo
Copy link
Author

sunshineo commented Oct 25, 2021

FYI our solution was to use https://www.npmjs.com/package/@alexlafroscia/yaml-merge and make it one file before get to serverless

@digitalkaoz
Copy link

@sunshineo that didnt work for us, as foo: !GetAtt Bar isnt valid code if unquoted... we ran into the variables problem as well, i tried to change the plugin code to work earlier in the chain, but im not familar with serverless plugins

@ValorMorgan
Copy link

i tried to change the plugin code to work earlier in the chain, but im not familar with serverless plugins

I think this plugin needs to utilize the serverless hooks to perform BEFORE the variable resolution happens

Seems we're on the same page. Serverless exposes lifecycle hooks which can allow the plugin to fire at specific times of the serverless operations. I believe it currently fires sometime after the variable resolution. I was previously able to get it to fire earlier but with mixed results. That was pre-v3 of Serverless though so it's been a hot-minute since I last did anything with plugins and couldn't tell you exactly how to do it anymore.

Looks like you do something with this.hooks = { [hook: string]: () => void }. Someone made a cheatsheet of all the hooks: https://gist.github.com/HyperBrain/50d38027a8f57778d5b0f135d80ea406

@digitalkaoz
Copy link

digitalkaoz commented Feb 25, 2022 via email

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants