iopipe / serverless-plugin-iopipe

Automatically wrap your serverless framework functions with IOpipe
https://www.iopipe.com
Apache License 2.0
40 stars 8 forks source link

Support serverless.yml variable interpolation #41

Closed kolanos closed 6 years ago

kolanos commented 7 years ago

If custom.iopipeToken is set to something like ${self:custom.some_var} the plugin uses that value instead of the interpolated one.

jspies commented 7 years ago

👍 More info from my perspective:

For example, we load settings for different stages into a custom var and reference it all over the place.

custom:
  deployVars: ${file(../config/deploy.${self:provider.stage}.yml)}
  iopipeToken: ${self:custom.deployVars.IOPIPE}

However, when I use this, the token in the handler is '${self:custom.deployVars.IOPIPE}', not the value of the variable.

coreylight commented 7 years ago

We aren't doing anything particularly funky with the serverless.yml or interpolation as far as I know - so I'm currently thinking it's a bug on the serverless side. There are a few issues that hint at this: https://github.com/serverless/serverless/issues/4161 https://github.com/serverless/serverless/pull/4169 Perhaps a test case with an issue filed on their side is warranted.

alexdebrie commented 7 years ago

Hey @coreylight, just saw this from the link in serverless/serverless#4169.

At a quick glance, I think the issue is here, where you're setting the options in the constructor for the plugin. The general flow for Serverless is:

1) Load + initialize all plugins; 2) Interpolate variables in serverless.yml; 3) Execute the command by calling the requested plugin.

With this plugin, you're setting the value of the token during step 1, but the value of that variable won't be resolved until step 2. A better approach would be to wait to set the options for the plugin during step 3, after the plugin is triggered through a hook.

Let me know if this doesn't make sense or if you have any questions 😄

coreylight commented 7 years ago

Ahh, that helps a lot and makes sense @alexdebrie. Hopefully we can knock this out quickly then. Thank you!