无法解析模板语言表达式 'encodeURIComponent([parameters('table_storage_name')])'

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

嘿,我正在为一个逻辑应用程序进行 CI/CD 部署,我有一个 table 存储空间用于存储一些数据,我有两个 table 存储空间用于 testprod 环境。我在 ARM 模板中创建了一个名为 *table_storage_name" 的参数:

"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"
        }
}

错误来自于我在template.json文件中引用这里的参数:

// ...
"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"
  }
}

但出现此错误:

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'.".'.

我尝试用反斜杠转义引号,例如:encodeURIComponent(\'[parameters('table_storage_name')]\')encodeURIComponent('[parameters(''table_storage_name'')]') 但它们都会引发错误。如何在 ARM 模板中引用 encodeURIComponent 内的参数?

如评论中所述。学分:@marone

 "path": "/Tables/@{encodeURIComponent(parameters('table_storage_name'))}/entities"

从中找到解决方案 link https://platform.deloitte.com.au/articles/preparing-azure-logic-apps-for-cicd

但这里是引用参数逻辑应用程序的步骤:

  1. 在 template.json 中创建一个 ARM 参数 table_storage_name_armparam,以便使用它的值来引用 ARM 参数的值(是的,这令人困惑,但跟着你就明白了):
{
    "$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. 现在在逻辑应用程序参数值中(在 json 文件的底部)创建逻辑应用程序参数 table_storage_name 和此参数的值将是在步骤 1 中创建的 ARM 参数:
.......
"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. 最后引用logic app参数值如下:
"path": "/Tables/@{encodeURIComponent(parameters('table_storage_name'))}/entities"