gpt4 book ai didi

arrays - 将参数文件中的连接字符串数组传递到 bicep 文件,以用于应用程序服务的循环

转载 作者:行者123 更新时间:2023-12-03 03:26:55 27 4
gpt4 key购买 nike

我正在尝试创建一个应用程序服务以通过 CI/CD 管道进行部署,但是我正在努力为连接字符串创建一个 For 循环。

我的参数文件有以下内容:

{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
// Required Parameters
...
// Optional Parameters
"connectionStrings": [
{
"name": "Tracking",
"connectionString": "...",
"type": "SQLServer"
}
{
"name": "Logs",
"connectionString": "...",
"type": "SQLServer"
}
],
...
}
}

我将其作为 param connectionStrings 数组 传递到 main.bicep 文件和 appService.bicep 模块文件中。

appService.bicep 文件中,我有以下 for 循环。

resource appServiceWeb 'Microsoft.Web/sites@2022-03-01' = {
name: nameWeb
location: location
tags: tags
kind: kind
identity: {
type: 'SystemAssigned'
}
properties: {
serverFarmId: appServicePlan_id
siteConfig: {
appSettings: [
...
]
connectionStrings: [for connectionString in connectionStrings: {
name: connectionString.name
connectionString: connectionString.connectionString
type: connectionString.type
}]
}
}
}

我收到以下错误:

{
"code": "InvalidRequestContent",
"message": "The request content was invalid and could not be deserialized: 'Cannot deserialize the current JSON array (e.g. [1,2,3]) into type 'Azure.Deployments.Core.Definitions.DeploymentParameterDefinition' because the type requires a JSON object (e.g. {\"name\":\"value\"}) to deserialize correctly.\r\nTo fix this error either change the JSON to a JSON object (e.g. {\"name\":\"value\"}) or change the deserialized type to an array or a type that implements a collection interface (e.g. ICollection, IList) like List<T> that can be deserialized from a JSON array. JsonArrayAttribute can also be added to the type to force it to deserialize from a JSON array.\r\nPath 'properties.parameters.connectionStrings', line 1, position 280.'."
}

最佳答案

我已经成功解决了我的问题。虽然我的 Json 结构是合法的,但它不是二头肌文件的正确结构。

我需要添加下面的value部分:

"connectionStrings": {
"value": [
{
"name": "TrackingEntities",
"connectionString": "...",
"type": "SQLServer"
}
]
},

关于arrays - 将参数文件中的连接字符串数组传递到 bicep 文件,以用于应用程序服务的循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75458578/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com