Azure VMSS custom script extension error - unable to download script files - azure

I'm running the custom template deployment which includes a Linux VM and a Linux-based VMSS.
Both operations (VM creation and VMSS creation) involves the CustomScriptExtension.
The scripts used for post-configuration are the same for VM and VMSS.
They have the same reference inside the template.
However, the deployment for VM is completed succesfully but for VMSS is ended with an error.
When checking resource group in Azure portal, VMSS is created successfully and shows activity (CPU, memory etc).
In "Extensions" blade I can see my predefined extension:
However the state is "Failed". When clicking on "Failed" to see the details the following error is shown:
Message: VM has reported a failure when processing extension 'filesextension'. Error message: "Enable failed: processing file downloads failed: failed to download file[1]: failed to download file: unexpected status code: actual=404 expected=200" More information on troubleshooting is available at https://aka.ms/VMExtensionCSELinuxTroubleshoot
Azure portal deployment error:
{
"status": "Failed",
"error": {
"code": "ResourceDeploymentFailure",
"message": "The resource operation completed with terminal provisioning state 'Failed'.",
"details": [
{
"code": "VMExtensionProvisioningError",
"message": "VM has reported a failure when processing extension 'filesextension'. Error message: \"Enable failed: processing file downloads failed: failed to download file[1]: failed to download file: unexpected status code: actual=404 expected=200\"\r\n\r\nMore information on troubleshooting is available at https://aka.ms/VMExtensionCSELinuxTroubleshoot "
}
]
}
}
The same error is when deploying via CLI:
Deployment failed. Correlation ID: f077af77-405b-49fe-9f95-bf42a722c7ec. {
"status": "Failed",
"error": {
"code": "ResourceDeploymentFailure",
"message": "The resource operation completed with terminal provisioning state 'Failed'.",
"details": [
{
"code": "VMExtensionProvisioningError",
"message": "VM has reported a failure when processing extension 'filesextension'. Error message: \"Enable failed: processing file downloads failed: failed to download file[0]: failed to download file: unexpected status code: actual=404 expected=200\"\r\n\r\nMore information on troubleshooting is available at https://aka.ms/VMExtensionCSELinuxTroubleshoot "
}
ARM template itself:
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"location": {
"defaultValue": "[resourceGroup().location]",
"type": "String",
"metadata": {
"description": "Location for all resources"
}
},
"dnsNameForJumpBox": {
"type": "String",
"metadata": {
"description": "Unique DNS Name for the Public IP used to access the Docker Virtual Machine (master node)."
}
},
"vmImageReference": {
"defaultValue": {
"publisher": "Canonical",
"offer": "UbuntuServer",
"sku": "16.04-LTS",
"version": "latest"
},
"type": "Object",
"metadata": {
"description": "The image to use for VMs created. This can be marketplace or custom image",
"link": "https://learn.microsoft.com/en-us/nodejs/api/azure-arm-compute/imagereference?view=azure-node-2.2.0"
}
},
"vmNodeSku": {
"defaultValue": "Standard_F8s_v2",
"type": "String",
"metadata": {
"description": "Size of VMs in the VM Scale Set."
}
},
"vmMasterSku": {
"defaultValue": "Standard_F16s_v2",
"type": "String",
"metadata": {
"description": "Size of the master node."
}
},
"vmMasterDiskType": {
"defaultValue": "Premium_LRS",
"allowedValues": [
"Premium_LRS",
"Standard_LRS"
],
"type": "String",
"metadata": {
"description": "Choose between a standard disk for and SSD disk for the master node's NFS fileshare"
}
},
"vmMasterDiskSize": {
"defaultValue": 256,
"allowedValues": [
32,
64,
128,
256,
512,
1000,
2000,
4000,
10000
],
"type": "Int",
"metadata": {
"description": "The SSD Size to be used for the NFS file share. For pricing details see https://azure.microsoft.com/en-us/pricing/details/managed-disks/"
}
},
"vmAdditionalInstallScriptUrl": {
"defaultValue": "",
"type": "String",
"metadata": {
"description": "An additional installs script (bash run as root) to be run after nodes/master are configured. Can be used to mount additional storage or do additional setup"
}
},
"vmAdditionalInstallScriptArgument": {
"defaultValue": "",
"type": "String",
"metadata": {
"description": "An argument to be passed to the additional install script"
}
},
"nextflowInstallUrl": {
"defaultValue": "https://get.nextflow.io",
"type": "String",
"metadata": {
"description": "The install URL for nextflow, this can be used to pin nextflow versions"
}
},
"instanceCount": {
"defaultValue": 2,
"maxValue": 100,
"type": "Int",
"metadata": {
"description": "Number of cluster VM instances (100 or less)."
}
},
"adminUsername": {
"type": "String",
"metadata": {
"description": "Admin username on all VMs."
}
},
"vnetName": {
"defaultValue": "nfvnet",
"type": "String",
"metadata": {
"description": "Name of the virtual network to deploy the scale set into."
}
},
"subnetName": {
"defaultValue": "nfsubnet",
"type": "String",
"metadata": {
"description": "Name of the subnet to deploy the scale set into."
}
},
"shareName": {
"defaultValue": "sharedstorage",
"type": "String",
"metadata": {
"description": "Azure file share name."
}
},
"mountpointPath": {
"defaultValue": "/datadisks/disk1",
"type": "String",
"metadata": {
"description": "Path on VM to mount file shares. '/datadisks/disk1/' is a Premium Managed disk with high iops, this will suit most uses."
}
},
"nodeMaxCpus": {
"defaultValue": 2,
"type": "Int",
"metadata": {
"description": "Sets the cluster.maxCpus setting on all cluster nodes"
}
},
"_artifactsLocation": {
"defaultValue": "https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master",
"type": "String",
"metadata": {
"description": "*Advanced* This is best left as default unless you are an advanced user. The base URI where artifacts required by this template are located."
}
},
"_artifactsLocationSasToken": {
"defaultValue": "",
"type": "SecureString",
"metadata": {
"description": "*Advanced* This should be left as default unless you are an advanced user. The sasToken required to access _artifactsLocation. When the template is deployed using the accompanying scripts, a sasToken will be automatically generated."
}
},
"_artifactsSharedFolder": {
"defaultValue": "shared_scripts/ubuntu",
"type": "String",
"metadata": {
"description": "*Advanced* This should be left as default unless you are an advanced user. The folder in the artifacts location were shared scripts are stored."
}
},
"_artifactsNextflowFolder": {
"defaultValue": "nextflow-genomics-cluster-ubuntu/scripts",
"type": "String",
"metadata": {
"description": "*Advanced* This should be left as default unless you are an advanced user. The folder in the artifacts location were nextflow scripts are stored."
}
},
"authenticationType": {
"defaultValue": "sshPublicKey",
"allowedValues": [
"sshPublicKey",
"password"
],
"type": "String",
"metadata": {
"description": "Type of authentication to use on the Virtual Machine. SSH key is recommended."
}
},
"adminPasswordOrKey": {
"type": "SecureString",
"metadata": {
"description": "SSH Key or password for the Virtual Machine. SSH key is recommended."
}
}
},
"variables": {
"nextflowInitScript": "[uri(parameters('_artifactsLocation'), concat(parameters('_artifactsNextflowFolder'), '/init.sh', parameters('_artifactsLocationSasToken')))]",
"diskInitScript": "[uri(parameters('_artifactsLocation'), concat(parameters('_artifactsSharedFolder'), '/vm-disk-utils-0.1.sh', parameters('_artifactsLocationSasToken')))]",
"jumpboxNICName": "jumpboxNIC",
"addressPrefix": "10.0.0.0/16",
"subnetPrefix": "10.0.0.0/24",
"vmssName": "[concat('cluster', uniqueString(parameters('dnsNameForJumpBox')))]",
"storageAccountType": "Standard_LRS",
"storageAccountName": "[concat('nfstorage', uniqueString(resourceGroup().id))]",
"publicIPAddressName": "jumpboxPublicIP",
"publicIPAddressType": "Dynamic",
"jumpboxVMName": "jumpboxVM",
"subnetRef": "[resourceId('Microsoft.Network/virtualNetworks/subnets', parameters('vnetName'), parameters('subnetName'))]",
"linuxConfiguration": {
"disablePasswordAuthentication": true,
"ssh": {
"publicKeys": [
{
"path": "[concat('/home/', parameters('adminUsername'), '/.ssh/authorized_keys')]",
"keyData": "[parameters('adminPasswordOrKey')]"
}
]
}
},
"networkSecurityGroupName": "default-NSG"
},
"resources": [
{
"type": "Microsoft.Storage/storageAccounts",
"apiVersion": "2016-01-01",
"name": "[variables('storageAccountName')]",
"location": "[parameters('location')]",
"sku": {
"name": "[variables('storageAccountType')]"
},
"kind": "Storage"
},
{
"type": "Microsoft.Network/publicIPAddresses",
"apiVersion": "2017-06-01",
"name": "[variables('publicIPAddressName')]",
"location": "[parameters('location')]",
"properties": {
"publicIPAllocationMethod": "[variables('publicIPAddressType')]",
"dnsSettings": {
"domainNameLabel": "[parameters('dnsNameForJumpBox')]"
}
}
},
{
"type": "Microsoft.Network/networkSecurityGroups",
"apiVersion": "2019-08-01",
"name": "[variables('networkSecurityGroupName')]",
"location": "[parameters('location')]",
"properties": {
"securityRules": [
{
"name": "default-allow-22",
"properties": {
"priority": 1000,
"access": "Allow",
"direction": "Inbound",
"destinationPortRange": "22",
"protocol": "Tcp",
"sourceAddressPrefix": "*",
"sourcePortRange": "*",
"destinationAddressPrefix": "*"
}
}
]
}
},
{
"type": "Microsoft.Network/virtualNetworks",
"apiVersion": "2017-06-01",
"name": "[parameters('vnetName')]",
"location": "[parameters('location')]",
"dependsOn": [
"[resourceId('Microsoft.Network/networkSecurityGroups', variables('networkSecurityGroupName'))]"
],
"properties": {
"addressSpace": {
"addressPrefixes": [
"[variables('addressPrefix')]"
]
},
"subnets": [
{
"name": "[parameters('subnetName')]",
"properties": {
"addressPrefix": "[variables('subnetPrefix')]",
"networkSecurityGroup": {
"id": "[resourceId('Microsoft.Network/networkSecurityGroups', variables('networkSecurityGroupName'))]"
}
}
}
]
}
},
{
"type": "Microsoft.Network/networkInterfaces",
"apiVersion": "2017-06-01",
"name": "[variables('jumpboxNICName')]",
"location": "[parameters('location')]",
"dependsOn": [
"[concat('Microsoft.Network/publicIPAddresses/', variables('publicIPAddressName'))]",
"[concat('Microsoft.Network/virtualNetworks/', parameters('vnetName'))]"
],
"properties": {
"ipConfigurations": [
{
"name": "ipconfig1",
"properties": {
"privateIPAllocationMethod": "Dynamic",
"publicIPAddress": {
"id": "[resourceId('Microsoft.Network/publicIPAddresses',variables('publicIPAddressName'))]"
},
"subnet": {
"id": "[variables('subnetRef')]"
}
}
}
]
}
},
{
"type": "Microsoft.Compute/virtualMachines",
"apiVersion": "2017-03-30",
"name": "[variables('jumpboxVMName')]",
"location": "[parameters('location')]",
"dependsOn": [
"[concat('Microsoft.Storage/storageAccounts/', variables('storageAccountName'))]",
"[concat('Microsoft.Network/networkInterfaces/', variables('jumpboxNICName'))]"
],
"properties": {
"hardwareProfile": {
"vmSize": "[parameters('vmMasterSKU')]"
},
"osProfile": {
"computerName": "[variables('jumpboxVMName')]",
"adminUsername": "[parameters('adminUsername')]",
"adminPassword": "[parameters('adminPasswordOrKey')]",
"linuxConfiguration": "[if(equals(parameters('authenticationType'), 'password'), json('null'), variables('linuxConfiguration'))]"
},
"storageProfile": {
"imageReference": "[parameters('vmImageReference')]",
"osDisk": {
"createOption": "FromImage"
},
"dataDisks": [
{
"lun": 0,
"name": "jumpboxdatadisk",
"diskSizeGB": "[parameters('vmMasterDiskSize')]",
"caching": "None",
"createOption": "Empty",
"managedDisk": {
"storageAccountType": "[parameters('vmMasterDiskType')]"
}
}
]
},
"networkProfile": {
"networkInterfaces": [
{
"id": "[resourceId('Microsoft.Network/networkInterfaces',variables('jumpboxNICName'))]"
}
]
}
}
},
{
"type": "Microsoft.Compute/virtualMachines/extensions",
"apiVersion": "2017-03-30",
"name": "[concat(variables('jumpboxVMName'),'/nfinit')]",
"location": "[parameters('location')]",
"dependsOn": [
"[concat('Microsoft.Compute/virtualMachines/', variables('jumpboxVMName'))]"
],
"properties": {
"publisher": "Microsoft.Azure.Extensions",
"type": "CustomScript",
"typeHandlerVersion": "2.0",
"autoUpgradeMinorVersion": true,
"forceUpdateTag": "rerunnow",
"settings": {
"fileUris": [
"[variables('nextflowInitScript')]",
"[variables('diskInitScript')]"
]
},
"protectedSettings": {
"commandToExecute": "[concat('bash init.sh ', variables('storageAccountName'), ' ', listKeys(resourceId('Microsoft.Storage/storageAccounts', variables('storageAccountName')), '2016-01-01').keys[0].value, ' ', parameters('shareName'), ' ', parameters('mountpointPath'), ' false ', parameters('adminUsername'), ' 0 ', parameters('nextflowInstallUrl'), ' ', parameters('vmAdditionalInstallScriptUrl'), ' ', parameters('vmAdditionalInstallScriptArgument'))]"
}
}
},
{
"type": "Microsoft.Compute/virtualMachineScaleSets",
"apiVersion": "2017-03-30",
"name": "[variables('vmssName')]",
"location": "[parameters('location')]",
"dependsOn": [
"[concat('Microsoft.Network/virtualNetworks/', parameters('vnetName'))]",
"[concat('Microsoft.Storage/storageAccounts/', variables('storageAccountName'))]"
],
"sku": {
"name": "[parameters('vmNodeSKU')]",
"capacity": "[parameters('instanceCount')]"
},
"properties": {
"overprovision": true,
"upgradePolicy": {
"mode": "Manual"
},
"virtualMachineProfile": {
"storageProfile": {
"osDisk": {
"createOption": "FromImage",
"caching": "ReadWrite"
},
"imageReference": "[parameters('vmImageReference')]"
},
"osProfile": {
"computerNamePrefix": "[variables('vmssName')]",
"adminUsername": "[parameters('adminUsername')]",
"adminPassword": "[parameters('adminPasswordOrKey')]",
"linuxConfiguration": "[if(equals(parameters('authenticationType'), 'password'), json('null'), variables('linuxConfiguration'))]"
},
"networkProfile": {
"networkInterfaceConfigurations": [
{
"name": "nic",
"properties": {
"primary": true,
"ipConfigurations": [
{
"name": "ipconfig",
"properties": {
"subnet": {
"id": "[resourceId(resourceGroup().name, 'Microsoft.Network/virtualNetworks/subnets', parameters('vnetName'), parameters('subnetName'))]"
}
}
}
]
}
}
]
},
"extensionProfile": {
"extensions": [
{
"name": "filesextension",
"properties": {
"publisher": "Microsoft.Azure.Extensions",
"type": "CustomScript",
"typeHandlerVersion": "2.0",
"autoUpgradeMinorVersion": true,
"forceUpdateTag": "rerunnow",
"settings": {
"fileUris": [
"[variables('nextflowInitScript')]",
"[variables('diskInitScript')]"
]
},
"protectedSettings": {
"commandToExecute": "[concat('bash init.sh ', variables('storageAccountName'), ' ', listKeys(resourceId('Microsoft.Storage/storageAccounts', variables('storageAccountName')), '2016-01-01').keys[0].value, ' ', parameters('shareName'), ' ', parameters('mountpointPath'), ' true ', parameters('adminUsername'), ' ', parameters('nodeMaxCpus'), ' ', parameters('nextflowInstallUrl'), ' ', parameters('vmAdditionalInstallScriptUrl'), ' ', parameters('vmAdditionalInstallScriptArgument'))]"
}
}
}
]
}
}
}
}
],
"outputs": {
"JumpboxConnectionString": {
"type": "String",
"value": "[concat('ssh ', parameters('adminUsername'), '#', reference(variables('publicIPAddressName')).dnsSettings.fqdn)]"
},
"ExampleNextflowCommand": {
"type": "String",
"value": "[concat('nextflow run hello -process.executor ignite -cluster.join path:', parameters('mountpointPath'), '/cifs/cluster', ' -with-timeline runtimeline.html -with-trace -cluster.maxCpus 0')]"
},
"ExampleNextflowCommandWithDocker": {
"type": "String",
"value": "[concat('nextflow run nextflow-io/rnatoy -with-docker -process.executor ignite -cluster.join path:', parameters('mountpointPath'), '/cifs/cluster', ' -with-timeline runtimeline.html -with-trace -cluster.maxCpus 0')]"
}
}
}
I have only one suggestion that the extensionProfile part of the template isn't working as expected however was unable to find any proofs.
"extensionProfile": {
"extensions": [
{
"name": "filesextension",
"properties": {
"publisher": "Microsoft.Azure.Extensions",
"type": "CustomScript",
"typeHandlerVersion": "2.0",
"autoUpgradeMinorVersion": true,
"forceUpdateTag": "rerunnow",
"settings": {
"fileUris": [
"[variables('nextflowInitScript')]",
"[variables('diskInitScript')]"
]
},
"protectedSettings": {
"commandToExecute": "[concat('bash init.sh ', variables('storageAccountName'), ' ', listKeys(resourceId('Microsoft.Storage/storageAccounts', variables('storageAccountName')), '2016-01-01').keys[0].value, ' ', parameters('shareName'), ' ', parameters('mountpointPath'), ' true ', parameters('adminUsername'), ' ', parameters('nodeMaxCpus'), ' ', parameters('nextflowInstallUrl'), ' ', parameters('vmAdditionalInstallScriptUrl'), ' ', parameters('vmAdditionalInstallScriptArgument'))]"
}
}
}
]
}
}

Has the url with sas token worked at all? Check it by attempting to download the script in a browser after you have created the sas token.
If it works and then doesn't work later - this could be down to the sas token expiring after a set period. You can attempt to log the full url out after deploying of your vmss. Then try again and download the script from a browser.

Related

Getting ARM template deploy error "Could not find member 'securityType' ...."

I have a ARM template that works fine for creating a virtual machine (Windows Server 2022).
I added some variables for Trusted Launch:
"variables": {
"securityType": "TrustedLaunch",
"secureBoot": true,
"vTPMEnabled": true
},
In the virtual machine (Microsoft.Compute/virtualMachines) resources array I added the following:
"securityProfile": {
"securityType": "[variables('securityType')]",
"uefiSettings": {
"secureBootEnabled": "[variables('secureBoot')]",
"vTpmEnabled": "[variables('vTPMEnabled')]"
}
}
When I deploy the template and click Create, it gives the following error:
{"code":"DeploymentFailed","message":"At least one resource deployment operation failed. Please list deployment operations for details. Please see https://aka.ms/DeployOperations for usage details.","details":[{"code":"BadRequest","message":"Could not find member 'securityType' on object of type 'SecurityProfile'. Path 'properties.securityProfile.securityType', line 1, position 1186."}]}
I can go to Virtual Machines and create a VM with Security Type set to 'Trusted launch virtual machines' and it creates fine. When I download the template before clicking create and look at the JSON it is nearly identical (it uses parameters instead of variables, but I tried using variables and hardcoding the SecureProfiles and I get the same error). This is the SecureProfiles from the downloaded template JSON for reference:
securityProfile": {
securityType": "[parameters('securityType')]",
uefiSettings": {
secureBootEnabled": "[parameters('secureBoot')]",
vTpmEnabled": "[parameters('vTPM')]"
}
}
Looking for help on the error "Could not find member 'securityType'..." I am getting.
Trusted Launch VM ARM Template Reference
azure-deploy.json
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"adminUsername": {
"type": "string",
"metadata": {
"description": "Username for the Virtual Machine."
}
},
"adminPassword": {
"type": "secureString",
"minLength": 12,
"metadata": {
"description": "Password for the Virtual Machine."
}
},
"dnsLabelPrefix": {
"type": "string",
"defaultValue": "[toLower(format('{0}-{1}', parameters('vmName'), uniqueString(resourceGroup().id, parameters('vmName'))))]",
"metadata": {
"description": "Unique DNS Name for the Public IP used to access the Virtual Machine."
}
},
"publicIpName": {
"type": "string",
"defaultValue": "myPublicIP",
"metadata": {
"description": "Name for the Public IP used to access the Virtual Machine."
}
},
"publicIPAllocationMethod": {
"type": "string",
"defaultValue": "Dynamic",
"allowedValues": [
"Dynamic",
"Static"
],
"metadata": {
"description": "Allocation method for the Public IP used to access the Virtual Machine."
}
},
"publicIpSku": {
"type": "string",
"defaultValue": "Basic",
"allowedValues": [
"Basic",
"Standard"
],
"metadata": {
"description": "SKU for the Public IP used to access the Virtual Machine."
}
},
"OSVersion": {
"type": "string",
"defaultValue": "2022-datacenter-azure-edition-core",
"allowedValues": [
"2008-R2-SP1",
"2008-R2-SP1-smalldisk",
"2012-Datacenter",
"2012-datacenter-gensecond",
"2012-Datacenter-smalldisk",
"2012-datacenter-smalldisk-g2",
"2012-Datacenter-zhcn",
"2012-datacenter-zhcn-g2",
"2012-R2-Datacenter",
"2012-r2-datacenter-gensecond",
"2012-R2-Datacenter-smalldisk",
"2012-r2-datacenter-smalldisk-g2",
"2012-R2-Datacenter-zhcn",
"2012-r2-datacenter-zhcn-g2",
"2016-Datacenter",
"2016-datacenter-gensecond",
"2016-datacenter-gs",
"2016-Datacenter-Server-Core",
"2016-datacenter-server-core-g2",
"2016-Datacenter-Server-Core-smalldisk",
"2016-datacenter-server-core-smalldisk-g2",
"2016-Datacenter-smalldisk",
"2016-datacenter-smalldisk-g2",
"2016-Datacenter-with-Containers",
"2016-datacenter-with-containers-g2",
"2016-datacenter-with-containers-gs",
"2016-Datacenter-zhcn",
"2016-datacenter-zhcn-g2",
"2019-Datacenter",
"2019-Datacenter-Core",
"2019-datacenter-core-g2",
"2019-Datacenter-Core-smalldisk",
"2019-datacenter-core-smalldisk-g2",
"2019-Datacenter-Core-with-Containers",
"2019-datacenter-core-with-containers-g2",
"2019-Datacenter-Core-with-Containers-smalldisk",
"2019-datacenter-core-with-containers-smalldisk-g2",
"2019-datacenter-gensecond",
"2019-datacenter-gs",
"2019-Datacenter-smalldisk",
"2019-datacenter-smalldisk-g2",
"2019-Datacenter-with-Containers",
"2019-datacenter-with-containers-g2",
"2019-datacenter-with-containers-gs",
"2019-Datacenter-with-Containers-smalldisk",
"2019-datacenter-with-containers-smalldisk-g2",
"2019-Datacenter-zhcn",
"2019-datacenter-zhcn-g2",
"2022-datacenter",
"2022-datacenter-azure-edition",
"2022-datacenter-azure-edition-core",
"2022-datacenter-azure-edition-core-smalldisk",
"2022-datacenter-azure-edition-smalldisk",
"2022-datacenter-core",
"2022-datacenter-core-g2",
"2022-datacenter-core-smalldisk",
"2022-datacenter-core-smalldisk-g2",
"2022-datacenter-g2",
"2022-datacenter-smalldisk",
"2022-datacenter-smalldisk-g2"
],
"metadata": {
"description": "The Windows version for the VM. This will pick a fully patched image of this given Windows version."
}
},
"vmSize": {
"type": "string",
"defaultValue": "Standard_D2s_v5",
"metadata": {
"description": "Size of the virtual machine."
}
},
"location": {
"type": "string",
"defaultValue": "[resourceGroup().location]",
"metadata": {
"description": "Location for all resources."
}
},
"vmName": {
"type": "string",
"defaultValue": "simple-vm",
"metadata": {
"description": "Name of the virtual machine."
}
},
"securityType": {
"type": "string",
"metadata": {
"description": "Security Type of virtualmachine"
}
},
"secureBootEnabled": {
"type": "string",
"metadata": {
"description": "secureBootEnabled of the virtual machine"
}
},
"vTpmEnabled": {
"type": "string",
"metadata": {
"description": "vTpmEnabled of the virtual machine"
}
}
},
"variables": {
"storageAccountName": "[format('bootdiags{0}', uniqueString(resourceGroup().id))]",
"nicName": "myVMNic",
"addressPrefix": "10.0.0.0/16",
"subnetName": "Subnet",
"subnetPrefix": "10.0.0.0/24",
"virtualNetworkName": "MyVNET",
"networkSecurityGroupName": "default-NSG"
},
"resources": [
{
"type": "Microsoft.Storage/storageAccounts",
"apiVersion": "2021-04-01",
"name": "[variables('storageAccountName')]",
"location": "[parameters('location')]",
"sku": {
"name": "Standard_LRS"
},
"kind": "Storage"
},
{
"type": "Microsoft.Network/publicIPAddresses",
"apiVersion": "2021-02-01",
"name": "[parameters('publicIpName')]",
"location": "[parameters('location')]",
"sku": {
"name": "[parameters('publicIpSku')]"
},
"properties": {
"publicIPAllocationMethod": "[parameters('publicIPAllocationMethod')]",
"dnsSettings": {
"domainNameLabel": "[parameters('dnsLabelPrefix')]"
}
}
},
{
"type": "Microsoft.Network/networkSecurityGroups",
"apiVersion": "2021-02-01",
"name": "[variables('networkSecurityGroupName')]",
"location": "[parameters('location')]",
"properties": {
"securityRules": [
{
"name": "default-allow-3389",
"properties": {
"priority": 1000,
"access": "Allow",
"direction": "Inbound",
"destinationPortRange": "3389",
"protocol": "Tcp",
"sourcePortRange": "*",
"sourceAddressPrefix": "*",
"destinationAddressPrefix": "*"
}
}
]
}
},
{
"type": "Microsoft.Network/virtualNetworks",
"apiVersion": "2021-02-01",
"name": "[variables('virtualNetworkName')]",
"location": "[parameters('location')]",
"properties": {
"addressSpace": {
"addressPrefixes": [
"[variables('addressPrefix')]"
]
},
"subnets": [
{
"name": "[variables('subnetName')]",
"properties": {
"addressPrefix": "[variables('subnetPrefix')]",
"networkSecurityGroup": {
"id": "[resourceId('Microsoft.Network/networkSecurityGroups', variables('networkSecurityGroupName'))]"
}
}
}
]
},
"dependsOn": [
"[resourceId('Microsoft.Network/networkSecurityGroups', variables('networkSecurityGroupName'))]"
]
},
{
"type": "Microsoft.Network/networkInterfaces",
"apiVersion": "2021-02-01",
"name": "[variables('nicName')]",
"location": "[parameters('location')]",
"properties": {
"ipConfigurations": [
{
"name": "ipconfig1",
"properties": {
"privateIPAllocationMethod": "Dynamic",
"publicIPAddress": {
"id": "[resourceId('Microsoft.Network/publicIPAddresses', parameters('publicIpName'))]"
},
"subnet": {
"id": "[resourceId('Microsoft.Network/virtualNetworks/subnets', variables('virtualNetworkName'), variables('subnetName'))]"
}
}
}
]
},
"dependsOn": [
"[resourceId('Microsoft.Network/publicIPAddresses', parameters('publicIpName'))]",
"[resourceId('Microsoft.Network/virtualNetworks', variables('virtualNetworkName'))]"
]
},
{
"type": "Microsoft.Compute/virtualMachines",
"apiVersion": "2021-03-01",
"name": "[parameters('vmName')]",
"location": "[parameters('location')]",
"properties": {
"hardwareProfile": {
"vmSize": "[parameters('vmSize')]"
},
"osProfile": {
"computerName": "[parameters('vmName')]",
"adminUsername": "[parameters('adminUsername')]",
"adminPassword": "[parameters('adminPassword')]"
},
"storageProfile": {
"imageReference": {
"publisher": "MicrosoftWindowsServer",
"offer": "WindowsServer",
"sku": "[parameters('OSVersion')]",
"version": "latest"
},
"osDisk": {
"createOption": "FromImage",
"managedDisk": {
"storageAccountType": "StandardSSD_LRS"
}
},
"dataDisks": [
{
"diskSizeGB": 1023,
"lun": 0,
"createOption": "Empty"
}
]
},
"networkProfile": {
"networkInterfaces": [
{
"id": "[resourceId('Microsoft.Network/networkInterfaces', variables('nicName'))]"
}
]
},
"diagnosticsProfile": {
"bootDiagnostics": {
"enabled": true,
"storageUri": "[reference(resourceId('Microsoft.Storage/storageAccounts', variables('storageAccountName'))).primaryEndpoints.blob]"
}
},
"securityProfile":{
"securityType": "[parameters('securityType')]",
"uefiSettings": {
"secureBootEnabled": "[parameters('secureBootEnabled')]",
"vTpmEnabled": "[parameters('vTpmEnabled')]"
}
}
},
"dependsOn": [
"[resourceId('Microsoft.Network/networkInterfaces', variables('nicName'))]",
"[resourceId('Microsoft.Storage/storageAccounts', variables('storageAccountName'))]"
]
}
],
"outputs": {
"hostname": {
"type": "string",
"value": "[reference(resourceId('Microsoft.Network/publicIPAddresses', parameters('publicIpName'))).dnsSettings.fqdn]"
}
}
}
azure-deploy.parameters.json
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"adminUsername": {
"value": ""
},
"adminPassword": {
"value": ""
},
"dnsLabelPrefix": {
"value": ""
},
"publicIpName": {
"value": ""
},
"publicIPAllocationMethod": {
"value": ""
},
"publicIpSku": {
"value": ""
},
"OSVersion": {
"value": "2022-datacenter-azure-edition-core"
},
"vmSize": {
"value": "Standard_D2s_v5"
},
"location": {
"value": "eastus"
},
"vmName": {
"value": ""
},
"securityType": {
"value": "TrustedLaunch"
},
"secureBootEnabled": {
"value": "true"
},
"vTpmEnabled": {
"value": "true"
}
}
}

Only one SFTP Server for one Azure Resource group possible?

Is it only possible to create one on-demand SFPT Server with one Resource group in Azure?
This is a link regards to SFPT on Azure. https://learn.microsoft.com/en-us/samples/azure-samples/sftp-creation-template/sftp-on-azure/
I tried to create a second SFPT in the same Resource group, but previous SFPT got replaced with the new one.
I tried Goolging on this one, but I was not able to find the answer, so I am posting this question here.
Yes we can deploy multiple SFTP server to our Azure resource group.
But the template you are using already they have declare default variables ,Instead of that we need to declare parameters as shown in below template, So that you can use the same template multiple times.
TEMPLATE:-
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"metadata": {
"_generator": {
"name": "bicep",
"version": "0.4.63.48766",
"templateHash": "17013458610905703770"
}
},
"parameters": {
"storageAccountType": {
"type": "string",
"defaultValue": "Standard_LRS",
"metadata": {
"description": "Storage account type"
},
"allowedValues": [
"Standard_LRS",
"Standard_ZRS",
"Standard_GRS"
]
},
"storageAccountPrefix": {
"type": "string",
"defaultValue": "sftpstg",
"metadata": {
"description": "Prefix for new storage account"
}
},
"fileShareName": {
"type": "string",
"defaultValue": "sftpfileshare",
"metadata": {
"description": "Name of file share to be created"
}
},
"sftpUser": {
"type": "string",
"defaultValue": "sftp",
"metadata": {
"description": "Username to use for SFTP access"
}
},
"sftpPassword": {
"type": "securestring",
"metadata": {
"description": "Password to use for SFTP access"
}
},
"location": {
"type": "string",
"defaultValue": "[resourceGroup().location]",
"metadata": {
"description": "Primary location for resources"
}
},
"containerGroupDNSLabel": {
"type": "string",
"defaultValue": "[uniqueString(resourceGroup().id, deployment().name)]",
"metadata": {
"description": "DNS label for container group"
}
},
"sftpContainerGroupName": {
"type": "string",
"metadata": {
"description": "cngroup for container group"
}
},
"sftpContainerName": {
"type": "string",
"metadata": {
"description": "container name"
}
}
},
"functions": [],
"variables": {
"sftpContainerImage": "atmoz/sftp:debian",
"sftpEnvVariable": "[format('{0}:{1}:1001', parameters('sftpUser'), parameters('sftpPassword'))]",
"storageAccountName": "[take(toLower(format('{0}{1}', parameters('storageAccountPrefix'), uniqueString(resourceGroup().id))), 24)]"
},
"resources": [
{
"type": "Microsoft.Storage/storageAccounts",
"apiVersion": "2019-06-01",
"name": "[variables('storageAccountName')]",
"location": "[parameters('location')]",
"kind": "StorageV2",
"sku": {
"name": "[parameters('storageAccountType')]"
}
},
{
"type": "Microsoft.Storage/storageAccounts/fileServices/shares",
"apiVersion": "2019-06-01",
"name": "[toLower(format('{0}/default/{1}', variables('storageAccountName'), parameters('fileShareName')))]",
"dependsOn": [
"[resourceId('Microsoft.Storage/storageAccounts', variables('storageAccountName'))]"
]
},
{
"type": "Microsoft.ContainerInstance/containerGroups",
"apiVersion": "2019-12-01",
"name": "[parameters('sftpContainerGroupName')]",
"location": "[parameters('location')]",
"properties": {
"containers": [
{
"name": "[parameters('sftpContainerName')]",
"properties": {
"image": "[variables('sftpContainerImage')]",
"environmentVariables": [
{
"name": "SFTP_USERS",
"secureValue": "[variables('sftpEnvVariable')]"
}
],
"resources": {
"requests": {
"cpu": 1,
"memoryInGB": 1
}
},
"ports": [
{
"port": 22,
"protocol": "TCP"
}
],
"volumeMounts": [
{
"mountPath": "[format('/home/{0}/upload', parameters('sftpUser'))]",
"name": "sftpvolume",
"readOnly": false
}
]
}
}
],
"osType": "Linux",
"ipAddress": {
"type": "Public",
"ports": [
{
"port": 22,
"protocol": "TCP"
}
],
"dnsNameLabel": "[parameters('containerGroupDNSLabel')]"
},
"restartPolicy": "OnFailure",
"volumes": [
{
"name": "sftpvolume",
"azureFile": {
"readOnly": false,
"shareName": "[parameters('fileShareName')]",
"storageAccountName": "[variables('storageAccountName')]",
"storageAccountKey": "[listKeys(resourceId('Microsoft.Storage/storageAccounts', variables('storageAccountName')), '2019-06-01').keys[0].value]"
}
}
]
},
"dependsOn": [
"[resourceId('Microsoft.Storage/storageAccounts', variables('storageAccountName'))]"
]
}
],
"outputs": {
"containerDNSLabel": {
"type": "string",
"value": "[format('{0}.{1}.azurecontainer.io', reference(resourceId('Microsoft.ContainerInstance/containerGroups', parameters('sftpContainerGroupName'))).ipAddress.dnsNameLabel, reference(resourceId('Microsoft.ContainerInstance/containerGroups', parameters('sftpContainerGroupName')), '2019-12-01', 'full').location)]"
}
}
}
Deployment details:-

ARM Template for creating VM in azure using existing VHD Uri (osDiskVHDUri) & join to domain

Use-case description:
I've a use case wherein, we need to create a VM in azure using the existing VHD Uri available in storage account & the same ARM template should have the feasibility to join to domain. At the present currently tried working & executing the ARM template which has only flexibility of using the existing VHD Uri and creating a VM (this Uri will act as "OsDiskVhdUri") & another template has only the ability to create new VM and join to domain these are working on standalone basis.
Key highlighters:-
Need a template which has both "OsDiskVhdUri" & domain join parameters.
Template reference should be "OsDiskVhdUri", because when i tried integrating both templates & troubleshooting - Image reference related errors are there on while deployment.
The very important point, was - the ARM template while blueprint assignment asks for OsDiskVhdUri parameter and although I give the Uri for creating the VM, with the below template, it doesn't seems to take that Uri" instead it creates a NEW VM every time and attaches to domain.
Deployment method is blueprint in Azure.
Error:-
type 'Template' failed to deploy due to the following error: Template deployment failed with error [ { "message": "Could not find member 'osDiskVhdUri' on object of type 'ImageReference'. Path 'properties.storageProfile.imageReference.osDiskVhdUri', line 1, position 237." }
Exhausted all methods finding still deeper dive into it & any guidance on this will be highly appreciated!!
Code for reference:
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"existingVNETName": {
"type": "string",
"metadata": {
"description": "Existing VNET that contains the domain controller"
}
},
"osDiskVhdUri": {
"type": "string",
"metadata": {
"description": "Uri of the existing VHD in ARM standard or premium storage"
}
},
"osType": {
"type": "string",
"defaultValue": "2019-Datacenter",
"allowedValues": [
"2019-Datacenter"
],
"metadata": {
"description": "The Windows version for the VMs. Allowed values: 2008-R2-SP1, 2012-Datacenter, 2012-R2-Datacenter."
}
},
"existingSubnetName": {
"type": "string",
"metadata": {
"description": "Existing subnet that contains the domain controller"
}
},
"vmname": {
"type": "string",
"metadata": {
"description": "Unique public DNS prefix for the deployment. The fqdn will look something like '<dnsname>.westus.cloudapp.azure.com'. Up to 62 chars, digits or dashes, lowercase, should start with a letter: must conform to '^[a-z][a-z0-9-]{1,61}[a-z0-9]$'."
}
},
"vmSize": {
"type": "string",
"defaultValue": "Standard_D2_v2",
"metadata": {
"description": "The size of the virtual machines"
}
},
"domainToJoin": {
"type": "string",
"metadata": {
"description": "The FQDN of the AD domain"
}
},
"domainUsername": {
"type": "string",
"metadata": {
"description": "Username of the account on the domain"
}
},
"domainPassword": {
"type": "string",
"metadata": {
"description": "Password of the account on the domain"
}
},
"ouPath": {
"type": "string",
"defaultValue": "",
"metadata": {
"description": "Specifies an organizational unit (OU) for the domain account. Enter the full distinguished name of the OU in quotation marks. Example: \"OU=testOU; DC=domain; DC=Domain; DC=com\""
}
},
"domainJoinOptions": {
"type": "int",
"defaultValue": 3,
"metadata": {
"description": "Set of bit flags that define the join options. Default value of 3 is a combination of NETSETUP_JOIN_DOMAIN (0x00000001) & NETSETUP_ACCT_CREATE (0x00000002) i.e. will join the domain and create the account on the domain. For more information see https://msdn.microsoft.com/en-us/library/aa392154(v=vs.85).aspx"
}
},
"vmAdminUsername": {
"type": "string",
"metadata": {
"description": "The name of the administrator of the new VM and the domain. Exclusion list: 'admin','administrator"
}
},
"vmAdminPassword": {
"type": "string",
"metadata": {
"description": "The password for the administrator account of the new VM and the domain"
}
},
"location": {
"type": "string",
"defaultValue": "East US",
"metadata": {
"description": "Location for all resources."
}
}
},
"variables": {
"storageAccountName": "[concat('diags', uniquestring(resourceGroup().id))]",
"diskName": "[concat('diags', uniquestring(resourceGroup().id))]",
"osDiskVhdUri": "[concat(parameters('osDiskVhdUri'), '-image')]",
"nicName": "[concat(parameters('vmname'),'Nic')]",
"publicIPName": "[concat(parameters('vmname'),'Pip')]",
"subnetId": "[resourceId(resourceGroup().name, 'Microsoft.Network/virtualNetworks/subnets', parameters('existingVNETName'), parameters('existingSubnetName'))]"
},
"resources": [
{
"apiVersion": "2015-06-15",
"type": "Microsoft.Network/publicIPAddresses",
"name": "[variables('publicIPName')]",
"location": "[parameters('location')]",
"properties": {
"publicIPAllocationMethod": "Dynamic",
"dnsSettings": {
"domainNameLabel": "[parameters('vmname')]"
}
}
},
{
"type": "Microsoft.Compute/disks",
"apiVersion": "2018-09-30",
"name": "[variables('diskName')]",
"location": "[parameters('location')]",
"properties": {
"creationData": {
"createOption": "Import",
"sourceUri": "[parameters('osDiskVhdUri')]"
}
}
},
{
"apiVersion": "2015-06-15",
"type": "Microsoft.Storage/storageAccounts",
"name": "[variables('storageAccountName')]",
"location": "[parameters('location')]",
"properties": {
"accountType": "Standard_LRS"
}
},
{
"apiVersion": "2015-06-15",
"type": "Microsoft.Network/networkInterfaces",
"name": "[variables('nicName')]",
"location": "[parameters('location')]",
"dependsOn": [
"[concat('Microsoft.Network/publicIPAddresses/', variables('publicIPName'))]"
],
"properties": {
"ipConfigurations": [
{
"name": "ipconfig",
"properties": {
"privateIPAllocationMethod": "Dynamic",
"publicIPAddress": {
"id": "[resourceId('Microsoft.Network/publicIPAddresses', variables('publicIPName'))]"
},
"subnet": {
"id": "[variables('subnetId')]"
}
}
}
]
}
},
{
"type": "Microsoft.Compute/images",
"apiVersion": "2020-06-01",
"name": "[variables('imageName')]",
"location": "[parameters('location')]",
"properties": {
"hyperVGeneration": "V2",
"storageProfile": {
"osDisk": {
"osType": "[parameters('osType')]",
"osState": "Generalized",
"blobUri": "[parameters('osDiskVhdUri')]",
"caching": "ReadWrite",
"storageAccountType": "Standard_LRS"
}
}
}
},
{
"apiVersion": "2020-06-01",
"type": "Microsoft.Compute/virtualMachines",
"name": "[parameters('vmName')]",
"location": "[parameters('location')]",
"tags": {
"displayName": "VirtualMachine"
},
"dependsOn": [
"[variables('nicName')]",
"[variables('imageName')]"
],
"properties": {
"hardwareProfile": {
"vmSize": "[parameters('vmSize')]"
},
"osProfile": {
"computerName": "[parameters('vmName')]",
"adminUsername": "[parameters('adminUsername')]",
"adminPassword": "[parameters('adminPasswordOrKey')]",
"linuxConfiguration": "[if(equals(parameters('authenticationType'), 'password'), json('null'), variables('linuxConfiguration'))]"
},
"storageProfile": {
"imageReference": {
"id": "[resourceId('Microsoft.Compute/images', variables('imageName'))]"
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "[resourceId('Microsoft.Network/networkInterfaces', variables('nicName'))]"
}
]
},
"diagnosticsProfile": {
"bootDiagnostics": {
"enabled": true,
"storageUri": "[reference(variables('diagStorageAccountName')).primaryEndpoints.blob]"
}
}
}
},
{
"apiVersion": "2015-06-15",
"type": "Microsoft.Compute/virtualMachines/extensions",
"name": "[concat(parameters('vmname'),'/joindomain')]",
"location": "[parameters('location')]",
"dependsOn": [
"[concat('Microsoft.Compute/virtualMachines/', parameters('vmname'))]"
],
"properties": {
"publisher": "Microsoft.Compute",
"type": "JsonADDomainExtension",
"typeHandlerVersion": "1.3",
"autoUpgradeMinorVersion": true,
"settings": {
"Name": "[parameters('domainToJoin')]",
"OUPath": "[parameters('ouPath')]",
"User": "[concat(parameters('domainToJoin'), '\\', parameters('domainUsername'))]",
"Restart": "true",
"Options": "[parameters('domainJoinOptions')]"
},
"protectedSettings": {
"Password": "[parameters('domainPassword')]"
}
}
}
]
}
If you want to create Azure VM with vhd file, please update your template as below
{
"type": "Microsoft.Compute/images",
"apiVersion": "2020-06-01",
"name": "[variables('imageName')]",
"location": "[parameters('location')]",
"properties": {
"hyperVGeneration": "V2",
"storageProfile": {
"osDisk": {
"osType": "[parameters('osType')]",
"osState": "Generalized",
"blobUri": "[parameters('osDiskVhdUri')]",
"caching": "ReadWrite",
"storageAccountType": "Standard_LRS"
}
}
}
},
{
"apiVersion": "2020-06-01",
"type": "Microsoft.Compute/virtualMachines",
"name": "[parameters('vmName')]",
"location": "[parameters('location')]",
"tags": {
"displayName": "VirtualMachine"
},
"dependsOn": [
"[variables('nicName')]",
"[variables('imageName')]"
],
"properties": {
"hardwareProfile": {
"vmSize": "[parameters('vmSize')]"
},
"osProfile": {
"computerName": "[parameters('vmName')]",
"adminUsername": "[parameters('adminUsername')]",
"adminPassword": "[parameters('adminPasswordOrKey')]",
"linuxConfiguration": "[if(equals(parameters('authenticationType'), 'password'), json('null'), variables('linuxConfiguration'))]"
},
"storageProfile": {
"imageReference": {
"id": "[resourceId('Microsoft.Compute/images', variables('imageName'))]"
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "[resourceId('Microsoft.Network/networkInterfaces', variables('nicName'))]"
}
]
},
"diagnosticsProfile": {
"bootDiagnostics": {
"enabled": true,
"storageUri": "[reference(variables('diagStorageAccountName')).primaryEndpoints.blob]"
}
}
}
}

Need 5vm with 5 vsts agent installed from arm template

{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"vmAdminUsername": {
"type": "String",
"metadata": {
"description": "User name for the Virtual Machine."
}
},
"vmAdminPassword": {
"type": "SecureString",
"metadata": {
"description": "Password for the Virtual Machine."
}
},
"vmName": {
"type": "String",
"metadata": {
"description": "Unique hostname for the Virtual Machine."
}
},
"OSVersion": {
"defaultValue": "2019-Datacenter",
"type": "String",
"metadata": {
"description": "2019-Datacenter"
}
},
"existingVirtualNetworkResourceGroupName": {
"type": "String",
"metadata": {
"description": "VSTS deployment group name."
}
},
"existingSubnetName": {
"type": "String",
"metadata": {
"description": "Name of the existing subnet in the existing VNET you want to use"
}
},
"existingVirtualNetworkName": {
"type": "String",
"metadata": {
"description": "Name of the existing VNET"
}
},
"vmSize": {
"defaultValue": "Standard_D2_v3",
"type": "String",
"metadata": {
"description": "Desired Size of the VM. Any valid option accepted but if you choose premium storage type you must choose a DS class VM size."
}
},
"numberOfVms": {
"defaultValue": "1",
"type": "Int",
"metadata": {
"description": "Give the total number of vm to be deployed."
}
},
"VSTSAccount": {
"type": "String",
"metadata": {
"description": "Specify the name of the VSTSAccount Name"
}
},
"AgentName": {
"type": "String",
"metadata": {
"description": "Specify the name of the Agent"
}
},
"AgentPool": {
"type": "String",
"metadata": {
"description": "Specify the name of the AgentPool which is present"
}
},
"AgentNo": {
"type": "Int",
"metadata": {
"description": "Specify suffix number for Agent name "
}
},
"PATToken": {
"type": "String",
"metadata": {
"description": "Specify the PATToken of organisation or project"
}
},
"resourceTag": {
"type": "Object",
"metadata": {
"description": "Tag of AKS resource."
}
}
},
"variables": {
"imagePublisher": "MicrosoftWindowsServer",
"imageOffer": "WindowsServer",
"copy": [
{
"name": "Agent",
"count": "[parameters('numberOfVms')]",
"input": "[concat(parameters('AgentName'), copyIndex('Agent', 1))]"
}
],
"vnetID": "[resourceId('Microsoft.Network/virtualNetworks',parameters('existingVirtualNetworkName'))]",
"subnetRef": "[resourceID(parameters('existingVirtualNetworkResourceGroupName'), 'Microsoft.Network/virtualNetWorks/subnets', parameters('existingVirtualNetworkName'), parameters('existingSubnetName'))]"
},
"resources": [
{
"type": "Microsoft.Network/networkInterfaces",
"apiVersion": "2020-06-01",
"name": "[concat(parameters('vmName'),'-nic', copyindex(1))]",
"location": "[resourceGroup().location]",
"dependsOn": [],
"tags": "[parameters('resourceTag')]",
"properties": {
"ipConfigurations": [
{
"name": "ipconfig1",
"properties": {
"privateIPAllocationMethod": "Dynamic",
"subnet": {
"id": "[variables('subnetRef')]"
}
}
}
]
},
"copy": {
"name": "nicLoop",
"count": "[parameters('numberOfVms')]"
}
},
{
"type": "Microsoft.Compute/virtualMachines",
"apiVersion": "2017-03-30",
"name": "[concat(parameters('vmName'),'-vm', copyindex(1))]",
"location": "[resourceGroup().location]",
"dependsOn": [
"[resourceId('Microsoft.Network/networkInterfaces/', concat(parameters('vmName'),'-nic', copyindex(1)))]"
],
"properties": {
"hardwareProfile": {
"vmSize": "[parameters('vmSize')]"
},
"osProfile": {
"computerName": "[concat(parameters('vmName'),'-vm', copyindex(1))]",
"adminUsername": "[parameters('vmAdminUsername')]",
"adminPassword": "[parameters('vmAdminPassword')]"
},
"storageProfile": {
"imageReference": {
"publisher": "[variables('imagePublisher')]",
"offer": "[variables('imageOffer')]",
"sku": "[parameters('OSVersion')]",
"version": "latest"
},
"osDisk": {
"createOption": "FromImage"
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "[resourceId('Microsoft.Network/networkInterfaces',concat(parameters('vmName'),'-nic', copyindex(1)))]"
}
]
}
},
"copy": {
"name": "vmLoop",
"count": "[parameters('numberOfVms')]",
"mode": "serial"
}
},
{
"type": "Microsoft.Compute/virtualMachines/extensions",
"apiVersion": "2018-06-01",
"name": "[concat('virtualMachineName/agt',copyindex(1))]",
"location": "[ResourceGroup().location]",
"dependsOn": [
"[concat(parameters('vmName'),'-vm', copyindex(1))]"
],
"tags": "[parameters('resourceTag')]",
"properties": {
"publisher": "Microsoft.Compute",
"type": "CustomScriptExtension",
"autoUpgradeMinorVersion": true,
"typeHandlerVersion": "1.10",
"settings": {
"fileUris": [
"https://ehpiacarmstorage.blob.core.windows.net/armagentscripts/winserviceagt.ps1"
]
},
"protectedSettings": {
"commandToExecute": "[concat('powershell.exe -ExecutionPolicy Unrestricted -Command .\\winserviceagt.ps1 -vstsAccount ', parameters('VSTSAccount'), ' -PAT ', parameters('PATToken'), ' -vstsAgent ', variables('Agent'), ' -AgentNo ', parameters('AgentNo'), ' -vmAdminPassword ''', parameters('vmAdminPassword'), ''' -vmAdminUserName ', parameters('vmAdminUsername'), ' -vstsPoolName ', parameters('AgentPool'))]"
}
},
"copy": {
"name": "agtLoop",
"count": "[parameters('numberOfVms')]"
}
}
],
"outputs": {}
}
Error Message
At least one resource deployment operation failed. Please list
deployment operations for details. Please see
https://aka.ms/DeployOperations for usage details.", "details": [
{
"code": "InvalidTemplate",
"message": "Unable to process template language expressions for resource
'/subscriptions/----------/resourceGroups/mygroup/providers/Microsoft.Compute/virtualMachines/virtualMachineName/extensions/agt2'
at line '232' and column '9'. 'The provided parameters for language
function 'concat' are invalid. Either all or none of the parameters
must be an array. Please see
https://aka.ms/arm-template-expressions/#concat for usage details.
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"vmAdminUsername": {
"type": "String",
"metadata": {
"description": "User name for the Virtual Machine."
}
},
"vmAdminPassword": {
"type": "SecureString",
"metadata": {
"description": "Password for the Virtual Machine."
}
},
"vmName": {
"type": "String",
"metadata": {
"description": "Unique hostname for the Virtual Machine."
}
},
"OSVersion": {
"defaultValue": "2019-Datacenter",
"type": "String",
"metadata": {
"description": "2019-Datacenter"
}
},
"indexValue": {
"defaultValue": "1",
"type": "Int",
"metadata": {
"description": "Give the starting deploy vm number for index start."
}
},
"existingVirtualNetworkResourceGroupName": {
"type": "String",
"metadata": {
"description": "VSTS deployment group name."
}
},
"existingSubnetName": {
"type": "String",
"metadata": {
"description": "Name of the existing subnet in the existing VNET you want to use"
}
},
"existingVirtualNetworkName": {
"type": "String",
"metadata": {
"description": "Name of the existing VNET"
}
},
"vmSize": {
"defaultValue": "Standard_D2_v3",
"type": "String",
"metadata": {
"description": "Desired Size of the VM. Any valid option accepted but if you choose premium storage type you must choose a DS class VM size."
}
},
"numberOfVms": {
"defaultValue": "1",
"type": "Int",
"metadata": {
"description": "Give the total number of vm to be deployed."
}
},
"VSTSAccount": {
"type": "String",
"metadata": {
"description": "Specify the name of the VSTSAccount Name"
}
},
"AgentName": {
"type": "String",
"metadata": {
"description": "Specify the name of the Agent"
}
},
"AgentPool": {
"type": "String",
"metadata": {
"description": "Specify the name of the AgentPool which is present"
}
},
"AgentNo": {
"type": "Int",
"metadata": {
"description": "Specify suffix number for Agent name "
}
},
"PATToken": {
"type": "String",
"metadata": {
"description": "Specify the PATToken of organisation or project"
}
},
"resourceTag": {
"type": "Object",
"metadata": {
"description": "Tag of AKS resource."
}
}
},
"variables": {
"imagePublisher": "MicrosoftWindowsServer",
"imageOffer": "WindowsServer",
"vnetID": "[resourceId('Microsoft.Network/virtualNetworks',parameters('existingVirtualNetworkName'))]",
"subnetRef": "[resourceID(parameters('existingVirtualNetworkResourceGroupName'), 'Microsoft.Network/virtualNetWorks/subnets', parameters('existingVirtualNetworkName'), parameters('existingSubnetName'))]"
},
"resources": [
{
"type": "Microsoft.Network/networkInterfaces",
"apiVersion": "2020-06-01",
"name": "[concat(parameters('vmName'),'-nic', copyindex(parameters('indexValue')))]",
"location": "[resourceGroup().location]",
"dependsOn": [],
"tags": "[parameters('resourceTag')]",
"properties": {
"ipConfigurations": [
{
"name": "ipconfig1",
"properties": {
"privateIPAllocationMethod": "Dynamic",
"subnet": {
"id": "[variables('subnetRef')]"
}
}
}
]
},
"copy": {
"name": "nicLoop",
"count": "[parameters('numberOfVms')]"
}
},
{
"type": "Microsoft.Compute/virtualMachines",
"apiVersion": "2017-03-30",
"name": "[concat(parameters('vmName'),'-vm', copyindex(parameters('indexValue')))]",
"location": "[resourceGroup().location]",
"tags": "[parameters('resourceTag')]",
"dependsOn": [
"[resourceId('Microsoft.Network/networkInterfaces/', concat(parameters('vmName'),'-nic', copyindex(parameters('indexValue'))))]"
],
"properties": {
"hardwareProfile": {
"vmSize": "[parameters('vmSize')]"
},
"osProfile": {
"computerName": "[concat(parameters('vmName'),'-vm', copyindex(parameters('indexValue')))]",
"adminUsername": "[parameters('vmAdminUsername')]",
"adminPassword": "[parameters('vmAdminPassword')]"
},
"storageProfile": {
"imageReference": {
"publisher": "[variables('imagePublisher')]",
"offer": "[variables('imageOffer')]",
"sku": "[parameters('OSVersion')]",
"version": "latest"
},
"osDisk": {
"createOption": "FromImage"
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "[resourceId('Microsoft.Network/networkInterfaces',concat(parameters('vmName'),'-nic', copyindex(parameters('indexValue'))))]"
}
]
}
},
"copy": {
"name": "vmLoop",
"count": "[parameters('numberOfVms')]"
}
},
{
"type": "Microsoft.Compute/virtualMachines/extensions",
"apiVersion": "2018-06-01",
"name": "[concat(parameters('vmName'),'-vm', copyindex(parameters('indexValue')),'/agt')]",
"location": "[ResourceGroup().location]",
"dependsOn": [
"[concat(parameters('vmName'),'-vm', copyindex(parameters('indexValue')))]"
],
"tags": "[parameters('resourceTag')]",
"properties": {
"publisher": "Microsoft.Compute",
"type": "CustomScriptExtension",
"autoUpgradeMinorVersion": true,
"typeHandlerVersion": "1.10",
"settings": {
"fileUris": [
"https://ehpiacarmstorage.blob.core.windows.net/armagentscripts/winserviceagt.ps1"
]
},
"protectedSettings": {
"commandToExecute": "[concat('powershell.exe -ExecutionPolicy Unrestricted -Command .\\winserviceagt.ps1 -vstsAccount ', parameters('VSTSAccount'), ' -PAT ', parameters('PATToken'), ' -vstsAgent ', parameters('AgentName'), ' -AgentNo ', parameters('AgentNo'), ' -vmAdminPassword ''', parameters('vmAdminPassword'), ''' -vmAdminUserName ', parameters('vmAdminUsername'), ' -vstsPoolName ', parameters('AgentPool'))]"
}
},
"copy": {
"name": "agtLoop",
"count": "[parameters('numberOfVms')]"
}
}
],
"outputs": {}
}

Microsoft.Compute/virtualMachines/extensions' has incorrect segment lengths

I'm unable to deploy this NESTED template because of an Custom Script Extension (CompDesc) that I've added to it. I am prompted with the following error when trying to deploy:
Error: Code=InvalidTemplate; Message=Deployment template validation failed: 'The template resource 'CompDesc' for type 'Microsoft.Compute/virtualMachines/extensions' at line '207' and column '6' 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.'.
As you can see it already has a DSC extension which I have tested and deployed perfectly fine, but I also need to add this CSE for a small .ps1 script.
I have checked out:
Azure website resource template error
and Set ARM Template Web appSetting
I have tried:
changing the name to 1 word
changing the type to 1 word
changing the name to [concat(parameters('vmName'),'/extension')]
changing the type to Microsoft.Compute/virtualMachines/extensions
nested the resource inside the VM resource, and then changed the name and type to one of the varieties I've tried
removed the CSE from the VM resource and placed it on its own (as it is now shown), and then changed the name and type to one of the varieties I've tried
I know it has something to do with the naming convention, but I'm unsure on how to fix it. Bear in mind, that this is a nested template. From what I read and understand from the error, nested templates must have identical segments as its resource name, which I've tried.
Please, any ideas?
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"adminPassword": {
"type": "securestring",
"metadata": {
"description": "Password for the Virtual Machine."
}
},
"adminUsername": {
"type": "string",
"minLength": 1,
"metadata": {
"description": "Username for the Virtual Machine."
}
},
"computerDescription": {
"type": "string",
"metadata": {
"description": "The description name of the VM."
}
},
"nicName": {
"type": "string",
"metadata": {
"description": "The name of the VM nic"
}
},
"nodeConfigurationName": {
"type": "string",
"metadata": {
"description": "The name of the node configuration, on the Azure Automation DSC pull server, that this node will be configured as"
}
},
"projectTag": {
"type": "string",
"metadata": {
"description": "name of the Project"
}
},
"registrationKey": {
"type": "securestring",
"metadata": {
"description": "Registration key to use to onboard to the Azure Automation DSC pull/reporting server"
}
},
"registrationUrl": {
"type": "string",
"metadata": {
"description": "The URL to register against the DSC automation server"
}
},
"sasToken": {
"type": "securestring",
"metadata": {
"description": "Generated SAS token to be used."
}
},
"virtualNetworkName": {
"type": "string",
"metadata": {
"description": "name of the vNet"
}
},
"vmName": {
"type": "string",
"defaultValue": "myVM",
"metadata": {
"description": "The name of the VM resource"
}
},
"windowsOSVersion": {
"type": "string",
"metadata": {
"description": "The Windows version for the VM. This will pick a fully patched image of this given Windows version. Allowed values: 2008-R2-SP1, 2012-Datacenter, 2012-R2-Datacenter."
}
}
},
"variables": {
// Configuration for the VM
"imagePublisher": "MicrosoftWindowsServer",
"imageOffer": "WindowsServer",
"vmSize": "Standard_A2",
"vhdStorageAccountName": "[concat('vhdstorage', uniqueString(resourceGroup().id))]",
"vhdStorageContainerName": "vhds",
"vhdStorageType": "Standard_LRS",
// Configuration for network
"publicIPAddressName": "myPublicIP",
"publicIPAddressType": "Dynamic",
"subnetRef": "[concat(variables('vnetId'), '/subnets/', variables('subnetName'))]",
"subnetName": "default",
"vnetId": "[resourceId(resourceGroup().name, 'Microsoft.Network/virtualNetworks', parameters('virtualNetworkName'))]",
// Configuration of the DSC
"allowModuleOverwrite": false,
"actionAfterReboot": "ContinueConfiguration",
"configurationFunction": "UpdateLCMforAAPull.ps1\\ConfigureLCMforAAPull",
"configurationMode": "ApplyAndAutoCorrect",
"configurationModeFrequencyMins": 15,
"modulesUrl": "[concat('REDACTED', parameters('sasToken'))]",
"refreshFrequencyMins": 30,
"rebootNodeIfNeeded": true,
"timestamp": "MM/dd/yyyy H:mm:ss tt"
},
"resources": [
{
"type": "Microsoft.Storage/storageAccounts",
"name": "[variables('vhdStorageAccountName')]",
"apiVersion": "2016-01-01",
"location": "[resourceGroup().location]",
"tags": {
"displayName": "StorageAccount"
},
"sku": {
"name": "[variables('vhdStorageType')]"
},
"kind": "Storage"
},
{
"apiVersion": "2016-03-30",
"type": "Microsoft.Network/publicIPAddresses",
"name": "[variables('publicIPAddressName')]",
"location": "[resourceGroup().location]",
"tags": {
"displayName": "PublicIPAddress"
},
"properties": {
"publicIPAllocationMethod": "[variables('publicIPAddressType')]"
}
},
{
"apiVersion": "2016-03-30",
"type": "Microsoft.Network/networkInterfaces",
"name": "[parameters('nicName')]",
"location": "[resourceGroup().location]",
"properties": {
"ipConfigurations": [
{
"name": "ipconfig",
"properties": {
"privateIPAllocationMethod": "Dynamic",
"subnet": {
"id": "[variables('subnetRef')]"
}
}
}
]
}
},
{
"apiVersion": "2017-03-30",
"type": "Microsoft.Compute/virtualMachines",
"name": "[parameters('vmName')]",
"location": "[resourceGroup().location]",
"tags": {
"displayName": "[concat(parameters('vmName'), parameters('projectTag'))]"
},
"dependsOn": [
"[resourceId('Microsoft.Storage/storageAccounts/', variables('vhdStorageAccountName'))]",
"[resourceId('Microsoft.Network/networkInterfaces/', parameters('nicName'))]"
],
"properties": {
"hardwareProfile": {
"vmSize": "[variables('vmSize')]"
},
"osProfile": {
"computerName": "[parameters('vmName')]",
"adminUsername": "[parameters('adminUsername')]",
"adminPassword": "[parameters('adminPassword')]"
},
"storageProfile": {
"imageReference": {
"publisher": "[variables('imagePublisher')]",
"offer": "[variables('imageOffer')]",
"sku": "[parameters('windowsOSVersion')]",
"version": "latest"
},
"osDisk": {
"createOption": "FromImage"
},
"dataDisks": [
{
"diskSizeGB": 1023,
"lun": 0,
"createOption": "Empty"
}
]
},
"networkProfile": {
"networkInterfaces": [
{
"id": "[resourceId('Microsoft.Network/networkInterfaces', parameters('nicName'))]"
}
]
},
"diagnosticsProfile": {
"bootDiagnostics": {
"enabled": true,
"storageUri": "[reference(resourceId('Microsoft.Storage/storageAccounts', variables('vhdStorageAccountName')), '2016-01-01').primaryEndpoints.blob]"
}
}
}
},
{
"name": "CompDesc",
"type": "extensions",
"location": "[resourceGroup().location]",
"apiVersion": "2016-03-30",
"dependsOn": [
"[resourceId('Microsoft.Compute/virtualMachines', parameters('vmName'))]"
],
"tags": {
"displayName": "CompDesc"
},
"properties": {
"publisher": "Microsoft.Compute",
"type": "CustomScriptExtension",
"typeHandlerVersion": "1.4",
"autoUpgradeMinorVersion": true,
"settings": {
"fileUris": [
"[concat('REDACTED', parameters('sasToken'))]"
],
"commandToExecute": "[concat('powershell -ExecutionPolicy Unrestricted -File compdesc.ps1', ' ', '\"', parameters('computerDescription'), '\"')]"
}
}
},
{
"type": "Microsoft.Compute/virtualMachines/extensions",
"name": "[concat(parameters('vmName'),'/Microsoft.Powershell.DSC')]",
"apiVersion": "2015-06-15",
"location": "[resourceGroup().location]",
"dependsOn": [
"[resourceId('Microsoft.Compute/virtualMachines', parameters('vmName'))]"
],
"properties": {
"publisher": "Microsoft.Powershell",
"type": "DSC",
"typeHandlerVersion": "2.19",
"autoUpgradeMinorVersion": true,
"protectedSettings": {
"Items": {
"registrationKeyPrivate": "[parameters('registrationKey')]"
}
},
"settings": {
"ModulesUrl": "[variables('modulesUrl')]",
"SasToken": "",
"ConfigurationFunction": "[variables('configurationFunction')]",
"Properties": [
{
"Name": "RegistrationKey",
"Value": {
"UserName": "PLACEHOLDER_DONOTUSE",
"Password": "PrivateSettingsRef:registrationKeyPrivate"
},
"TypeName": "System.Management.Automation.PSCredential"
},
{
"Name": "RegistrationUrl",
"Value": "[parameters('registrationUrl')]",
"TypeName": "System.String"
},
{
"Name": "NodeConfigurationName",
"Value": "[parameters('nodeConfigurationName')]",
"TypeName": "System.String"
},
{
"Name": "ConfigurationMode",
"Value": "[variables('configurationMode')]",
"TypeName": "System.String"
},
{
"Name": "ConfigurationModeFrequencyMins",
"Value": "[variables('configurationModeFrequencyMins')]",
"TypeName": "System.Int32"
},
{
"Name": "RefreshFrequencyMins",
"Value": "[variables('refreshFrequencyMins')]",
"TypeName": "System.Int32"
},
{
"Name": "RebootNodeIfNeeded",
"Value": "[variables('rebootNodeIfNeeded')]",
"TypeName": "System.Boolean"
},
{
"Name": "ActionAfterReboot",
"Value": "[variables('actionAfterReboot')]",
"TypeName": "System.String"
},
{
"Name": "AllowModuleOverwrite",
"Value": "[variables('allowModuleOverwrite')]",
"TypeName": "System.Boolean"
},
{
"Name": "Timestamp",
"Value": "[variables('timestamp')]",
"TypeName": "System.String"
}
]
}
}
}
]
}
My god, an oversight by myself. I forgot to re-upload the nested template to blob storage once I made my changes. So dumb.
Anyway, for those that want to know;
https://github.com/blumu/azure-content/blob/master/articles/resource-manager-common-deployment-errors.md

Resources