0
votes

I am creating an azure marketplace offer using ARM template. I am creating a Linux VM using my ARM template. I need to run a custom configuration script post deploy. I followed the example provided in the azure quickstart repo.

https://github.com/Azure/azure-quickstart-templates/tree/master/100-marketplace-sample When I try to validate the template i get the following error.

{   "error": {
    "additionalInfo": [
      {
        "info": {
          "lineNumber": 166,
          "linePosition": 28,
          "path": "resources[1].type"
        },
        "type": "TemplateViolation"
      }
    ],
    "code": "InvalidTemplate",
    "details": null,
    "message": "Deployment template validation failed: 'The template resource 'configScript' at line '166' and column '28' is not valid. The type property is invalid. Please see https://aka.ms/arm-template/#resources for usage details.'.",
    "target": null   

},
"properties": null }

The script part of my template looks like

{
    "type": "extensions",
    "name": "configScript",
    "apiVersion": "2018-04-01",
    "location": "[parameters('location')]",
    "dependsOn": [
    "[parameters('vmName')]"
    ],
    "properties": {
    "publisher": "Microsoft.Azure.Extensions",
    "type": "CustomScript",
    "typeHandlerVersion": "2.0",
    "autoUpgradeMinorVersion": true,
    "settings": {
        "fileUris": [
        "[uri(parameters('_artifactsLocation'), concat('scripts/copyfilefromazure.sh', parameters('_artifactsLocationSasToken')))]"
        ]
    },
    "protectedSettings": {
        "commandToExecute": "[concat('bash ', variables('scriptFileName'), ' ', variables('scriptArgs'))]"
    }
    }
},
1
Do you have this inside of a VMs resources[]? You'll have the template's resources[] defined and then you should have the Microsoft.Compute/virtualMachines resources[] inside of that. Your CustomScript should be inside the VM resources[]Anthony Klotz

1 Answers

1
votes

The error means that it is a nested resource (the config object is nested inside the site object) the name needs to reflect this. So instead of config the name should be something like virtualMachines/extensions. I also needed to add the dependsOn section.

"dependsOn": ["[concat('Microsoft.Compute/virtualMachines/', concat(variables('vmName'),copyindex()))]"]

Here's the template that validated successfully:

{
  "name": "config-app",
  "type": "Extensions",
  "location": "[resourceGroup().location]",
  "apiVersion": "2019-03-01",
  "dependsOn": [
    "[concat('Microsoft.Compute/virtualMachines/', concat(variables('vmName'),copyindex()))]"
  ],
  "tags": {
    "displayName": "config-app"
  },
  "properties": {
    "publisher": "Microsoft.Azure.Extensions",
    "type": "CustomScript",
    "typeHandlerVersion": "2.0",
    "autoUpgradeMinorVersion": true,
    "settings": {
      "skipDos2Unix":false,
      "timestamp":123456789          
    },
    "protectedSettings": {
       "commandToExecute": "<command-to-execute>",
       "script": "<base64-script-to-execute>",
       "storageAccountName": "<storage-account-name>",
       "storageAccountKey": "<storage-account-key>",
       "fileUris": ["https://.."]  
    }
  }
}

For more details, you could read this article Use the Azure Custom Script Extension Version 2 with Linux virtual machines.