Azure ARM 模板 - VM 的多个 Microsoft.Compute/virtualMachines/extensions

Azure ARM 模板 - VM 的多个 Microsoft.Compute/virtualMachines/extensions

我正在尝试在配置 bacpac 时自动还原到 azure mssql VM,但使用自定义脚本扩展无法做到这一点。我使用门户中的自动化脚本生成了 Azure MSSSQL VM ARM 模板,如果我详细查看此模板,我会看到它已经在使用自定义扩展在配置后的 VM 上设置 mssql。如果我需要在配置后在其上恢复数据库,我需要其他自定义脚本扩展资源。我想不出其他办法了。但无论我怎么尝试,第二个自定义脚本扩展“DependsOn”标签中都会出现语法错误。任何帮助都将不胜感激。请注意,我已尝试在 DependsOn 中以各种方式添加资源名称,但一直出现错误。

“消息”:“部署模板验证失败:‘第 1 行和第 7717 列的模板资源‘dbrestore’无效:资源标识符‘bugtvm/SqlIaasExtension’格式不正确。请参阅https://aka.ms/arm-template-expressions/#reference有关使用详情,请参阅https://aka.ms/arm-template-expressions了解使用详情。'", "target": null

谢谢

{
  "name": "[parameters('virtualMachineName')]",
  "type": "Microsoft.Compute/virtualMachines",
  "apiVersion": "2016-04-30-preview",
  "location": "[parameters('location')]",
  "dependsOn": [
    "[concat('Microsoft.Network/networkInterfaces/', parameters('networkInterfaceName'))]",
    "[concat('Microsoft.Storage/storageAccounts/', parameters('diagnosticsStorageAccountName'))]"
  ],
  "properties": {
    "osProfile": {
      "computerName": "[parameters('virtualMachineName')]",
      "adminUsername": "[parameters('adminUsername')]",
      "adminPassword": "[parameters('adminPassword')]",
      "windowsConfiguration": {
        "provisionVmAgent": "true"
      }
    },
    "hardwareProfile": {
      "vmSize": "[parameters('virtualMachineSize')]"
    },
    "storageProfile": {
      "imageReference": {
        "publisher": "MicrosoftSQLServer",
        "offer": "SQL2016SP1-WS2016",
        "sku": "Web",
        "version": "latest"
      },
      "osDisk": {
        "createOption": "fromImage",
        "managedDisk": {
          "storageAccountType": "Standard_LRS"
        }
      },
      "dataDisks": [
        {
          "createOption": "empty",
          "lun": 0,
          "diskSizeGB": "128",
          "caching": "ReadOnly",
          "managedDisk": {
            "storageAccountType": "Standard_LRS"
          }
        }
      ]
    },
    "networkProfile": {
      "networkInterfaces": [
        {
          "id": "[resourceId('Microsoft.Network/networkInterfaces', parameters('networkInterfaceName'))]"
        }
      ]
    },
    "diagnosticsProfile": {
      "bootDiagnostics": {
        "enabled": true,
        "storageUri": "[reference(resourceId('Microsoft.Storage/storageAccounts', parameters('diagnosticsStorageAccountName')), '2015-06-15').primaryEndpoints['blob']]"
      }
    }
  }
},
{
  "apiVersion": "2015-06-15",
  "type": "Microsoft.Compute/virtualMachines/extensions",
  "name": "[concat(parameters('virtualMachineName'), '/SqlIaasExtension')]",
  "location": "[parameters('location')]",
  "dependsOn": [
    "[concat('Microsoft.Compute/virtualMachines/', parameters('virtualMachineName'))]"
  ],
  "properties": {
    "type": "SqlIaaSAgent",
    "publisher": "Microsoft.SqlServer.Management",
    "typeHandlerVersion": "1.2",
    "autoUpgradeMinorVersion": "true",
    "settings": {
      "AutoTelemetrySettings": {
        "Region": "[parameters('location')]"
      },
      "AutoPatchingSettings": {
        "PatchCategory": "WindowsMandatoryUpdates",
        "Enable": true,
        "DayOfWeek": "[parameters('sqlAutopatchingDayOfWeek')]",
        "MaintenanceWindowStartingHour": "[parameters('sqlAutopatchingStartHour')]",
        "MaintenanceWindowDuration": "[parameters('sqlAutopatchingWindowDuration')]"
      },
      "AutoBackupSettings": {
        "Enable": true,
        "RetentionPeriod": "[parameters('sqlAutobackupRetentionPeriod')]",
        "EnableEncryption": false
      },
      "KeyVaultCredentialSettings": {
        "Enable": false,
        "CredentialName": ""
      },
      "ServerConfigurationsManagementSettings": {
        "SQLConnectivityUpdateSettings": {
          "ConnectivityType": "[parameters('sqlConnectivityType')]",
          "Port": "[parameters('sqlPortNumber')]"
        },
        "SQLWorkloadTypeUpdateSettings": {
          "SQLWorkloadType": "[parameters('sqlStorageWorkloadType')]"
        },
        "SQLStorageUpdateSettings": {
          "DiskCount": "[parameters('sqlStorageDisksCount')]",
          "NumberOfColumns": "[parameters('sqlStorageDisksCount')]",
          "StartingDeviceID": "[parameters('sqlStorageStartingDeviceId')]",
          "DiskConfigurationType": "[parameters('sqlStorageDisksConfigurationType')]"
        },
        "AdditionalFeaturesServerConfigurations": {
          "IsRServicesEnabled": "[parameters('rServicesEnabled')]"
        }
      }
    },
    "protectedSettings": {
      "StorageUrl": "[reference(resourceId('Microsoft.Storage/storageAccounts', parameters('diagnosticsStorageAccountName')), '2015-06-15').primaryEndpoints['blob']]",
      "StorageAccessKey": "[listKeys(resourceId('Microsoft.Storage/storageAccounts', parameters('diagnosticsStorageAccountName')), '2015-06-15').key1]",
      "SQLAuthUpdateUserName": "[parameters('sqlAuthenticationLogin')]",
      "SQLAuthUpdatePassword": "[parameters('sqlAuthenticationPassword')]"
    }
  }
},
{
  "apiVersion": "2015-06-15",
  "type": "Microsoft.Compute/virtualMachines/extensions",
  "name": "dbrestore",
  "location": "[resourceGroup().location]",
  "dependsOn": [
    "[concat('Microsoft.Compute/virtualMachines/', parameters('virtualMachineName') )]",
    "[concat(parameters('virtualMachineName'),'/', 'SqlIaasExtension')]"
  ],
  "properties": {
    "publisher": "Microsoft.Compute",
    "type": "CustomScriptExtension",
    "typeHandlerVersion": "1.9",
    "autoUpgradeMinorVersion": true,
    "settings": {
      "fileUris": [
        "https://somestoragehere.blob.core.windows.net/dbbackups/restorescript.ps1"
      ]
    },
    "protectedSettings": {
      "commandToExecute": "powershell -ExecutionPolicy Unrestricted -File restorescript.ps1",
      "storageAccountName": "some storage here",
      "storageAccountKey": "some key here"
    }
  }
},

答案1

根本原因是"[concat(parameters('virtualMachineName'),'/', 'SqlIaasExtension')]"不存在。您应该按如下方式进行修改:

   "[concat('Microsoft.Compute/virtualMachines/', parameters('virtualMachineName'),'/extensions/SqlIaasExtension')]"

你可以检查一下关联

来自OP的更新:

一旦我将名称字段从“restoredb”更改为,就会出现段错误"[concat(parameters('virtualMachineName'),'/restoredb')]"。它与多个 customscriptextensions 无关

相关内容