Created
March 13, 2020 17:34
-
-
Save alexjmoore/d2e86d9d918579869e9a1e8bacb8d49d to your computer and use it in GitHub Desktop.
101-vm-simple-linux extended to add DNS record to existing zone
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#", | |
"contentVersion": "1.0.0.0", | |
"parameters": { | |
"vmName": { | |
"type": "string", | |
"defaultValue": "simpleLinuxVM", | |
"metadata": { | |
"description": "The name of you Virtual Machine." | |
} | |
}, | |
"adminUsername": { | |
"type": "string", | |
"metadata": { | |
"description": "Username for the Virtual Machine." | |
} | |
}, | |
"authenticationType": { | |
"type": "string", | |
"defaultValue": "password", | |
"allowedValues": [ | |
"sshPublicKey", | |
"password" | |
], | |
"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." | |
} | |
}, | |
"dnsLabelPrefix": { | |
"type": "string", | |
"defaultValue": "[toLower(concat('simplelinuxvm-', uniqueString(resourceGroup().id)))]", | |
"metadata": { | |
"description": "Unique DNS Name for the Public IP used to access the Virtual Machine." | |
} | |
}, | |
"ubuntuOSVersion": { | |
"type": "string", | |
"defaultValue": "18.04-LTS", | |
"allowedValues": [ | |
"12.04.5-LTS", | |
"14.04.5-LTS", | |
"16.04.0-LTS", | |
"18.04-LTS" | |
], | |
"metadata": { | |
"description": "The Ubuntu version for the VM. This will pick a fully patched image of this given Ubuntu version." | |
} | |
}, | |
"location": { | |
"type": "string", | |
"defaultValue": "[resourceGroup().location]", | |
"metadata": { | |
"description": "Location for all resources." | |
} | |
}, | |
"VmSize": { | |
"type": "string", | |
"defaultValue": "Standard_B2s", | |
"metadata": { | |
"description": "The size of the VM" | |
} | |
}, | |
"virtualNetworkName": { | |
"type": "string", | |
"defaultValue": "vNet", | |
"metadata": { | |
"description": "Name of the VNET" | |
} | |
}, | |
"subnetName": { | |
"type": "string", | |
"defaultValue": "Subnet", | |
"metadata": { | |
"description": "Name of the subnet in the virtual network" | |
} | |
}, | |
"networkSecurityGroupName": { | |
"type": "string", | |
"defaultValue": "SecGroupNet", | |
"metadata": { | |
"description": "Name of the Network Security Group" | |
} | |
}, | |
"zoneName": { | |
"type": "string", | |
"metadata": { | |
"description": "Name of the Azure Public DNS Zone" | |
} | |
}, | |
"recordName": { | |
"type": "string", | |
"metadata": { | |
"description": "Name of the Azure Public DNS A record name" | |
} | |
}, | |
"dnsResourceGroup": { | |
"type": "string", | |
"metadata": { | |
"description": "Name of the Resource Group where the DNS Zone resides" | |
} | |
} | |
}, | |
"variables": { | |
"publicIpAddressName": "[concat(parameters('vmName'), 'PublicIP' )]", | |
"networkInterfaceName": "[concat(parameters('vmName'),'NetInt')]", | |
"subnetRef": "[resourceId('Microsoft.Network/virtualNetworks/subnets', parameters('virtualNetworkName'), parameters('subnetName'))]", | |
"osDiskType": "Standard_LRS", | |
"subnetAddressPrefix": "10.1.0.0/24", | |
"addressPrefix": "10.1.0.0/16", | |
"linuxConfiguration": { | |
"disablePasswordAuthentication": true, | |
"ssh": { | |
"publicKeys": [ | |
{ | |
"path": "[concat('/home/', parameters('adminUsername'), '/.ssh/authorized_keys')]", | |
"keyData": "[parameters('adminPasswordOrKey')]" | |
} | |
] | |
} | |
} | |
}, | |
"resources": [ | |
{ | |
"type": "Microsoft.Network/networkInterfaces", | |
"apiVersion": "2018-10-01", | |
"name": "[variables('networkInterfaceName')]", | |
"location": "[parameters('location')]", | |
"dependsOn": [ | |
"[resourceId('Microsoft.Network/networkSecurityGroups/', parameters('networkSecurityGroupName'))]", | |
"[resourceId('Microsoft.Network/virtualNetworks/', parameters('virtualNetworkName'))]", | |
"[resourceId('Microsoft.Network/publicIpAddresses/', variables('publicIpAddressName'))]" | |
], | |
"properties": { | |
"ipConfigurations": [ | |
{ | |
"name": "ipconfig1", | |
"properties": { | |
"subnet": { | |
"id": "[variables('subnetRef')]" | |
}, | |
"privateIPAllocationMethod": "Dynamic", | |
"publicIpAddress": { | |
"id": "[resourceId('Microsoft.Network/publicIPAddresses',variables('publicIPAddressName'))]" | |
} | |
} | |
} | |
], | |
"networkSecurityGroup": { | |
"id": "[resourceId('Microsoft.Network/networkSecurityGroups',parameters('networkSecurityGroupName'))]" | |
} | |
} | |
}, | |
{ | |
"type": "Microsoft.Network/networkSecurityGroups", | |
"apiVersion": "2019-02-01", | |
"name": "[parameters('networkSecurityGroupName')]", | |
"location": "[parameters('location')]", | |
"properties": { | |
"securityRules": [ | |
{ | |
"name": "SSH", | |
"properties": { | |
"priority": 1000, | |
"protocol": "TCP", | |
"access": "Allow", | |
"direction": "Inbound", | |
"sourceAddressPrefix": "*", | |
"sourcePortRange": "*", | |
"destinationAddressPrefix": "*", | |
"destinationPortRange": "22" | |
} | |
} | |
] | |
} | |
}, | |
{ | |
"type": "Microsoft.Network/virtualNetworks", | |
"apiVersion": "2019-04-01", | |
"name": "[parameters('virtualNetworkName')]", | |
"location": "[parameters('location')]", | |
"properties": { | |
"addressSpace": { | |
"addressPrefixes": [ | |
"[variables('addressPrefix')]" | |
] | |
}, | |
"subnets": [ | |
{ | |
"name": "[parameters('subnetName')]", | |
"properties": { | |
"addressPrefix": "[variables('subnetAddressPrefix')]", | |
"privateEndpointNetworkPolicies": "Enabled", | |
"privateLinkServiceNetworkPolicies": "Enabled" | |
} | |
} | |
] | |
} | |
}, | |
{ | |
"type": "Microsoft.Network/publicIpAddresses", | |
"apiVersion": "2019-02-01", | |
"name": "[variables('publicIpAddressName')]", | |
"location": "[parameters('location')]", | |
"properties": { | |
"publicIpAllocationMethod": "Dynamic", | |
"publicIPAddressVersion": "IPv4", | |
"dnsSettings": { | |
"domainNameLabel": "[parameters('dnsLabelPrefix')]" | |
}, | |
"idleTimeoutInMinutes": 4 | |
}, | |
"sku": { | |
"name": "Basic", | |
"tier": "Regional" | |
} | |
}, | |
{ | |
"type": "Microsoft.Compute/virtualMachines", | |
"apiVersion": "2019-03-01", | |
"name": "[parameters('vmName')]", | |
"location": "[parameters('location')]", | |
"dependsOn": [ | |
"[resourceId('Microsoft.Network/networkInterfaces/', variables('networkInterfaceName'))]" | |
], | |
"properties": { | |
"hardwareProfile": { | |
"vmSize": "[parameters('VmSize')]" | |
}, | |
"storageProfile": { | |
"osDisk": { | |
"createOption": "fromImage", | |
"managedDisk": { | |
"storageAccountType": "[variables('osDiskType')]" | |
} | |
}, | |
"imageReference": { | |
"publisher": "Canonical", | |
"offer": "UbuntuServer", | |
"sku": "[parameters('ubuntuOSVersion')]", | |
"version": "latest" | |
} | |
}, | |
"networkProfile": { | |
"networkInterfaces": [ | |
{ | |
"id": "[resourceId('Microsoft.Network/networkInterfaces', variables('networkInterfaceName'))]" | |
} | |
] | |
}, | |
"osProfile": { | |
"computerName": "[parameters('vmName')]", | |
"adminUsername": "[parameters('adminUsername')]", | |
"adminPassword": "[parameters('adminPasswordOrKey')]", | |
"linuxConfiguration": "[if(equals(parameters('authenticationType'), 'password'), json('null'), variables('linuxConfiguration'))]" | |
} | |
} | |
}, | |
{ | |
"type": "Microsoft.Resources/deployments", | |
"apiVersion": "2017-05-10", | |
"name": "nestedTemplate", | |
"resourceGroup": "[parameters('dnsResourceGroup')]", | |
"dependsOn": [ | |
"[resourceId('Microsoft.Compute/virtualMachines/', parameters('vmName'))]" | |
], | |
"properties": { | |
"mode": "Incremental", | |
"template": { | |
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", | |
"contentVersion": "1.0.0.0", | |
"parameters": {}, | |
"variables": {}, | |
"resources": [ | |
{ | |
"name": "[concat(parameters('zoneName'), '/', parameters('recordName'))]", | |
"type": "Microsoft.Network/dnsZones/A", | |
"apiVersion": "2018-05-01", | |
"properties": { | |
"metadata": {}, | |
"TTL": 300, | |
"ARecords": [ | |
{ | |
"ipv4Address": "[reference(resourceId('Microsoft.Network/networkInterfaces', variables('networkInterfaceName'))).ipConfigurations[0].properties.privateIPAddress]" | |
} | |
] | |
} | |
} | |
] | |
} | |
} | |
} | |
], | |
"outputs": { | |
"adminUsername": { | |
"type": "string", | |
"value": "[parameters('adminUsername')]" | |
}, | |
"hostname": { | |
"type": "string", | |
"value": "[reference(variables('publicIPAddressName')).dnsSettings.fqdn]" | |
}, | |
"sshCommand": { | |
"type": "string", | |
"value": "[concat('ssh ', parameters('adminUsername'), '@', reference(variables('publicIPAddressName')).dnsSettings.fqdn)]" | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment