Only one SFTP Server for one Azure Resource group possible? - azure

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:-

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

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

Subnet DemoSubnet is in use and cannot be updated

I have created a DemoSubnet and an ElasticIP, then I am trying to deploy a ARM template which has a Virtual machine which is trying to attach with that existing elastic IP. The template works fine initially, and after some time its failing due to below error
"At least one resource deployment operation failed. Please list
deployment operations for details"
Here is the detailed error message from the arm template deployment:
Details=[{"code":"BadRequest","message":"{\r\n \"error\": {\r\n
\"code\": \"InUseSubnetCannotBeUpdated\",\r\n \"message\": \"Subnet
DemoSubnet is in use and cannot be updated.\",\r\n \"details\":
[]\r\n }\r\n}"}]
ARM Temaplate
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"addressPrefixes": {
"defaultValue": [
"10.0.0.0/16"
],
"type": "Array",
"metadata": {
"description": "Address prefix of the virtual network"
}
},
"location": {
"defaultValue": "[resourceGroup().location]",
"type": "String",
"metadata": {
"description": "Location for all resources."
}
},
"publicIpNewOrExisting": {
"defaultValue": "existing",
"type": "String",
"metadata": {
"description": "Determines whether or not a new public ip should be provisioned."
}
},
"publicIpResourceGroupName": {
"defaultValue": "[resourceGroup().name]",
"type": "String",
"metadata": {
"description": "Name of the resource group for the public ip address"
}
},
"storageAccountResourceGroupName": {
"defaultValue": "[resourceGroup().name]",
"type": "String",
"metadata": {
"description": "Name of the resource group for the existing storage account"
}
},
"storageNewOrExisting": {
"defaultValue": "existing",
"type": "String",
"metadata": {
"description": "Determines whether or not a new storage account should be provisioned."
}
},
"subnetPrefix": {
"defaultValue": "10.0.0.0/24",
"type": "String",
"metadata": {
"description": "Subnet prefix of the virtual network"
}
},
"virtualNetworkNewOrExisting": {
"defaultValue": "existing",
"type": "String",
"metadata": {
"description": "Determines whether or not a new virtual network should be provisioned."
}
},
"virtualNetworkResourceGroupName": {
"defaultValue": "[resourceGroup().name]",
"type": "String",
"metadata": {
"description": "Name of the resource group for the existing virtual network"
}
}
},
"resources": [
{
"type": "Microsoft.Compute/virtualMachines",
"apiVersion": "2018-10-01",
"name": "SampleVM",
"location": "[parameters('location')]",
"dependsOn": [
"[resourceId(parameters('storageAccountResourceGroupName'),'Microsoft.Storage/storageAccounts/', 'SampleStorageAccnt')]",
"[resourceId('Microsoft.Network/networkInterfaces/', 'SampleNIF')]"
],
"properties": {
"diagnosticsProfile": {
"bootDiagnostics": {
"enabled": true,
"storageUri": "[reference(resourceId(parameters('storageAccountResourceGroupName'),'Microsoft.Storage/storageAccounts/', 'SampleStorageAccnt')).primaryEndpoints.blob]"
}
},
"hardwareProfile": {
"vmSize": "Standard_A2"
},
"networkProfile": {
"networkInterfaces": [
{
"id": "[resourceId('Microsoft.Network/networkInterfaces','SampleNIF')]"
}
]
},
"osProfile": {
"adminPassword": "rajnikaur#253",
"adminUsername": "adminuser",
"computerName": "SampleVM"
},
"storageProfile": {
"dataDisks": [
{
"createOption": "Empty",
"diskSizeGB": 1023,
"lun": 0
}
],
"imageReference": {
"offer": "WindowsServer",
"publisher": "MicrosoftWindowsServer",
"sku": "2016-Datacenter",
"version": "latest"
},
"osDisk": {
"createOption": "FromImage"
}
}
}
},
{
"type": "Microsoft.Storage/storageAccounts",
"apiVersion": "2019-04-01",
"name": "SampleStorageAccnt",
"location": "[parameters('location')]",
"kind": "Storage",
"condition": "[equals(parameters('storageNewOrExisting'), 'existing')]"
},
{
"type": "Microsoft.Network/networkInterfaces",
"apiVersion": "2019-09-01",
"name": "SampleNIF",
"location": "[parameters('location')]",
"dependsOn": [
"[resourceId(parameters('virtualNetworkResourceGroupName'),'Microsoft.Network/virtualNetworks/', 'sampleVnet')]",
"[resourceId(parameters('publicIpResourceGroupName'),'Microsoft.Network/publicIPAddresses', 'DemoEIP')]"
],
"properties": {
"ipConfigurations": [
{
"name": "ipconfig",
"properties": {
"privateIPAllocationMethod": "Dynamic",
"publicIPAddress": {
"id": "[resourceId(parameters('publicIpResourceGroupName'),'Microsoft.Network/publicIPAddresses', 'DemoEIP')]"
},
"subnet": {
"id": "[resourceId(parameters('virtualNetworkResourceGroupName'),'Microsoft.Network/virtualNetworks/subnets', 'sampleVnet', 'DemoSubnet')]"
}
}
}
]
}
},
{
"type": "Microsoft.Network/publicIPAddresses",
"apiVersion": "2017-09-01",
"name": "DemoEIP",
"location": "[parameters('location')]",
"properties": {
"publicIPAllocationMethod": "Static"
},
"condition": "[equals(parameters('publicIpNewOrExisting'), 'existing')]"
},
{
"type": "Microsoft.Network/virtualNetworks",
"apiVersion": "2017-09-01",
"name": "sampleVnet",
"location": "[parameters('location')]",
"properties": {
"addressSpace": {
"addressPrefixes": "[parameters('addressPrefixes')]"
},
"subnets": [
{
"name": "DemoSubnet",
"properties": {
"addressPrefix": "[parameters('subnetPrefix')]"
}
}
]
},
"condition": "[equals(parameters('virtualNetworkNewOrExisting'), 'existing')]"
}
]
}

How to create custom script extension on virtual machine scale set of linux using azure resource manager template?

Here is my template1.json which is used to create cluster with virtual machine scale set. I want to add extensions to it using the same arm template1. I tried including script of extensions in the properties section of managed clusters ( template2.json) but it is throwing error of parent resource vnetName not found.
I tried adding extensionProfile in the properties section of managed clusters but that also didn't work.
can anyone help me out how can I set custom script extension using same arm template?
template1.json
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"vnetName": {
"type": "string",
"metadata": {
"description": "VNet name"
}
},
"location": {
"type": "string",
"defaultValue": "[resourceGroup().location]",
"metadata": {
"description": "Azure resource location"
}
},
"vnetAddressPrefix": {
"type": "string",
"metadata": {
"description": "Virtual network address range"
}
},
"subnetName": {
"type": "string",
"metadata": {
"description": "Azure subnet Name"
}
},
"subnetPrefix": {
"type": "string",
"metadata": {
"description": "Azure subnet prefix"
}
},
"kubernetesVersion": {
"type": "string",
"metadata": {
"description": "kubernetesVersion"
}
},
"enableRBAC": {
"defaultValue": false,
"type": "bool",
"metadata": {
"description": "boolean flag to turn on and off of RBAC"
}
},
"dnsPrefix": {
"type": "string",
"metadata": {
"description": "Optional DNS prefix to use with hosted Kubernetes API server FQDN."
}
},
"enableHttpApplicationRouting": {
"defaultValue": false,
"type": "bool",
"metadata": {
"description": "boolean flag to turn on and off of http application routing"
}
},
"osDiskSizeGB": {
"defaultValue": 0,
"minValue": 0,
"maxValue": 1023,
"type": "int",
"metadata": {
"description": "Disk size (in GB) to provision for each of the agent pool nodes. This value ranges from 0 to 1023. Specifying 0 will apply the default disk size for that agentVMSize."
}
},
"agentCount": {
"minValue": 1,
"maxValue": 50,
"type": "int",
"metadata": {
"description": "The number of agent nodes for the cluster. Production workloads have a recommended minimum of 3."
}
},
"agentVMSize": {
"type": "string",
"metadata": {
"description": "The size of the Virtual Machine."
}
},
"masterCount": {
"type": "int",
"allowedValues": [
1
],
"metadata": {
"description": "The number of Kubernetes masters for the cluster."
}
},
"adminUsername": {
"type": "string",
"defaultValue": "azureuser",
"metadata": {
"description": "User name for the Linux Virtual Machines."
}
},
"osType": {
"defaultValue": "Linux",
"allowedValues": [
"Linux"
],
"type": "string",
"metadata": {
"description": "The type of operating system."
}
},
"maxPods": {
"defaultValue": 30,
"type": "int",
"metadata": {
"description": "Maximum number of pods that can run on a node."
}
},
"ServicePrincipalClientId": {
"type": "string",
"metadata": {
"description": "ServicePrincipalClientId"
}
},
"ServicePrincipalClientSecret": {
"type": "string",
"metadata": {
"description": "ServicePrincipalClientId"
}
},
"ServicePrincipalObjectId": {
"type": "string",
"metadata": {
"description": "ServicePrincipalClientId"
}
},
"sshRSAPublicKey": {
"type": "securestring",
"metadata": {
"description": "Configure all linux machines with the SSH RSA public key string"
}
},
"networkPlugin": {
"allowedValues": [
"azure",
"kubenet"
],
"defaultValue": "kubenet",
"type": "string",
"metadata": {
"description": "Network plugin used for building Kubernetes network."
}
},
"dockerBridgeCidr": {
"type": "string",
"metadata": {
"description": "A CIDR notation IP for Docker bridge."
}
},
"dnsServiceIP": {
"type": "string",
"metadata": {
"description": "Containers DNS server IP address."
}
},
"serviceCidr": {
"type": "string",
"metadata": {
"description": "A CIDR notation IP range from which to assign service cluster IPs."
}
},
"resourceGroup": {
"type": "string",
"defaultValue": "[resourceGroup().name]",
"metadata": {
"description": "Azure resource group."
}
},
"autoscalingEnabled": {
"type": "bool",
"defaultValue": true,
"metadata": {
"description": "Flag to enable autoscaling."
}
},
"nodesMinimum": {
"type": "int",
"defaultValue": 2,
"metadata": {
"description": "Minimum number of nodes for autoscaling."
}
},
"nodesMaximum": {
"type": "int",
"defaultValue": 4,
"metadata": {
"description": "Maximum number of nodes for autoscaling."
}
}
},
"variables": {
"mastersEndpointDNSNamePrefix":"[concat(parameters('dnsPrefix'),'mgmt')]"
},
"resources": [
{
"type": "Microsoft.Resources/deployments",
"apiVersion": "2019-08-01",
"name": "nestedTemplate",
"properties": {
"mode": "Incremental",
"template": {
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"resources": [
{
"apiVersion": "2019-06-01",
"type": "Microsoft.Network/virtualNetworks",
"name": "[parameters('vnetName')]",
"location": "[parameters('location')]",
"properties": {
"addressSpace": {
"addressPrefixes": [
"[parameters('vnetAddressPrefix')]"
]
},
"subnets": [
{
"name": "[parameters('subnetName')]",
"properties": {
"addressPrefix": "[parameters('subnetPrefix')]"
}
}
]
}
},
{
"type": "Microsoft.ContainerService/managedClusters",
"name":"[concat('Kluster-',resourceGroup().name)]",
"apiVersion": "2019-08-01",
"location": "[parameters('location')]",
"tags": {},
"dependsOn": [
"[concat('Microsoft.Resources/deployments/', 'ClusterSubnetRoleAssignmentDeployment')]"
],
"properties": {
"kubernetesVersion": "[parameters('kubernetesVersion')]",
"enableRBAC": "[parameters('enableRBAC')]",
"dnsPrefix": "[parameters('dnsPrefix')]",
"addonProfiles": {
"httpApplicationRouting": {
"enabled": "[parameters('enableHttpApplicationRouting')]"
}
},
"masterProfile": {
"count": "[parameters('masterCount')]",
"vmSize": "[parameters('agentVMSize')]",
"dnsPrefix": "[variables('mastersEndpointDNSNamePrefix')]"
},
"agentPoolProfiles": [
{
"name": "agentpool",
"osDiskSizeGB": "[parameters('osDiskSizeGB')]",
"count": "[parameters('agentCount')]",
"vmSize": "[parameters('agentVMSize')]",
"osType": "[parameters('osType')]",
"storageProfile": "ManagedDisks",
"vnetSubnetID": "[concat(resourceGroup().id,'/providers/Microsoft.Network/virtualNetworks/',parameters('vnetName'),'/subnets/',parameters('subnetName'))]",
"maxPods": "[parameters('maxPods')]",
"enableAutoScaling": "[parameters('autoscalingEnabled')]",
"minCount": "[parameters('nodesMinimum')]",
"maxCount": "[parameters('nodesMaximum')]",
"type": "VirtualMachineScaleSets"
}
],
"linuxProfile": {
"adminUsername": "[parameters('adminUsername')]",
"ssh": {
"publicKeys": [
{
"keyData": "[parameters('sshRSAPublicKey')]"
}
]
}
},
"servicePrincipalProfile": {
"clientId": "[parameters('ServicePrincipalClientId')]",
"secret": "[parameters('ServicePrincipalClientSecret')]"
},
"networkProfile": {
"networkPlugin": "[parameters('networkPlugin')]",
"serviceCidr": "[parameters('serviceCidr')]",
"dnsServiceIP": "[parameters('dnsServiceIP')]",
"dockerBridgeCidr": "[parameters('dockerBridgeCidr')]"
}
}
},
{
"type": "Microsoft.Resources/deployments",
"name": "ClusterSubnetRoleAssignmentDeployment",
"apiVersion": "2019-08-01",
"subscriptionId": "[subscription().subscriptionId]",
"resourceGroup": "[parameters('resourceGroup')]",
"dependsOn": [
"[concat('Microsoft.Network/virtualNetworks/', parameters('vnetName'))]"
],
"properties": {
"mode": "Incremental",
"template": {
"$schema": "https://schema.management.azure.com/schemas/2018-05-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {},
"variables": {},
"resources": [
{
"type": "Microsoft.Network/virtualNetworks/subnets/providers/roleAssignments",
"apiVersion": "2019-04-01-preview",
"name": "[concat(parameters('vnetName'), '/', parameters('subnetName'), '/Microsoft.Authorization/', guid(resourceGroup().id, deployment().name))]",
"properties": {
"roleDefinitionId": "[concat('/subscriptions/', subscription().subscriptionId, '/providers/Microsoft.Authorization/roleDefinitions/', '4d97b98b-1d4f-4787-a291-c67834d212e7')]",
"principalId": "[parameters('ServicePrincipalObjectId')]",
"scope": "[concat(resourceGroup().id,'/providers/Microsoft.Network/virtualNetworks/',parameters('vnetName'),'/subnets/',parameters('subnetName'))]"
}
}
]
}
}
}
]
}
}
}
]
}
template2.json
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
Please copy from template1.json (due to characters limit I have removed)
},
"variables": {
"mastersEndpointDNSNamePrefix":"[concat(parameters('dnsPrefix'),'mgmt')]",
"vmssName":"aks-agentpool-43678249-vmss"
},
"resources": [
{
"type": "Microsoft.Resources/deployments",
"apiVersion": "2019-08-01",
"name": "nestedTemplate",
"properties": {
"mode": "Incremental",
"template": {
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"resources": [
{
"apiVersion": "2019-06-01",
"type": "Microsoft.Network/virtualNetworks",
"name": "[parameters('vnetName')]",
"location": "[parameters('location')]",
"properties": {
"addressSpace": {
"addressPrefixes": [
"[parameters('vnetAddressPrefix')]"
]
},
"subnets": [
{
"name": "[parameters('subnetName')]",
"properties": {
"addressPrefix": "[parameters('subnetPrefix')]"
}
}
]
}
},
{
"type": "Microsoft.ContainerService/managedClusters",
"name":"[concat('Kluster-',resourceGroup().name)]",
"apiVersion": "2019-08-01",
"location": "[parameters('location')]",
"tags": {},
"dependsOn": [
"[concat('Microsoft.Resources/deployments/', 'ClusterSubnetRoleAssignmentDeployment')]"
],
"properties": {
"kubernetesVersion": "[parameters('kubernetesVersion')]",
"enableRBAC": "[parameters('enableRBAC')]",
"dnsPrefix": "[parameters('dnsPrefix')]",
"addonProfiles": {
"httpApplicationRouting": {
"enabled": "[parameters('enableHttpApplicationRouting')]"
}
},
"masterProfile": {
"count": "[parameters('masterCount')]",
"vmSize": "[parameters('agentVMSize')]",
"dnsPrefix": "[variables('mastersEndpointDNSNamePrefix')]"
},
"agentPoolProfiles": [
{
"name": "agentpool",
"osDiskSizeGB": "[parameters('osDiskSizeGB')]",
"count": "[parameters('agentCount')]",
"vmSize": "[parameters('agentVMSize')]",
"osType": "[parameters('osType')]",
"storageProfile": "ManagedDisks",
"vnetSubnetID": "[concat(resourceGroup().id,'/providers/Microsoft.Network/virtualNetworks/',parameters('vnetName'),'/subnets/',parameters('subnetName'))]",
"maxPods": "[parameters('maxPods')]",
"enableAutoScaling": "[parameters('autoscalingEnabled')]",
"minCount": "[parameters('nodesMinimum')]",
"maxCount": "[parameters('nodesMaximum')]",
"type": "virtualMachineScaleSets"
}
],
"linuxProfile": {
"adminUsername": "[parameters('adminUsername')]",
"ssh": {
"publicKeys": [
{
"keyData": "[parameters('sshRSAPublicKey')]"
}
]
}
},
"servicePrincipalProfile": {
"clientId": "[parameters('ServicePrincipalClientId')]",
"secret": "[parameters('ServicePrincipalClientSecret')]"
},
"networkProfile": {
"networkPlugin": "[parameters('networkPlugin')]",
"serviceCidr": "[parameters('serviceCidr')]",
"dnsServiceIP": "[parameters('dnsServiceIP')]",
"dockerBridgeCidr": "[parameters('dockerBridgeCidr')]"
}
},
"resources": [
{
"apiVersion": "2019-03-01",
"type": "Microsoft.Compute/virtualMachines/extensions",
"name": "[concat('aks-agentpool-43678249-vmss','/', 'Extensions')]",
"location": "[parameters('location')]",
"dependsOn": [
"[concat('Microsoft.Network/virtualNetworks/', parameters('vnetName'))]",
"[concat('Microsoft.ContainerService/managedClusters/', concat('Kluster-',resourceGroup().name))]"
],
"properties": {
"publisher": "Microsoft.Azure.Extensions",
"type": "CustomScript",
"typeHandlerVersion": "2.0",
"autoUpgradeMinorVersion":true,
"settings": {
"skipDos2Unix":false,
"fileUris": ["filelink"],
"commandToExecute": "./filename.sh"
}
}
}
]
},
{
"type": "Microsoft.Resources/deployments",
"name": "ClusterSubnetRoleAssignmentDeployment",
"apiVersion": "2019-08-01",
"subscriptionId": "[subscription().subscriptionId]",
"resourceGroup": "[parameters('resourceGroup')]",
"dependsOn": [
"[concat('Microsoft.Network/virtualNetworks/', parameters('vnetName'))]"
],
"properties": {
"mode": "Incremental",
"template": {
"$schema": "https://schema.management.azure.com/schemas/2018-05-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {},
"variables": {},
"resources": [
{
"type": "Microsoft.Network/virtualNetworks/subnets/providers/roleAssignments",
"apiVersion": "2019-04-01-preview",
"name": "[concat(parameters('vnetName'), '/', parameters('subnetName'), '/Microsoft.Authorization/', guid(resourceGroup().id, deployment().name))]",
"properties": {
"roleDefinitionId": "[concat('/subscriptions/', subscription().subscriptionId, '/providers/Microsoft.Authorization/roleDefinitions/', '4d97b98b-1d4f-4787-a291-c67834d212e7')]",
"principalId": "[parameters('ServicePrincipalObjectId')]",
"scope": "[concat(resourceGroup().id,'/providers/Microsoft.Network/virtualNetworks/',parameters('vnetName'),'/subnets/',parameters('subnetName'))]"
}
}
]
}
}
}
]
}
}
}
]
}
Error thrown : Parent resource vnetname not found as shown below
template1_params.json
{
"$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"vnetName": {
"value": "aks-vnet"
},
"vnetAddressPrefix": {
"value": "10.0.0.0/8"
},
"subnetName": {
"value": "aks-subnet"
},
"subnetPrefix": {
"value": "10.240.0.0/16"
},
"kubernetesVersion": {
"value": "1.13.12"
},
"dnsPrefix": {
"value": "test"
},
"agentCount": {
"value": 2
},
"agentVMSize": {
"value": "Standard_E2_v3"
},
"masterCount": {
"value": 1
},
"ServicePrincipalClientId": {
"value": "clientid..."
},
"ServicePrincipalClientSecret": {
"value": "clientsecret..."
},
"ServicePrincipalObjectId": {
"value": "objectid.."
},
"sshRSAPublicKey": {
"value": "sshrsa-...."
},
"dnsServiceIP": {
"value": "10.0.0.10"
},
"serviceCidr": {
"value": "10.0.0.0/16"
},
"dockerBridgeCidr": {
"value": "172.17.0.1/16"
},
"nodesMinimum": {
"value": 2
},
"nodesMaximum": {
"value": 4
}
}
}
For your issue, there are two mistakes in your template as I see, maybe not all.
One is that the resources block in the AKS cluster, it's not for the extensions, only for the agent pools. You can learn its definition in Microsoft.ContainerService/managedClusters object.
Another is that you create the AKS cluster with virtual machine scale sets, so the extension should be the type Microsoft.Compute/virtualMachineScaleSets/extensions.
Maybe you can provide more details about the issue to get an exact solution. But before, you can try to change your template to fix the mistakes I found above.

How to add the existing virtual network into Azure SQL database using Azure ARM Template?

Currently I am working on to deploy the Azure SQL Database into exisiting virtual network using Azure ARM templates.
azuredeploy.json
{
"$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"sqlServerName": {
"type": "string",
"metadata": {
"description": "The SQL Servername."
}
},
"databaseName": {
"type": "string",
"metadata": {
"description": "The SQL Database."
}
},
"collation": {
"type": "string",
"metadata": {
"description": "The Collation of SQL Database and SQL Server."
}
},
"edition": {
"type": "string",
"metadata": {
"description": "The edition of SQL Database."
}
},
"maxSizeBytes": {
"type": "string",
"metadata": {
"description": "The maxsize of SQL Database."
}
},
"sqlAdministratorLogin": {
"type": "string",
"metadata": {
"description": "The administrator username of the SQL Server."
}
},
"sqlAdministratorLoginPassword": {
"type": "securestring",
"metadata": {
"description": "The administrator password of the SQL Server."
}
},
"transparentDataEncryption": {
"type": "string",
"allowedValues": [
"Enabled",
"Disabled"
],
"defaultValue": "Enabled",
"metadata": {
"description": "Enable or disable Transparent Data Encryption (TDE) for the database."
}
},
"zoneRedundant": {
"type": "bool",
"defaultValue": false
},
"startIpAddress": {
"type": "string",
"metadata": {
"description": "The start IpAddress"
}
},
"endIpAddress": {
"type": "string",
"metadata": {
"description": "The end IpAddress."
}
},
"sampleName": {
"type": "string",
"metadata": {
"description": "The sampleName."
}
},
"existingVnetName": {
"type": "string",
"metadata": {
"description": "The name of the existing virtual netwok."
}
},
"vnetRuleName": {
"type": "string",
"metadata": {
"description": "The name of the virtual netwrok rule."
}
},
"existingVirtualNetworkResourceGroup": {
"type": "string",
"metadata": {
"description": "The name of the exisitng VNET resource group."
}
},
"subscriptionID": {
"type": "string",
"metadata": {
"description": "The ID of the exisitng azure subscription."
}
}
},
"variables": {
"sqlServerName": "[parameters('sqlServerName')]",
"databaseName": "[parameters('databaseName')]",
"databaseEdition": "[parameters('edition')]",
"databaseCollation": "[parameters('collation')]",
"databaseServiceObjectiveName": "Basic",
"vnetID": "[concat('/subscriptions/', parameters('subscriptionID'), '/resourceGroups/',parameters('existingVirtualNetworkResourceGroup'),'/','Microsoft.Network/virtualNetworks', parameters('existingVnetName'))]",
//"vnetID": "[resourceId(parameters('resourceGroupName'), 'Microsoft.Network/virtualNetworks', parameters('existingVnetName'))]"
},
"resources": [
{
"name": "[variables('sqlServerName')]",
"type": "Microsoft.Sql/servers",
"apiVersion": "2014-04-01-preview",
"location": "[resourceGroup().location]",
"tags": {
"displayName": "SqlServer"
},
"properties": {
"administratorLogin": "[parameters('sqlAdministratorLogin')]",
"administratorLoginPassword": "[parameters('sqlAdministratorLoginPassword')]",
"version": "12.0"
},
"resources": [
{
"name": "[variables('databaseName')]",
"type": "databases",
"apiVersion": "2015-01-01",
"location": "[resourceGroup().location]",
"tags": {
"displayName": "Database"
},
"properties": {
"edition": "[variables('databaseEdition')]",
"collation": "[variables('databaseCollation')]",
"requestedServiceObjectiveName": "[variables('databaseServiceObjectiveName')]",
"maxSizeBytes": "[parameters('maxSizeBytes')]",
"sampleName": "[parameters('sampleName')]",
"zoneRedundant": "[parameters('zoneRedundant')]"
},
"dependsOn": [
"[variables('sqlServerName')]"
],
"resources": [
{
"comments": "Transparent Data Encryption",
"name": "current",
"type": "transparentDataEncryption",
"apiVersion": "2014-04-01-preview",
"properties": {
"status": "[parameters('transparentDataEncryption')]"
},
"dependsOn": [
"[variables('databaseName')]"
]
}
]
},
{
"name": "AllowAllMicrosoftAzureIps",
"type": "firewallrules",
"apiVersion": "2014-04-01",
"location": "[resourceGroup().location]",
"properties": {
"startIpAddress": "[parameters('startIpAddress')]",
"endIpAddress": "[parameters('endIpAddress')]"
},
"dependsOn": [
"[variables('sqlServerName')]"
]
},
{
"comments": "Adding existing VNET to the SQL Server",
"type": "Microsoft.Sql/servers/virtualNetworkRules",
"name": "[concat(parameters('sqlServerName'), '/', parameters('vnetRuleName'))]",
"apiVersion": "2015-05-01-preview",
"scale": null,
"properties": {
"virtualNetworkSubnetId": "[variables('vnetID')]"
},
"dependsOn": [
"[resourceId('Microsoft.Sql/servers', parameters('sqlServerName'))]"
]
}
]
}
],
"outputs": {
"sqlServerFqdn": {
"type": "string",
"value": "[reference(concat('Microsoft.Sql/servers/', variables('sqlServerName'))).fullyQualifiedDomainName]"
},
"databaseName": {
"type": "string",
"value": "[variables('databaseName')]"
}
}
}
Before I added this Microsoft.Sql/servers/virtualNetworkRules section into azuredeploy.json file at that time I am able to create the new SQL database into azure.
{
"comments": "Adding existing VNET to the SQL Server",
"type": "Microsoft.Sql/servers/virtualNetworkRules",
"name": "[concat(parameters('sqlServerName'), '/', parameters('vnetRuleName'))]",
"apiVersion": "2015-05-01-preview",
"scale": null,
"properties": {
"virtualNetworkSubnetId": "[variables('vnetID')]"
},
"dependsOn": [
"[resourceId('Microsoft.Sql/servers', parameters('sqlServerName'))]"
]
}
But whenever I added this Microsoft.Sql/servers/virtualNetworkRules section into azuredeploy.json file at that time I am not able to create database into existing virtual network and also it doesn’t give any response.
Can anyone please tell me where I did the mistake in the above azuredeploy.json file?
Finally I resolved the above issue by replacing this section of code with Microsoft.Sql/servers/virtualNetworkRules the below lines of code:
{
"comments": "Adding existing VNET to the SQL Server",
"type": "Microsoft.Sql/servers/virtualNetworkRules",
"name": "[concat(parameters('sqlServerName'), '/', parameters('vnetRuleName'))]",
"apiVersion": "2015-05-01-preview",
"scale": null,
"properties": {
"virtualNetworkSubnetId": "[resourceId('Microsoft.Network/virtualNetworks/subnets', parameters('existingVnetName'), parameters('subnets_default_name'))]",
"ignoreMissingVnetServiceEndpoint": "[parameters('ignoreMissingVnetServiceEndpoint')]"
},
"dependsOn": [
"[resourceId('Microsoft.Sql/servers', parameters('sqlServerName'))]"
]
}

Resources