nav-arm-templates/buildagent.json

463 строки
19 KiB
JSON

{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json",
"contentVersion": "1.0.0.0",
"parameters": {
"vmName": {
"type": "string",
"defaultValue": "",
"minLength": 3,
"maxLength": 15,
"metadata": {
"Description": "Select the name of the deployment"
}
},
"RemoteDesktopAccess": {
"type": "string",
"defaultValue": "",
"minLength": 1,
"metadata": {
"Description": "Specify * (star) to allow all remote desktop access, specify - (minus) to deny all remote desktop access (use JIT) or provide an address range using CIDR notation, e.g. 10.0.0.0/24; an IP address; or a list of address ranges or IP addresses"
}
},
"OperatingSystem": {
"type": "string",
"defaultValue": "Windows Server 2019",
"allowedValues": [
"Windows Server 2019",
"Windows Server 2019 with Containers",
"Windows Server 2022"
],
"metadata": {
"Description": "Select the Operating System of the VM"
}
},
"vmSize": {
"type": "string",
"defaultValue": "Standard_D4s_v3",
"allowedValues": [
"Standard_D2_v2",
"Standard_D3_v2",
"Standard_D4_v2",
"Standard_D5_v2",
"Standard_D2_v3",
"Standard_D4_v3",
"Standard_D8_v3",
"Standard_D16_v3",
"Standard_D32_v3",
"Standard_D48_v3",
"Standard_D64_v3",
"Standard_D2s_v3",
"Standard_D4s_v3",
"Standard_D8s_v3",
"Standard_D16s_v3",
"Standard_D32s_v3",
"Standard_D48s_v3",
"Standard_D64s_v3",
"Standard_D2_v4",
"Standard_D4_v4",
"Standard_D8_v4",
"Standard_D16_v4",
"Standard_D32_v4",
"Standard_D48_v4",
"Standard_D64_v4",
"Standard_D2s_v4",
"Standard_D4s_v4",
"Standard_D8s_v4",
"Standard_D16s_v4",
"Standard_D32s_v4",
"Standard_D48s_v4",
"Standard_D64s_v4",
"Standard_D2a_v4",
"Standard_D4a_v4",
"Standard_D8a_v4",
"Standard_D16a_v4",
"Standard_D32a_v4",
"Standard_D48a_v4",
"Standard_D64a_v4",
"Standard_D2as_v4",
"Standard_D4as_v4",
"Standard_D8as_v4",
"Standard_D16as_v4",
"Standard_D32as_v4",
"Standard_D48as_v4",
"Standard_D64as_v4",
"Standard_D2_v5",
"Standard_D4_v5",
"Standard_D8_v5",
"Standard_D16_v5",
"Standard_D32_v5",
"Standard_D48_v5",
"Standard_D64_v5",
"Standard_D2s_v5",
"Standard_D4s_v5",
"Standard_D8s_v5",
"Standard_D16s_v5",
"Standard_D32s_v5",
"Standard_D48s_v5",
"Standard_D64s_v5",
"Standard_D2a_v5",
"Standard_D4a_v5",
"Standard_D8a_v5",
"Standard_D16a_v5",
"Standard_D32a_v5",
"Standard_D48a_v5",
"Standard_D64a_v5",
"Standard_D2as_v5",
"Standard_D4as_v5",
"Standard_D8as_v5",
"Standard_D16as_v5",
"Standard_D32as_v5",
"Standard_D48as_v5",
"Standard_D64as_v5"
],
"metadata": {
"Description": "Select the VM size of the deployment"
}
},
"StorageAccountType": {
"type": "string",
"defaultValue": "Premium_LRS",
"allowedValues": [
"Standard_LRS",
"Premium_LRS"
],
"metadata": {
"Description": "Select the preferred storage account type. Standard_LRS is HDD, Premium_LRS is SSD. (Not all VM Sizes support SSD)"
}
},
"osDiskSize": {
"type": "int",
"defaultValue": 128,
"metadata": {
"Description": "Select the size of the OS Disk"
}
},
"vmAdminUsername": {
"type": "string",
"defaultValue": "vmadmin",
"minLength": 1,
"metadata": {
"Description": "Specify administrator user name for connecting to the VM"
}
},
"adminPassword": {
"type": "securestring",
"metadata": {
"Description": "Specify administrator password for VM, Business Central and SQL (if applicable)"
}
},
"count": {
"type": "int",
"defaultValue": 2,
"metadata": {
"Description": "Select the number of agents you want to create on the VM"
}
},
"Token": {
"type": "securestring",
"minLength": 1,
"metadata": {
"Description": "Specify a personal access token with permissions to add/remove agents from the agent pool for Azure DevOps or the token provided at https://github.com/{organization}/{repository}/settings/actions/runners/new for Github"
}
},
"Organization": {
"type": "string",
"minLength": 1,
"metadata": {
"Description": "Specify the URL for your GitHub Project/Organization or your Azure DevOps Organization (ex. https://github.com/BusinessCentralApps, https://github.com/freddydk/BingMaps.AppSource or https://dev.azure.com/freddykristiansen)"
}
},
"LabelsOrPool": {
"type": "string",
"defaultValue": "default",
"minLength": 1,
"metadata": {
"Description": "Specify additional labels for GitHub runners or specify the pool in which your agent should live for Azure DevOps"
}
},
"AgentUrl": {
"type": "string",
"defaultValue": "",
"minLength": 1,
"metadata": {
"Description": "Specify the URL for downloading the Agent. GitHub runner URL can be found at https://github.com/{organization}/{repository}/settings/actions/runners/new (ex. https://github.com/actions/runner/releases/download/v2.284.0/actions-runner-win-x64-2.284.0.zip). x64 Azure DevOps Agent can be found at https://dev.azure.com/{your_organization}/_admin/_AgentPool (click Download agent and select x64 ) (ex. https://vstsagentpackage.azureedge.net/agent/2.194.0/vsts-agent-win-x64-2.194.0.zip)"
}
},
"RunInsideDocker": {
"type": "string",
"defaultValue": "No",
"minLength": 1,
"metadata": {
"Description": "Run agents inside Docker (Yes/No)"
}
},
"FinalSetupScriptUrl": {
"type": "string",
"defaultValue": "additional-installforbuildagent.ps1",
"metadata": {
"Description": "Optional: Specify a Url to a PowerShell script that should be executed on the VM to do the final setup of the VM."
}
}
},
"variables": {
"vmName": "[trim(parameters('vmName'))]",
"vmSize": "[parameters('vmSize')]",
"RemoteDesktopAccess": "[parameters('RemoteDesktopAccess')]",
"vmAdminUsername": "[trim(parameters('vmAdminUsername'))]",
"adminPassword": "[parameters('adminPassword')]",
"OperatingSystem": "[parameters('OperatingSystem')]",
"imagePublisher": "[if(equals(variables('OperatingSystem'),'Windows 11'),'MicrosoftWindowsDesktop','MicrosoftWindowsServer')]",
"imageOffer": "[if(equals(variables('OperatingSystem'),'Windows 11'),'Windows-11','WindowsServer')]",
"imageSku": "[if(equals(variables('OperatingSystem'),'Windows 11'),'win11-21h2-pro',if(equals(variables('OperatingSystem'),'Windows Server 2022'),'2022-Datacenter',if(equals(variables('OperatingSystem'),'Windows Server 2019'),'2019-Datacenter','2019-Datacenter-with-containers')))]",
"storageAccountType": "[parameters('StorageAccountType')]",
"OSDiskName": "[concat(variables('vmName'),'_osdisk')]",
"publicIPAddressName": "[concat(variables('vmName'), '_pip')]",
"storageAccountName": "[concat('storage', uniqueString(resourceGroup().id))]",
"networkSecurityGroupName": "networksecuritygroup",
"dnsName": "[tolower(variables('vmName'))]",
"addressPrefix": "10.0.0.0/16",
"subnetName": "Subnet",
"subnetPrefix": "10.0.0.0/24",
"virtualNetworkName": "virtualnetwork",
"server1Name": "[tolower(variables('vmName'))]",
"nic1Name": "[concat(variables('vmName'),'_nic')]",
"delimiters": [ ",", ";" ],
"RdpAddresses": "[if(equals(variables('RemoteDesktopAccess'),'-'),'',variables('RemoteDesktopAccess'))]",
"rdpSourceAddressPrefix": "[split(variables('RdpAddresses'),variables('delimiters'))]",
"noOfAddresses": "[length(variables('rdpSourceAddressPrefix'))]",
"vnetID": "[resourceId('Microsoft.Network/virtualNetworks',variables('virtualNetworkName'))]",
"subnetRef": "[concat(variables('vnetID'),'/subnets/',variables('subnetName'))]",
"ScriptCommandToExecute": "powershell.exe -executionpolicy unrestricted -file "
},
"resources": [
{
"apiVersion": "2015-05-01-preview",
"type": "Microsoft.Storage/storageAccounts",
"name": "[variables('storageAccountName')]",
"location": "[resourceGroup().location]",
"properties": {
"accountType": "[variables('storageAccountType')]"
}
},
{
"apiVersion": "2015-05-01-preview",
"type": "Microsoft.Network/publicIPAddresses",
"name": "[variables('publicIPAddressName')]",
"location": "[resourceGroup().location]",
"properties": {
"publicIPAllocationMethod": "Dynamic",
"dnsSettings": {
"domainNameLabel": "[variables('dnsName')]"
}
}
},
{
"apiVersion": "2015-05-01-preview",
"type": "Microsoft.Network/networkSecurityGroups",
"name": "[variables('networkSecurityGroupName')]",
"location": "[resourceGroup().location]",
"properties": {
"securityRules": [
]
}
},
{
"apiVersion": "2015-01-01",
"type": "Microsoft.Resources/deployments",
"name": "rdp-0",
"condition": "[not(equals(variables('RemoteDesktopAccess'),'-'))]",
"dependsOn": [
"[concat('Microsoft.Network/networkSecurityGroups/',variables('networkSecurityGroupName'))]"
],
"properties": {
"mode":"Incremental",
"parameters":{},
"template": {
"$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {},
"variables": {},
"resources": [],
"outputs": {}
}
}
},
{
"apiVersion": "2015-01-01",
"type": "Microsoft.Resources/deployments",
"name": "[concat('rdp-', copyIndex(1))]",
"condition": "[not(equals(variables('RemoteDesktopAccess'),'-'))]",
"dependsOn": [
"[concat('rdp-', copyIndex())]"
],
"copy": {
"name": "iterator",
"count": "[variables('noOfAddresses')]"
},
"properties": {
"mode": "Incremental",
"template": {
"$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {},
"variables": {},
"resources": [
{
"apiVersion": "2016-09-01",
"name": "[concat(variables('networkSecurityGroupName'),'/Rdp',copyIndex())]",
"type": "Microsoft.Network/networkSecurityGroups/securityRules",
"location":"[resourceGroup().location]",
"properties":{
"description": "Remote Desktop Access",
"protocol": "Tcp",
"sourcePortRange": "*",
"destinationPortRange": "3389",
"sourceAddressPrefix": "[variables('rdpSourceAddressPrefix')[copyIndex()]]",
"destinationAddressPrefix": "*",
"access": "Allow",
"priority": "[add(copyIndex(),100)]",
"direction": "Inbound"
}
}
],
"outputs": {}
}
}
},
{
"apiVersion": "2015-05-01-preview",
"type": "Microsoft.Network/virtualNetworks",
"name": "[variables('virtualNetworkName')]",
"location": "[resourceGroup().location]",
"dependsOn": [
"[concat('Microsoft.Network/networkSecurityGroups/',variables('networkSecurityGroupName'))]"
],
"properties": {
"addressSpace": {
"addressPrefixes": [
"[variables('addressPrefix')]"
]
},
"subnets": [
{
"name": "[variables('subnetName')]",
"properties": {
"addressPrefix": "[variables('subnetPrefix')]",
"networkSecurityGroup": {
"id": "[resourceId('Microsoft.Network/networkSecurityGroups', variables('networkSecurityGroupName'))]"
}
}
}
]
}
},
{
"apiVersion": "2018-11-01",
"type": "Microsoft.Network/networkInterfaces",
"name": "[variables('nic1Name')]",
"location": "[resourceGroup().location]",
"dependsOn": [
"[concat('Microsoft.Network/publicIPAddresses/', variables('publicIPAddressName'))]",
"[concat('Microsoft.Network/virtualNetworks/', variables('virtualNetworkName'))]",
"[concat('Microsoft.Network/networkSecurityGroups/',variables('networkSecurityGroupName'))]"
],
"properties": {
"networkSecurityGroup": {
"id": "[resourceId('Microsoft.Network/networkSecurityGroups', variables('networkSecurityGroupName'))]"
},
"ipConfigurations": [
{
"name": "ipconfig1",
"properties": {
"privateIPAllocationMethod": "Dynamic",
"publicIPAddress": {
"id": "[resourceId('Microsoft.Network/publicIPAddresses',variables('publicIPAddressName'))]"
},
"subnet": {
"id": "[variables('subnetRef')]"
}
}
}
]
}
},
{
"apiVersion": "2018-10-01",
"type": "Microsoft.Compute/virtualMachines",
"name": "[variables('server1Name')]",
"location": "[resourceGroup().location]",
"dependsOn": [
"[concat('Microsoft.Storage/storageAccounts/', variables('storageAccountName'))]",
"[concat('Microsoft.Network/networkInterfaces/', variables('nic1Name'))]"
],
"properties": {
"hardwareProfile": {
"vmSize": "[variables('vmSize')]"
},
"osProfile": {
"computerName": "[variables('server1Name')]",
"adminUsername": "[variables('vmAdminUsername')]",
"adminPassword": "[variables('adminPassword')]",
"windowsConfiguration": {
"provisionVMAgent": true
}
},
"storageProfile": {
"imageReference": {
"publisher": "[variables('imagePublisher')]",
"offer": "[variables('imageOffer')]",
"sku": "[variables('imageSku')]",
"version": "latest"
},
"osDisk": {
"createOption": "FromImage",
"osType": "Windows",
"name": "[variables('OSDiskName')]",
"caching": "ReadWrite",
"managedDisk": {
"storageAccountType": "[variables('storageAccountType')]"
},
"diskSizeGB": "[parameters('OSDiskSize')]"
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "[resourceId('Microsoft.Network/networkInterfaces',variables('nic1Name'))]"
}
]
}
},
"resources": [
]
},
{
"apiVersion": "2015-06-15",
"type": "Microsoft.Compute/virtualMachines/extensions",
"name": "[concat(variables('server1Name'),'/vmextension1')]",
"location": "[resourceGroup().location]",
"tags": {
"displayName": "PowerShellScript2"
},
"dependsOn": [
"[concat('Microsoft.Compute/virtualMachines/', variables('server1Name'))]"
],
"properties": {
"publisher": "Microsoft.Compute",
"type": "CustomScriptExtension",
"typeHandlerVersion": "1.9",
"autoUpgradeMinorVersion": true,
"settings": {
"fileUris": [
"[uri(deployment().properties.templateLink.uri, 'initbuildagent.ps1')]"
],
"commandToExecute": "[concat(variables('ScriptCommandToExecute'),'initbuildagent.ps1',' -TemplateLink \"',deployment().properties.templateLink.uri,'\" -VMAdminUsername \"',variables('vmAdminUsername'),'\" -AdminPassword \"',replace(variables('adminPassword'),'\"','\\\"'),'\" -Organization \"',parameters('organization'),'\" -token \"',parameters('token'),'\" -Count ',parameters('count'),' -agentUrl \"',parameters('agentUrl'),'\" -runInsideDocker \"',parameters('runInsideDocker'),'\" -FinalSetupScriptUrl \"',parameters('FinalSetupScriptUrl'),'\" -Pool \"',parameters('labelsorpool'),'\" -vmName \"',variables('vmName'),'\"')]"
},
"protectedSettings": {}
}
}
],
"outputs": {
}
}