gpt4 book ai didi

azure - ARM模板语法将类型对象的参数注入(inject)到类型也需要对象的字段中?

转载 作者:行者123 更新时间:2023-12-02 07:48:39 25 4
gpt4 key购买 nike

我的目标是将 AppSettings 动态注入(inject)到托管在 Azure 应用服务产品上的 .NET 应用程序中。我有一些设置,例如我想将它们注入(inject) copy loop 中的 key3key4在名为 appList 的参数中定义,该参数可用于我的所有应用。

我正在尝试figure out the syntax注入(inject)我的定义参数,名为 myAppSettings,类型为 object。我查看了有关 using objects as parameters 的 Microsoft 文档但它不太适合我的情况。

这是我的代码

azuredeploy.json

{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"aspName": { "value": "my-asp" },
"aspSkuName": { "value": "B1" },
"webAppNameHostnameSuffix": { "value": "myhost.com" },
"appList": { "value": [ "myapp1", "myapp2", "myapp3","myapp4"] }
"myAppSettings": {
"value": {
"key3": "value3",
"key4": "value4"
}
}
}
}

azuredeploy.parameters.json

{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"aspName": { "type": "string", "minLength": 1,"metadata": { "description": "Name of App Service Plan" } },
"aspSkuName": {"type": "string", "allowedValues": [ "F1", "D1", "B1", "B2", "B3", "S1", "S2", "S3", "P1", "P2", "P3", "P4" ] },
"appList": { "type": "array" },
"myAppSettings": { "type": "object" }
},
"variables": {},
"resources": [
{
"name": "[parameters('aspName')]",
"type": "Microsoft.Web/serverfarms",
"location": "[resourceGroup().location]",
"apiVersion": "2015-08-01",
"sku": { "name": "[parameters('aspSkuName')]" },
"tags": { "displayName": "asp1" },
"properties": {
"name": "[parameters('aspName')]",
"numberOfWorkers": 1
}
},
{
"name": "[concat(parameters('webAppAzureNamePrefix'), parameters('appList')[copyIndex()])]",
"copy": {
"name": "webAppCopy",
"count": "[length(parameters('appList'))]"
},
"type": "Microsoft.Web/sites",
"location": "[resourceGroup().location]",
"apiVersion": "2015-08-01",
"dependsOn": [ "[resourceId('Microsoft.Web/serverfarms', parameters('aspName'))]" ],
"tags": { "displayName": "webapp" },
"properties": {
"name": "[concat('some-prefix', parameters('appList')[copyIndex()])]",
"serverFarmId": "[resourceId('Microsoft.Web/serverfarms', parameters('aspName'))]"
},
"resources": [
{
"name": "appsettings",
"type": "config",
"apiVersion": "2015-08-01",
"dependsOn": [ "[resourceId('Microsoft.Web/sites', concat('some-prefix', parameters('appList')[copyIndex()]))]" ],
"tags": { "displayName": "appsettings" },
"properties": { [parameters('myAppSettings')] }
},
{
"name": "web",
"type": "config",
"apiVersion": "2015-08-01",
"dependsOn": [ "[resourceId('Microsoft.Web/sites', concat('some-prefix', parameters('appList')[copyIndex()]))]" ],
"tags": { "displayName": "web" },
"properties": { "alwaysOn": true }
}
]
}
],
"outputs": {}
}

错误被抛出线上

“属性”:{ [参数('myAppSettings')] }

错误消息

[ERROR] New-AzureRmResourceGroupDeployment : Invalid character after parsing property name. Expected ':' but got: }. Path 
[ERROR] 'resources[1].resources[0].properties', line 62, position 57.
[ERROR] At line:3 char:1

最佳答案

"properties": "[parameters('myAppSettings')]"

如果变量\参数是一个对象并且某些东西需要一个对象,则只需传递变量\参数即可。

数组也是如此。

关于azure - ARM模板语法将类型对象的参数注入(inject)到类型也需要对象的字段中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47056073/

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