Search code examples
azure-devopsazure-logic-appsazure-rm-template

Unable to parse template language expression 'encodeURIComponent([parameters('table_storage_name')])'


Hey I am doing a CI/CD deployment for a logic app, I have a table storage where I store some data, I have two table storage for test and prod environment. I created a parameter called *table_storage_name" in ARM template :

"parameters": {
// ....
"connections_azuretables_1_externalid": {
   "defaultValue": "/subscriptions/e5..../resourceGroups/myrg.../providers/Microsoft.Web/connections/azuretables-1",
      "type": "String"
        },
"table_storage_name": {
          "defaultValue": "testdevops",
          "type": "String"
        }
}

The error comes from when I reference the parameter here in template.json file:

// ...
"Insert_Entity": {
  "runAfter": {
      "Initialize_variable": [
          "Succeeded"
      ]
  },
  "type": "ApiConnection",
  "inputs": {
      "body": {
          "PartitionKey": "@body('Parse_JSON')?['name']",
          "RowKey": "@body('Parse_JSON')?['last']"
      },
      "host": {
          "connection": {
              "name": "@parameters('$connections')['azuretables_1']['connectionId']"
          }
      },
      "method": "post",
      // problem occur after this line
      "path": "/Tables/@{encodeURIComponent('[parameters('table_storage_name')]')}/entities"
  }
}

but get this error:

InvalidTemplate: The template validation failed: 'The template action 'Insert_Entity' at line '1' and column '582' is not valid: "Unable to parse template language expression 'encodeURIComponent([parameters('table_storage_name')])': expected token 'Identifier' and actual 'LeftSquareBracket'.".'.

I tried escaping the quote with a backslash like: encodeURIComponent(\'[parameters('table_storage_name')]\') or encodeURIComponent('[parameters(''table_storage_name'')]') but all of them raise an error. How can I reference a paramter inside encodeURIComponent in an ARM template ?


Solution

  • Found the solution from this link https://platform.deloitte.com.au/articles/preparing-azure-logic-apps-for-cicd

    but here are the steps to reference a parameter logic app:

    1. create an ARM parameter table_storage_name_armparam in template.json, in order to use it's value to reference the value of the ARM parameter (yes it's confusing but follow along you'll understand):
    {
        "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
        "contentVersion": "1.0.0.0",
        "parameters": {
            "table_storage_name_armparam": {
              "type": "String"
            }
        },
        "variables": {},
        "resources": [
            {
             ......
    }
    
    1. Now in the logic app parameter value (in the bottom of json file) create the logic app parameter table_storage_name and the value of this parameter will be the ARM parameter created in step 1:
    .......
    "parameters": {
                        "$connections": {
                            "value": {
                                "azuretables": {
                                    "connectionId": "[parameters('connections_azuretables_externalid')]",
                                    "connectionName": "azuretables",
                                    "id": "/subscriptions/xxxxx-xxxx-xxxx-xxxxxxxx/providers/Microsoft.Web/locations/francecentral/managedApis/azuretables"
                                }
                            }
                        },
                        "table_storage_name": {
                          "value": "[parameters('table_storage_name_armparam')]"
                        }
                    }
                }
            }
        ]
    }
    
    1. finally, reference the logic app parameter value as follow:
    "path": "/Tables/@{encodeURIComponent(parameters('table_storage_name'))}/entities"