Repository: serverless/serverless (JavaScript)
Date: 2016-12-08 07:44:25+00:00
Task type: Bug Fix

Issue:
Variable Syntax matches itself in serverless.yml
# This is a Bug Report

## Description
I tried to use the `variableSyntax` property to enable me to use cross-stack references in CloudFormation. I set it to `'\${{([\s\S]+?)}}'` to allow me to use `${blah}` in CF and `${{opt:stage}}` 

The custom variable syntax I set is matching on itself. [Variables.js](https://github.com/serverless/serverless/blob/master/lib/classes/Variables.js) temporarily removes this property `this.service.defaults.variableSyntax` but does not remove `this.service.provider.variableSyntax` causing it to match on that property.

The fix will be to temporarily remove `this.service.provider.variableSyntax`.

## Similar Issue
* #2143

## Additional Data

* ***Serverless Framework Version you're using***: 1.3.0
* ***Operating System***: MacOSX
* ***Stack Trace***:
```
  Serverless Error ---------------------------------------
 
     Invalid variable reference syntax for variable ([\s\S]+?).
     You can only reference env vars, options, & files. You
     can check our docs for more info.
 
  Stack Trace --------------------------------------------
 
ServerlessError: Invalid variable reference syntax for variable ([\s\S]+?). You can only reference env vars, options, & files. You can check our docs for more info.
    at Variables.getValueFromSource (/.../serverless/lib/classes/Variables.js:128:13)
    at /.../serverless/lib/classes/Variables.js:66:34
    at Array.forEach (native)
    at Variables.populateProperty (/.../serverless/lib/classes/Variables.js:58:43)
    at Object.<anonymous> (/.../serverless/lib/classes/Variables.js:45:25)
    at walker (/.../serverless/node_modules/traverse/index.js:190:22)
    at /.../serverless/node_modules/traverse/index.js:208:29
    at Array.forEach (native)
    at forEach (/.../serverless/node_modules/traverse/index.js:298:31)
    at walker (/.../serverless/node_modules/traverse/index.js:203:13)
    at /.../serverless/node_modules/traverse/index.js:208:29
    at Array.forEach (native)
    at forEach (/.../serverless/node_modules/traverse/index.js:298:31)
    at walker (/.../serverless/node_modules/traverse/index.js:203:13)
    at walk (/.../serverless/node_modules/traverse/index.js:226:7)
    at Traverse.forEach (/.../serverless/node_modules/traverse/index.js:50:18)
From previous event:
    at processImmediate [as _immediateCallback] (timers.js:383:17)
From previous event:
    at /.../serverless/bin/serverless:11:28
    at Object.<anonymous> (/.../serverless/bin/serverless:20:28)
    at Module._compile (module.js:409:26)
    at Object.Module._extensions..js (module.js:416:10)
    at Module.load (module.js:343:32)
    at Function.Module._load (module.js:300:12)
    at Function.Module.runMain (module.js:441:10)
    at startup (node.js:134:18)
    at node.js:962:3
 
  Get Support --------------------------------------------
     Docs:          docs.serverless.com
     Bugs:          github.com/serverless/serverless/issues
 
  Your Environment Information -----------------------------
     OS:                 darwin
     Node Version:       4.3.2
     Serverless Version: 1.3.0
```



Issue discussion:

Solution patch:
diff --git a/lib/classes/Variables.js b/lib/classes/Variables.js
index 5c18e6aff1f..1e95bf03e9a 100644
--- a/lib/classes/Variables.js
+++ b/lib/classes/Variables.js
@@ -32,6 +32,7 @@ class Variables {
 
     // temporally remove variable syntax from service otherwise it'll match
     this.service.defaults.variableSyntax = true;
+    this.service.provider.variableSyntax = true;
 
     /*
      * we can't use an arrow function in this case cause that would
@@ -48,6 +49,7 @@ class Variables {
     });
 
     this.service.defaults.variableSyntax = variableSyntaxProperty;
+    this.service.provider.variableSyntax = variableSyntaxProperty;
     return this.service;
   }
 


Test patch:
diff --git a/lib/classes/Variables.test.js b/lib/classes/Variables.test.js
index a5cd3215da4..6d929008291 100644
--- a/lib/classes/Variables.test.js
+++ b/lib/classes/Variables.test.js
@@ -56,6 +56,7 @@ describe('Variables', () => {
       const barValue = 'test';
 
       serverless.service.defaults.variableSyntax = variableSyntax;
+      serverless.service.provider.variableSyntax = variableSyntax;
 
       serverless.service.custom = {
         var: barValue,