ARM 模板语法将对象类型的参数注入到类型也需要对象的字段中?
ARM template syntax to inject an param of type object into a field who's type is also expecting an object?
我的目标是将 AppSettings 动态注入到托管在 Azure 应用服务产品上的 .NET 应用程序中。我有一些设置,例如key3
和 key4
我想注入一个 copy loop 定义在一个名为 appList
的参数中,它将对我的所有应用程序可用。
我正在尝试 figure out the syntax to inject a defined parameter of mine named myAppSettings
of type object
. I've looked at Microsoft's docs regarding using objects as parameters 但它不太适合我的情况。
这是我的代码
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": {}
}
错误正在行中抛出
"properties": { [parameters('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')]"
如果 variable\parameter 是一个对象,而某些东西需要一个对象,只需传递 variable\parameter。
同样适用于数组。
我的目标是将 AppSettings 动态注入到托管在 Azure 应用服务产品上的 .NET 应用程序中。我有一些设置,例如key3
和 key4
我想注入一个 copy loop 定义在一个名为 appList
的参数中,它将对我的所有应用程序可用。
我正在尝试 figure out the syntax to inject a defined parameter of mine named myAppSettings
of type object
. I've looked at Microsoft's docs regarding using objects as parameters 但它不太适合我的情况。
这是我的代码
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": {}
}
错误正在行中抛出
"properties": { [parameters('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')]"
如果 variable\parameter 是一个对象,而某些东西需要一个对象,只需传递 variable\parameter。
同样适用于数组。