anantab / serverless-plugin-ifelse

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

Feature Request: support ElseIf #5

Closed aniham closed 5 years ago

aniham commented 5 years ago

Very neat plugin! Are there any plans to add ElseIf as in:

- If: '"${self:custom.stage}" == "prod"'
  Set:
   - someVal: 'prod'
- ElseIf: '"${self:custom.stage}" == "stg"'
  Set:
  - someVal: 'stg'
- Else:
  Set:
  - someVal: 'other'
GurpreetSingh5 commented 5 years ago

Any updates on this? This feature would be quite handy.

anantab commented 5 years ago

The plugin does not support ElseIf, but it can be achieved by writing multiple If conditions. Eg

- If: '"${self:custom.stage}" == "prod"'
  Set:
    someVal: 'prod'
- If: '"${self:custom.stage}" == "stg"'
  Set:
    someVal: 'stg'
- If: '["prod","stg"].indexOf("${self:custom.stage}") == -1 '
  Set:
    someVal: 'dev'
GurpreetSingh5 commented 5 years ago

The plugin does not support ElseIf, but it can be achieved by writing multiple If conditions. Eg

- If: '"${self:custom.stage}" == "prod"'
  Set:
    someVal: 'prod'
- If: '"${self:custom.stage}" == "stg"'
  Set:
    someVal: 'stg'
- If: '["prod","stg"].indexOf("${self:custom.stage}") == -1 '
  Set:
    someVal: 'dev'

Good Work.