softprops / serverless-rust

⚡ 🦀 a serverless framework plugin for rustlang applications
https://www.npmjs.com/package/serverless-rust
MIT License
541 stars 81 forks source link

Custom variables not expanding #104

Open tiagomjorge opened 2 years ago

tiagomjorge commented 2 years ago

I'm trying to configure the plugin's custom variables like this:

custom:
  rust:
    dockerTag: my-tag
    dockerImage: my-image
    dockerPath: ${env:DOCKER_PATH}

However, I've noticed that the dockerPath is getting passed to the plugin non-expanded. Looking at the plugin's code, it seems like since the plugin is consuming all of the configuration parameters on its constructor, it is reading the values before the serverless framework expands them. I've also tried using a file, like:

custom:
  rust:
    ${file(serverless/includes/serverless-rust.yml)}

But it also doesn't work, which makes sense, since the plugin is reading the config parameters before the serverless framework has a chance to fill them in. One fix would be to read those variables inside the hooked up functions, instead of inside the constructor.

Does this make sense? Am I missing something?

tiagomjorge commented 2 years ago

Just found this on the serverless framework plugin doc, which confirms my theory:

Note: Variable references in the serverless instance are not resolved before a Plugin's constructor is called, so if you need these, make sure to wait to access those from your hooks.