mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-11 02:32:35 -05:00
* visual consistent added variable table * typo * update variables and code * variable descriptions * typos * typo * added next steps * identifying param cells * updates to readme and removing orphaned notebooks Co-authored-by: Alex Ma <alma1@microsoft.com>
347 lines
14 KiB
Plaintext
347 lines
14 KiB
Plaintext
{
|
|
"metadata": {
|
|
"kernelspec": {
|
|
"name": "powershell",
|
|
"display_name": "PowerShell",
|
|
"language": "powershell"
|
|
},
|
|
"language_info": {
|
|
"name": "powershell",
|
|
"codemirror_mode": "shell",
|
|
"mimetype": "text/x-sh",
|
|
"file_extension": ".ps1"
|
|
}
|
|
},
|
|
"nbformat_minor": 2,
|
|
"nbformat": 4,
|
|
"cells": [
|
|
{
|
|
"cell_type": "markdown",
|
|
"source": [
|
|
"# Create Azure SQL Virtual Machine\n",
|
|
"\n",
|
|
"## Description\n",
|
|
"\n",
|
|
"For more information about other Azure PowerShell options for creating SQL VMs, see the [Provisioning guide for SQL Server VMs with Azure PowerShell](https://docs.microsoft.com/en-us/azure/virtual-machines/windows/sql/virtual-machines-windows-ps-sql-create). See also [Quickstart guide](https://docs.microsoft.com/en-us/azure/virtual-machines/windows/sql/quickstart-sql-vm-create-powershell) to creating a SQL Server VM with Azure PowerShell.\n",
|
|
"\n",
|
|
"Steps of this procedure include:\n",
|
|
"\n",
|
|
"1. Define notebook variables\n",
|
|
"2. Connect to Azure subscription\n",
|
|
"3. Provision resource group for SQL VM migration\n",
|
|
"4. Create a storage account\n",
|
|
"5. Configure Network Settings\n",
|
|
"6. Provision SQL VM\n",
|
|
"7. Configure SQL VM IaaS agent"
|
|
],
|
|
"metadata": {
|
|
"azdata_cell_guid": "e479b550-d6bd-49c5-965a-34a7d1d16412"
|
|
}
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"source": [
|
|
"## Define Notebook Variables"
|
|
],
|
|
"metadata": {
|
|
"azdata_cell_guid": "37db2e50-dcde-4dd5-820c-7dc11212f1eb"
|
|
}
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"source": [
|
|
"# Resource Group \r\n",
|
|
"$Subscription = \"\" # Leave blank to open a dialog to get Azure Subscription, or explicitly specify\r\n",
|
|
"$ResourceGroup = \"\" # Name of the resource group to create in the current subscription\r\n",
|
|
"$Location = \"\" # see Appendix for a list of location settings\r\n",
|
|
"\r\n",
|
|
"# Compute\r\n",
|
|
"$VMName = \"\" # VM to create\r\n",
|
|
"$PublisherName = \"\" # Name of Publisher, Default would be 'MicrosoftSQLServer'\r\n",
|
|
"$Version = \"\" # Version of VM, Default would be 'latest'\r\n",
|
|
"\r\n",
|
|
"# Storage\r\n",
|
|
"$StorageAccountName = $ResourceGroup + \"_storage\"\r\n",
|
|
"$StorageSKU = \"\" # Choose your storage SKU (see appendix)\r\n",
|
|
"$StorageName = \"sqlstorage\" + (Get-Random -Minimum 1 -Maximum 100)\r\n",
|
|
"\r\n",
|
|
"# VM Password\r\n",
|
|
"$secureVMPassword = \"\" # Create the password for VM."
|
|
],
|
|
"metadata": {
|
|
"azdata_cell_guid": "b9aff9cc-a3af-41cb-a2a5-35f36b2bcc55",
|
|
"tags": [
|
|
"parameters"
|
|
]
|
|
},
|
|
"outputs": [],
|
|
"execution_count": null
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"source": [
|
|
"## Get Subscription\n",
|
|
"\n",
|
|
"Open a dialog box with a list of subscriptions, if one isn't specified. Selecting one will set that subscription in the Az CLI context for rest of the notebook."
|
|
],
|
|
"metadata": {
|
|
"azdata_cell_guid": "b58f1048-3e9d-4888-bda0-4d0443a11c97"
|
|
}
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"source": [
|
|
"if (!$Subscription)\r\n",
|
|
"{\r\n",
|
|
" $Subscription = Get-AzSubscription | Out-GridView -PassThru\r\n",
|
|
"} \r\n",
|
|
"Set-AzContext -SubscriptionName $Subscription\r\n",
|
|
"Connect-AzAccount -Subscription $Subscription"
|
|
],
|
|
"metadata": {
|
|
"azdata_cell_guid": "0cc44e68-3810-46f4-b29c-e6ad4321e384"
|
|
},
|
|
"outputs": [],
|
|
"execution_count": null
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"source": [
|
|
"## Create Azure Resource Group"
|
|
],
|
|
"metadata": {
|
|
"azdata_cell_guid": "c17dd324-5c55-484f-8a25-2a5a7e43633e"
|
|
}
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"source": [
|
|
"# Create Azure resource group, if necessary\r\n",
|
|
"$rg = Get-AzResourceGroup | Where ResourceGroupName -eq $ResourceGroup\r\n",
|
|
"\r\n",
|
|
"if (!$rg)\r\n",
|
|
"{\r\n",
|
|
" # Need to create a new resource group\r\n",
|
|
" Write-Output \"Resource Group '$ResourceGroup' does not exist\"\r\n",
|
|
" $rg = New-AzResourceGroup -Name $ResourceGroup -Location $Location\r\n",
|
|
"}"
|
|
],
|
|
"metadata": {
|
|
"azdata_cell_guid": "2c37ef31-5f47-4918-a2b3-05e11aab28da"
|
|
},
|
|
"outputs": [],
|
|
"execution_count": null
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"source": [
|
|
"## Create a storage account\r\n",
|
|
"VMs require storage resources for OS, SQL data and logs. Create a new storage account as a place for it."
|
|
],
|
|
"metadata": {
|
|
"azdata_cell_guid": "11b78695-40d3-45d7-8e3c-32d086ddf94a"
|
|
}
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"source": [
|
|
"$StorageAccount = Get-AzStorageAccount | Where StorageAccountName -eq $StorageAccountName\r\n",
|
|
"\r\n",
|
|
"if (!$StorageAccount)\r\n",
|
|
"{\r\n",
|
|
" Write-Output \"Storage Account $StorageName does not exist. Creating...\"\r\n",
|
|
" $StorageAccount = New-AzStorageAccount -ResourceGroupName $ResourceGroup -Name $StorageName -SkuName $StorageSku -Kind \"Storage\" -Location $Location\r\n",
|
|
"}"
|
|
],
|
|
"metadata": {
|
|
"azdata_cell_guid": "f992bf91-a84a-40c2-813b-cb778907370d",
|
|
"tags": []
|
|
},
|
|
"outputs": [],
|
|
"execution_count": null
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"source": [
|
|
"## Configure network settings\r\n",
|
|
"Create a virtual network, subnet, and a public IP address. These resources are used to provide network connectivity to the virtual machine and connect it to the internet."
|
|
],
|
|
"metadata": {
|
|
"azdata_cell_guid": "202634eb-7edf-4ff4-8486-fffbda45dbc8"
|
|
}
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"source": [
|
|
"$SubnetName = $ResourceGroup + \"subnet\"\r\n",
|
|
"$VnetName = $ResourceGroup + \"vnet\"\r\n",
|
|
"$PipName = $ResourceGroup + $(Get-Random)\r\n",
|
|
"\r\n",
|
|
"# Create a subnet configuration\r\n",
|
|
"$SubnetConfig = New-AzVirtualNetworkSubnetConfig -Name $SubnetName -AddressPrefix 192.168.1.0/24\r\n",
|
|
"\r\n",
|
|
"# Create a virtual network\r\n",
|
|
"$Vnet = New-AzVirtualNetwork -ResourceGroupName $ResourceGroup -Location $Location `\r\n",
|
|
" -Name $VnetName -AddressPrefix 192.168.0.0/16 -Subnet $SubnetConfig\r\n",
|
|
"\r\n",
|
|
"# Create a public IP address and specify a DNS name\r\n",
|
|
"$Pip = New-AzPublicIpAddress -ResourceGroupName $ResourceGroup -Location $Location `\r\n",
|
|
" -AllocationMethod Static -IdleTimeoutInMinutes 4 -Name $PipName"
|
|
],
|
|
"metadata": {
|
|
"azdata_cell_guid": "af88cdae-1a62-4990-9231-094481c9337d"
|
|
},
|
|
"outputs": [],
|
|
"execution_count": null
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"source": [
|
|
"2. Create a network security group. Configure rules to allow remote desktop (RDP) and SQL Server connections."
|
|
],
|
|
"metadata": {
|
|
"azdata_cell_guid": "3b25e16e-b150-4a2e-80dc-66f2d18b43fb"
|
|
}
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"source": [
|
|
"# Rule to allow remote desktop (RDP)\r\n",
|
|
"$NsgRuleRDP = New-AzNetworkSecurityRuleConfig -Name \"RDPRule\" -Protocol Tcp `\r\n",
|
|
" -Direction Inbound -Priority 1000 -SourceAddressPrefix * -SourcePortRange * `\r\n",
|
|
" -DestinationAddressPrefix * -DestinationPortRange 3389 -Access Allow\r\n",
|
|
"\r\n",
|
|
"#Rule to allow SQL Server connections on port 1433\r\n",
|
|
"$NsgRuleSQL = New-AzNetworkSecurityRuleConfig -Name \"MSSQLRule\" -Protocol Tcp `\r\n",
|
|
" -Direction Inbound -Priority 1001 -SourceAddressPrefix * -SourcePortRange * `\r\n",
|
|
" -DestinationAddressPrefix * -DestinationPortRange 1433 -Access Allow\r\n",
|
|
"\r\n",
|
|
"# Create the network security group\r\n",
|
|
"$NsgName = $ResourceGroup + \"nsg\"\r\n",
|
|
"$Nsg = New-AzNetworkSecurityGroup -ResourceGroupName $ResourceGroup `\r\n",
|
|
" -Location $Location -Name $NsgName `\r\n",
|
|
" -SecurityRules $NsgRuleRDP,$NsgRuleSQL"
|
|
],
|
|
"metadata": {
|
|
"azdata_cell_guid": "debe940d-0d0f-4540-be5b-4d6495d338e1"
|
|
},
|
|
"outputs": [],
|
|
"execution_count": null
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"source": [
|
|
"3. Create the network interface."
|
|
],
|
|
"metadata": {
|
|
"azdata_cell_guid": "d44de03c-d4f2-48ef-8a60-507069d6c08e"
|
|
}
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"source": [
|
|
"$InterfaceName = $ResourceGroup + \"int\"\r\n",
|
|
"$Interface = New-AzNetworkInterface -Name $InterfaceName `\r\n",
|
|
" -ResourceGroupName $ResourceGroup -Location $Location `\r\n",
|
|
" -SubnetId $VNet.Subnets[0].Id -PublicIpAddressId $Pip.Id `\r\n",
|
|
" -NetworkSecurityGroupId $Nsg.Id"
|
|
],
|
|
"metadata": {
|
|
"azdata_cell_guid": "6dbb3ea0-b52f-4ed2-bd24-59096d134e88"
|
|
},
|
|
"outputs": [],
|
|
"execution_count": null
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"source": [
|
|
"## Create the SQL VM\r\n",
|
|
"1. Define your credentials to sign in to the VM. The username is \"azureadmin\". Make sure you change <password> before running the command."
|
|
],
|
|
"metadata": {
|
|
"azdata_cell_guid": "b25dca9e-269b-45db-8cdf-efa53e2213d2"
|
|
}
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"source": [
|
|
"# Define a credential object\r\n",
|
|
"$SecurePassword = ConvertTo-SecureString $secureVMPassword `\r\n",
|
|
" -AsPlainText -Force\r\n",
|
|
"$Cred = New-Object System.Management.Automation.PSCredential (\"azureadmin\", $securePassword)"
|
|
],
|
|
"metadata": {
|
|
"azdata_cell_guid": "40d0c992-860a-4b83-8104-16ec7e6e7983"
|
|
},
|
|
"outputs": [],
|
|
"execution_count": null
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"source": [
|
|
"2. Create a virtual machine configuration object and then create the VM. The following command creates a SQL Server 2017 Developer Edition VM on Windows Server 2016."
|
|
],
|
|
"metadata": {
|
|
"azdata_cell_guid": "2038172f-3f29-499c-ad68-88a1d96ead1f"
|
|
}
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"source": [
|
|
"# Create a virtual machine configuration\r\n",
|
|
"\r\n",
|
|
"$VMConfig = New-AzVMConfig -VMName $VMName -VMSize Standard_DS13_V2 |\r\n",
|
|
" Set-AzVMOperatingSystem -Windows -ComputerName $VMName -Credential $Cred -ProvisionVMAgent -EnableAutoUpdate |\r\n",
|
|
" Set-AzVMSourceImage -PublisherName \"MicrosoftSQLServer\" -Offer \"SQL2017-WS2016\" -Skus \"SQLDEV\" -Version \"latest\" |\r\n",
|
|
" Add-AzVMNetworkInterface -Id $Interface.Id"
|
|
],
|
|
"metadata": {
|
|
"azdata_cell_guid": "6625d7b2-6c97-432e-b5f5-be4ca93017ae"
|
|
},
|
|
"outputs": [],
|
|
"execution_count": null
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"source": [
|
|
"## Create Virtual Machine"
|
|
],
|
|
"metadata": {
|
|
"azdata_cell_guid": "c42ec570-331a-46ea-b358-b05e47320967"
|
|
}
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"source": [
|
|
"# Create the VM\r\n",
|
|
"New-AzVM -ResourceGroupName $ResourceGroup -Location $Location -VM $VMConfig"
|
|
],
|
|
"metadata": {
|
|
"azdata_cell_guid": "05fa1f3d-94e1-480f-ad20-d3006bafc6ac"
|
|
},
|
|
"outputs": [],
|
|
"execution_count": null
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"source": [
|
|
"## Install the SQL IaaS Agent\r\n",
|
|
"To get portal integration and SQL VM features, you must install the SQL Server IaaS Agent Extension. To install the agent on the new VM, run the following command after the VM is created."
|
|
],
|
|
"metadata": {
|
|
"azdata_cell_guid": "ef07b3d1-3e2d-45f0-b9d3-fb00be2a7da9"
|
|
}
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"source": [
|
|
"Set-AzVMSqlServerExtension -ResourceGroupName $ResourceGroup -VMName $VMName -name \"SQLIaasExtension\" -version \"2.0\" -Location $Location"
|
|
],
|
|
"metadata": {
|
|
"azdata_cell_guid": "bb3b5436-c34b-44b3-b631-ea60c9dcf16a"
|
|
},
|
|
"outputs": [],
|
|
"execution_count": null
|
|
}
|
|
]
|
|
} |