部署ARM模板时收到以下错误

时间:2019-09-03 10:05:23

标签: sql-server-2016 azure-resource-manager arm-template

在部署ARM模板时,我一直收到以下错误消息。

  

无法处理资源的模板语言表达式   '/subscriptions/dxxxxb-5xxa-4xx46-xxx49-500fxxxxx49/resourceGroups/Cluxxrxxx/providers/Microsoft.Compute/virtualMachines/Clustertest0'   在“ 123”行和“ 9”列。 '无法评估模板语言   函数'resourceId':所有函数参数必须为字符串文字

{
    "$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "location": {
            "type": "string"
        },
        "enableAcceleratedNetworking": {
            "type": "bool"
        },
        "subnetName": {
            "type": "string"
        },
        "virtualMachineName": {
            "type": "string"
        },
        "osDiskType": {
            "type": "string"
        },
        "dataDisks": {
            "type": "array"
        },
        "virtualMachineSize": {
            "type": "string"
        },
        "adminUsername": {
            "type": "string"
        },
        "adminPassword": {
            "type": "securestring"
        },
        "diagnosticsStorageAccountName": {
            "type": "string"
        },
        "sqlVirtualMachineLocation": {
            "type": "string"
        },
        "sqlVirtualMachineName": {
            "type": "string"
        },
        "sqlConnectivityType": {
            "type": "string"
        },
        "sqlPortNumber": {
            "type": "int"
        },
        "sqlStorageDisksCount": {
            "type": "int"
        },
        "sqlStorageWorkloadType": {
            "type": "string"
        },
        "sqlStorageDisksConfigurationType": {
            "type": "string"
        },
        "sqlStorageStartingDeviceId": {
            "type": "int"
        },
        "sqlStorageDeploymentToken": {
            "type": "int"
        },
        "sqlAutopatchingDayOfWeek": {
            "type": "string"
        },
        "sqlAutopatchingStartHour": {
            "type": "string"
        },
        "sqlAutopatchingWindowDuration": {
            "type": "string"
        },
        "sqlAuthenticationLogin": {
            "type": "string"
        },
        "sqlAuthenticationPassword": {
            "type": "securestring"
        },
        "rServicesEnabled": {
            "type": "string"
        },
        "numberOfInstances": {
            "type": "int"
        },
        "virtualNetworkRgName": {
            "type": "string"
        },
        "virtualNetworkName": {
            "type": "string"
        }
    },
    "variables": {
        "vnetId": "[resourceId('Microsoft.Network/virtualNetworks', parameters('virtualNetworkName'))]",
        "subnetRef": "[concat(variables('vnetId'), '/subnets/', parameters('subnetName'))]",
        "nicSuffix": "NIC",
        "networkInterfaceName": "[concat(parameters('virtualMachineName'), variables('nicSuffix'))]"
    },
    "resources": [
        {
            "name": "[concat(variables('networkInterfaceName'), copyindex())]",
            "type": "Microsoft.Network/networkInterfaces",
            "apiVersion": "2018-10-01",
            "location": "[parameters('location')]",
            "copy": {
                "name": "nicLoop",
                "count": "[parameters('numberOfInstances')]"
            },
            "properties": {
                "ipConfigurations": [
                    {
                        "name": "ipconfig1",
                        "properties": {
                            "subnet": {
                                "id": "[variables('subnetRef')]"
                            },
                            "privateIPAllocationMethod": "Dynamic"
                        }
                    }
                ],
                "enableAcceleratedNetworking": "[parameters('enableAcceleratedNetworking')]"
            }
        },
        {
            "name": "[concat(parameters('virtualMachineName'), copyindex())]",
            "type": "Microsoft.Compute/virtualMachines",
            "apiVersion": "2018-10-01",
            "location": "[parameters('location')]",
            "zones": "[split(string(add(mod(copyIndex(),3),1)), ',')]",
            "dependsOn": [
                "nicLoop"
            ],
            "copy": {
                "name": "virtualMachineLoop",
                "count": "[parameters('numberOfInstances')]"
            },
            "properties": {
                "hardwareProfile": {
                    "vmSize": "[parameters('virtualMachineSize')]"
                },
                "storageProfile": {
                    "osDisk": {
                        "createOption": "FromImage",
                        "managedDisk": {
                            "storageAccountType": "[parameters('osDiskType')]"
                        }
                    },
                    "imageReference": {
                        "publisher": "MicrosoftSQLServer",
                        "offer": "SQL2016SP2-WS2016",
                        "sku": "Enterprise",
                        "version": "latest"
                    },
                    "copy": [
                        {
                            "name": "dataDisks",
                            "count": "[length(parameters('dataDisks'))]",
                            "input": {
                                "lun": "[parameters('dataDisks')[copyIndex('dataDisks')].lun]",
                                "createOption": "[parameters('dataDisks')[copyIndex('dataDisks')].createOption]",
                                "caching": "[parameters('dataDisks')[copyIndex('dataDisks')].caching]",
                                "writeAcceleratorEnabled": "[parameters('dataDisks')[copyIndex('dataDisks')].writeAcceleratorEnabled]",
                                "diskSizeGB": "[parameters('dataDisks')[copyIndex('dataDisks')].diskSizeGB]",
                                "managedDisk": {
                                    "id": "[coalesce(parameters('dataDisks')[copyIndex('dataDisks')].id, if(equals(parameters('dataDisks')[copyIndex('dataDisks')].name, json('null')), json('null'), resourceId('Microsoft.Compute/disks', parameters('dataDisks')[copyIndex('dataDisks')].name)))]",
                                    "storageAccountType": "[parameters('dataDisks')[copyIndex('dataDisks')].storageAccountType]"
                                }
                            }
                        }
                    ]
                },
                "networkProfile": {
                    "networkInterfaces": [
                        {
                            "id": "[resourceId('Microsoft.Network/networkInterfaces', variables('networkInterfaceName'), copyindex())]"
                        }
                    ]
                },
                "osProfile": {
                    "computerName": "[parameters('virtualMachineName')]",
                    "adminUsername": "[parameters('adminUsername')]",
                    "adminPassword": "[parameters('adminPassword')]",
                    "windowsConfiguration": {
                        "enableAutomaticUpdates": true,
                        "provisionVmAgent": true
                    }
                },
                "diagnosticsProfile": {
                    "bootDiagnostics": {
                        "enabled": true,
                        "storageUri": "[concat('https://', parameters('diagnosticsStorageAccountName'), '.blob.core.windows.net/')]"
                    }
                }
            }
        },
        {
            "name": "[concat(parameters('sqlVirtualMachineName'), copyindex())]",
            "type": "Microsoft.SqlVirtualMachine/SqlVirtualMachines",
            "apiVersion": "2017-03-01-preview",
            "location": "[parameters('sqlVirtualMachineLocation')]",
            "copy": {
                "name": "sqlvirtualMachineLoop",
                "count": "[parameters('numberOfInstances')]"
            },
            "dependsOn": [
                "virtualMachineLoop"
            ],
            "properties": {
                "virtualMachineResourceId": "[resourceId('Microsoft.Compute/virtualMachines', parameters('virtualMachineName'))]",
                "sqlManagement": "Full",
                "SqlServerLicenseType": "PAYG",
                "AutoPatchingSettings": {
                    "Enable": true,
                    "DayOfWeek": "[parameters('sqlAutopatchingDayOfWeek')]",
                    "MaintenanceWindowStartingHour": "[parameters('sqlAutopatchingStartHour')]",
                    "MaintenanceWindowDuration": "[parameters('sqlAutopatchingWindowDuration')]"
                },
                "KeyVaultCredentialSettings": {
                    "Enable": false,
                    "CredentialName": ""
                },
                "ServerConfigurationsManagementSettings": {
                    "SQLConnectivityUpdateSettings": {
                        "ConnectivityType": "[parameters('sqlConnectivityType')]",
                        "Port": "[parameters('sqlPortNumber')]",
                        "SQLAuthUpdateUserName": "[parameters('sqlAuthenticationLogin')]",
                        "SQLAuthUpdatePassword": "[parameters('sqlAuthenticationPassword')]"
                    },
                    "SQLWorkloadTypeUpdateSettings": {
                        "SQLWorkloadType": "[parameters('sqlStorageWorkloadType')]"
                    },
                    "SQLStorageUpdateSettings": {
                        "DiskCount": "[parameters('sqlStorageDisksCount')]",
                        "DiskConfigurationType": "[parameters('sqlStorageDisksConfigurationType')]",
                        "StartingDeviceID": "[parameters('sqlStorageStartingDeviceId')]"
                    },
                    "AdditionalFeaturesServerConfigurations": {
                        "IsRServicesEnabled": "[parameters('rServicesEnabled')]"
                    }
                }
            }
        }
    ],
    "outputs": {
        "adminUsername": {
            "type": "string",
            "value": "[parameters('adminUsername')]"
        }
    }
}

1 个答案:

答案 0 :(得分:0)

您的错误似乎在这里:

"[resourceId('Microsoft.Network/networkInterfaces', variables('networkInterfaceName'), copyindex())]"

您需要将其更改为此:

"[resourceId('Microsoft.Network/networkInterfaces', concat(variables('networkInterfaceName'), copyindex()))]"