anantab / serverless-plugin-ifelse

A Serverless Plugin to write If Else conditions in serverless YAML file
69 stars 21 forks source link

Can Plugin Set custom Variables? #35

Open rpattcorner opened 2 years ago

rpattcorner commented 2 years ago

Been experimenting, and it looks like this most useful plugin can target a section of serverless.yml like a provider, but cannot set the value of a custom variable, e.g.

serverlessIfElse:
    - If: '"${self:custom.somevalue}" == "true"'
      Set: 
        self:custom.targetValue: somevalue
      ElseSet:
         self:custom.targetValue: someOthervalue

Tried a few syntactic variants with $ and brackets, without effect

Is it indeed not possible to set a conditional custom variable this way? Works great targeting a provider, though :)

deCodeIt commented 2 years ago

I did use it to update the custom variable value and it worked for me.

I'd the following:

custom:
  dynamodb:
    start:
      dbPath: "somePath/"

and then I used the following and it worked for my case.

serverlessIfElse:
  - If: '"${self:custom.ENV.IS_OFFLINE}" == "1"'
      Set:
        custom.dynamodb.start.dbPath: "someOtherPath/"
CaioF commented 2 years ago

From my experience using serverlessIfElse to set custom vars, specially those that are in the config of another plugin does not work.