0

I am trying to do auto restore of a bacpac to azure mssql VM when it is provisioned but failing to do so using custom scripts extensions. I generated the Azure MSSSQL VM ARM template using automation scripts in portal and If I see this in detail, i see that it is already using a custom extension to setup mssql on the VM post provisioning. If i need to restore a DB on top of it post provisioning, I need an other custom script extension resource. I cant think of any other way around. But No matter what i try, the keep getting syntax error in the second custom script extension, 'DependsOn' tag. any help to get this done will be appreciated. Please note i have tried adding resource names in various ways in DependsOn but keep getting error.

"message": "Deployment template validation failed: 'The template resource 'dbrestore' at line '1' and column '7717' is not valid: The resource identificator 'bugtvm/SqlIaasExtension' is malformed. Please see https://aka.ms/arm-template-expressions/#reference for usage details.. Please see https://aka.ms/arm-template-expressions for usage details.'.", "target": null

Thanks

{
  "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 Answers1

0

The root reason is "[concat(parameters('virtualMachineName'),'/', 'SqlIaasExtension')]" is not exist. You should modify it like below:

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

You could check this link.

Update from OP:

The segment error went once i changes the name field from 'restoredb' to "[concat(parameters('virtualMachineName'),'/restoredb')]" . it had nothing to do with multiple customscriptextensions

Shui shengbao
  • 3,503
  • 1
  • 10
  • 20
  • This [question](https://stackoverflow.com/questions/45752453/multiple-extensions-for-a-vm-with-azure-arm) maybe helpful. – Shui shengbao Mar 05 '18 at 07:25
  • thanks. I tried and get new error. seems to a be separate issue now. It was the missing /extentions after VM name. The other example does not have it either. "message": "Deployment template validation failed: 'The template resource 'dbrestore' for type 'Microsoft.Compute/virtualMachines/extensions' at line '1' and column '7717' has incorrect segment lengths. A nested resource type must have identical number of segments as its resource name. A root resource type must have segment length one greater than its resource name. Please see https://aka.ms/arm-template/#resources for usage details.'.", – Rajan Bhayana Mar 05 '18 at 07:37
  • something wrong with the type property? https://blogs.msdn.microsoft.com/kaevans/2015/11/22/creating-arm-templates-with-azure-resource-explorer/ – Rajan Bhayana Mar 05 '18 at 07:39
  • Could you find the line you get the error log? – Shui shengbao Mar 05 '18 at 07:43
  • no. col 7717 is here. "SQLAuthUpdateUserName": "[parameters('sqlAuthenticationLogin')]" but i doubt this might be the error – Rajan Bhayana Mar 05 '18 at 07:50
  • Hi, you could check this [link](https://github.com/Azure/azure-quickstart-templates/blob/master/201-dependency-between-scripts-using-extensions/azuredeploy.json), you could not install two custom script extension at a template. You need use [`Microsoft.Resources/deployments`](https://github.com/Azure/azure-quickstart-templates/blob/master/201-dependency-between-scripts-using-extensions/azuredeploy.json#L190) to do this. – Shui shengbao Mar 05 '18 at 07:57
  • On your scenario, your script stores in a private blob. You need use a sas token to get it. See this link https://docs.microsoft.com/en-us/azure/azure-resource-manager/resource-group-linked-templates#securing-an-external-template – Shui shengbao Mar 05 '18 at 08:00
  • I test it on Azure Portal, it also like this https://imgur.com/a/prR0r – Shui shengbao Mar 05 '18 at 08:01
  • Let us [continue this discussion in chat](https://chat.stackexchange.com/rooms/74043/discussion-between-shengbao-shui-msft-and-rajan-bhayana). – Shui shengbao Mar 05 '18 at 08:01
  • 1
    just to update post chat - I WAS ABLE to run multiple customscriptextensions for same VM using same arm template. For some reason, the segment error went once i changes the name field from 'restoredb' to "[concat(parameters('virtualMachineName'),'/restoredb')]" . it had nothing to do with multiple customscriptextensions – Rajan Bhayana Mar 05 '18 at 12:45
  • If possible, you could accept it as an answer. I think it will help more people. – – Shui shengbao Mar 09 '18 at 08:24