Azure ARM-Vorlage – mehrere Microsoft.Compute/virtualMachines/Erweiterungen für VM

Azure ARM-Vorlage – mehrere Microsoft.Compute/virtualMachines/Erweiterungen für VM

Ich versuche, eine BACPAC automatisch auf einer Azure MSSQL-VM wiederherzustellen, wenn sie bereitgestellt wird, aber dies gelingt mir nicht mit benutzerdefinierten Skripterweiterungen. Ich habe die Azure MSSSQL VM ARM-Vorlage mithilfe von Automatisierungsskripten im Portal generiert und wenn ich mir dies im Detail ansehe, sehe ich, dass bereits eine benutzerdefinierte Erweiterung verwendet wird, um MSSQL nach der Bereitstellung auf der VM einzurichten. Wenn ich nach der Bereitstellung eine Datenbank darüber wiederherstellen muss, benötige ich eine andere benutzerdefinierte Skripterweiterungsressource. Mir fällt kein anderer Weg ein. Aber egal, was ich versuche, ich erhalte immer wieder einen Syntaxfehler in der zweiten benutzerdefinierten Skripterweiterung, dem Tag „DependsOn“. Jede Hilfe, um dies zu erledigen, ist willkommen. Bitte beachten Sie, dass ich versucht habe, Ressourcennamen auf verschiedene Weise in DependsOn hinzuzufügen, aber immer wieder einen Fehler erhalte.

"Nachricht": "Die Validierung der Bereitstellungsvorlage ist fehlgeschlagen: 'Die Vorlagenressource 'dbrestore' in Zeile '1' und Spalte '7717' ist ungültig: Die Ressourcenkennung 'bugtvm/SqlIaasExtension' ist fehlerhaft. Bitte lesen Siehttps://aka.ms/arm-template-expressions/#referencefür Einzelheiten zur Nutzung. Bitte sehen Siehttps://aka.ms/arm-template-expressionsfür Nutzungsdetails.'.", "target": null

Danke

{
  "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"
    }
  }
},

Antwort1

Der Grund dafür ist, "[concat(parameters('virtualMachineName'),'/', 'SqlIaasExtension')]"dass er nicht existiert. Sie sollten ihn wie folgt ändern:

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

Sie können dies überprüfenVerknüpfung.

Update vom OP:

Der Segmentfehler trat auf, nachdem ich das Namensfeld von 'restoredb' in geändert hatte "[concat(parameters('virtualMachineName'),'/restoredb')]". Es hatte nichts mit mehreren Customscriptextensions zu tun.

verwandte Informationen