serverless / serverless-azure-functions

Serverless Azure Functions Plugin – Add Azure Functions support to the Serverless Framework
MIT License
266 stars 162 forks source link

Support extended JSON format for ARM templates #560

Open freastro opened 3 years ago

freastro commented 3 years ago

This is a Feature Proposal

Description

Azure supports an extended JSON format for its ARM templates that includes support for comments and multi-line strings. But these templates are not currently supported by Serverless Azure Functions due to using JSON.parse() which only supports the regular JSON format. I propose that the provider.armTemplate.file parameter should be extended to support any valid ARM template.

Examples

Here are some examples from the Azure docs of valid ARM templates that are not currently supported by Serverless Azure Functions. https://docs.microsoft.com/en-us/azure/azure-resource-manager/templates/syntax

Comments

{
  "type": "Microsoft.Compute/virtualMachines",
  "apiVersion": "2018-10-01",
  "name": "[variables('vmName')]", // to customize name, change it in variables
  "location": "[parameters('location')]", //defaults to resource group location
  "dependsOn": [ /* storage account and network interface must be deployed first */
    "[resourceId('Microsoft.Storage/storageAccounts/', variables('storageAccountName'))]",
    "[resourceId('Microsoft.Network/networkInterfaces/', variables('nicName'))]"
  ],

Multi-line strings

{
  "type": "Microsoft.Compute/virtualMachines",
  "apiVersion": "2018-10-01",
  "name": "[variables('vmName')]", // to customize name, change it in variables
  "location": "[
    parameters('location')
    ]", //defaults to resource group location
  /*
    storage account and network interface
    must be deployed first
  */
  "dependsOn": [
    "[resourceId('Microsoft.Storage/storageAccounts/', variables('storageAccountName'))]",
    "[resourceId('Microsoft.Network/networkInterfaces/', variables('nicName'))]"
  ],jsonc

Error

Below is the current error message displayed when trying to use an ARM template that includes comments:

  SyntaxError: Unexpected token / in JSON at position 1164
      at JSON.parse (<anonymous>)
      at ArmService.createDeploymentFromConfig (node_modules/serverless-azure-functions/lib/services/armService.js:169:29)
      at FunctionAppService.<anonymous> (node_modules/serverless-azure-functions/lib/services/functionAppService.js:319:57)
      at step (node_modules/serverless-azure-functions/lib/services/functionAppService.js:45:23)
      at Object.next (node_modules/serverless-azure-functions/lib/services/functionAppService.js:26:53)
      at node_modules/serverless-azure-functions/lib/services/functionAppService.js:20:71
      at new Promise (<anonymous>)
      at __awaiter (node_modules/serverless-azure-functions/lib/services/functionAppService.js:16:12)
      at FunctionAppService.deploy (node_modules/serverless-azure-functions/lib/services/functionAppService.js:310:16)
      at AzureDeployPlugin.<anonymous> (node_modules/serverless-azure-functions/lib/plugins/deploy/azureDeployPlugin.js:143:65)
      at step (node_modules/serverless-azure-functions/lib/plugins/deploy/azureDeployPlugin.js:56:23)
      at Object.next (node_modules/serverless-azure-functions/lib/plugins/deploy/azureDeployPlugin.js:37:53)
      at fulfilled (node_modules/serverless-azure-functions/lib/plugins/deploy/azureDeployPlugin.js:28:58)
      at processTicksAndRejections (internal/process/task_queues.js:95:5)
  Your Environment Information ---------------------------
     Operating System:          darwin
     Node Version:              14.17.0
     Framework Version:         2.50.0 (local)
     Plugin Version:            5.4.3
     SDK Version:               4.2.3
     Components Version:        3.13.2