Files
azuredatastudio/extensions/azurehybridtoolkit/notebooks/hybridbook/content/provisioning/create-sqldb.ipynb
Christopher C 0108da2a24 Cavonac/params (#14264)
* 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>
2021-02-23 13:36:09 -08:00

292 lines
12 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 Database\n",
"\n",
"## Description\n",
"\n",
"Run this notebook to create a Azure SQL Database in a new Azure SQL Server in the cloud and then configure a server-level firewall rule it. For more information, see [Use PowerShell to create a single database and configure a server-level firewall rule](https://docs.microsoft.com/en-us/azure/azure-sql/database/scripts/create-and-configure-database-powershell).\n",
"\n",
"| Line | Variable | Description | Example |\n",
"| --- | --- | --- | --- |\n",
"| 1 | Subscription | Specify the name or ID of the Azure subscription to create Azure resources in | \"ContosoCorp\\_Infra\" |\n",
"| 2 | ResourceGroup | Choose a name to logically group the Azure resources | \"ContosoBackend\" |\n",
"| 3 | Location | Name of geographic location (See the [Appendices](.\\................\\Program%20Files\\Azure%20Data%20Studio\\resources\\app\\out\\vs\\code\\electron-browser\\Appendices.ipynb) for more information) | \"EastUS2\" |\n",
"| 4 | ServerName | The logical server name has to be unique in the system | \"contoso-srv1\" |\n",
"| 5 | AdminLogin | SQL admin login to create | \"SqlAdmin\" |\n",
"| 6 | Password | Temporary password to use (change in the portal for greater security) | \"Temp123\" |\n",
"| 7 | StartIp | Starting IP to begin the IP firewall rule | \"0.0.0.0\" for everyone |\n",
"| 8 | EndIp | Ending IP to end the IP firewall rule | \"0.0.0.0\" for everyone |\n",
"| 9 | DatabaseName | The sample database name | \"ContosoDb1\" |\n",
"| 10 | DbEdition | Database edition. Allowed values include: _Basic_, _Standard_, _Premium_, _GeneralPurpose_, _BusinessCritical_, _Hyperscale_ | GeneralPurpose |\n",
"| 11 | DbCores | Integer for number of vcores to utilize | 2 |\n",
"| 12 | DbComputeGen | The compute generation component for vcores. Allowed values include: _Gen4_, _Gen5_. | Gen5 |\n",
"| 13 | DbMinCapacity | Minimum capacity of vcores to utilize, integer only | 2 |"
],
"metadata": {
"azdata_cell_guid": "6af59d69-ade7-480a-b33e-52a86fe5bfd3"
}
},
{
"cell_type": "code",
"source": [
"$Subscription = \"\"\r\n",
"$ResourceGroup = \"\"\r\n",
"$Location = \"\"\r\n",
"$ServerName = \"\"\r\n",
"$AdminLogin = \"\"\r\n",
"$Password = \"\"\r\n",
"$StartIp = \"\"\r\n",
"$EndIp = \"\"\r\n",
"$DatabaseName = \"\"\r\n",
"$DbEdition = \"\"\r\n",
"$DbCores = \"\"\r\n",
"$DbComputeGen = \"\"\r\n",
"$DbMinCapacity= = \"\""
],
"metadata": {
"azdata_cell_guid": "c5c06fd6-8e47-4abb-808a-edc8b1c2d690",
"tags": [
"parameters"
]
},
"outputs": [],
"execution_count": null
},
{
"cell_type": "markdown",
"source": [
"## Notebook Steps\r\n",
"\r\n",
"Steps of this procedure include:\r\n",
"1. Connect to Azure subscription\r\n",
"1. Provision resource group for SQL Managed Instance\r\n",
"2. Create Sql Server\r\n",
"3. Provision firewall rules to allow access\r\n",
"4. Create Sql Database"
],
"metadata": {
"azdata_cell_guid": "d5346c50-c03b-4e3a-983f-7b4b22c78319"
}
},
{
"cell_type": "markdown",
"source": [
"### Connect to Azure\r\n",
"Prompt for Azure account credentials in a dialog window outside of ADS."
],
"metadata": {
"azdata_cell_guid": "e34334a7-0d55-4c18-8c0a-1c4a673629cd"
}
},
{
"cell_type": "code",
"source": [
"Connect-AzAccount"
],
"metadata": {
"azdata_cell_guid": "96800b54-48a8-463b-886c-3d0e96f29765"
},
"outputs": [],
"execution_count": null
},
{
"cell_type": "markdown",
"source": [
"### Get Subscription\r\n",
"If a subscription is not specified, open a dialog with list of subscriptions. Selecting one will set that subscription for rest of the notebook."
],
"metadata": {
"azdata_cell_guid": "ed6b781d-ce7e-4b51-a7ec-1eeeb2032c73"
}
},
{
"cell_type": "code",
"source": [
"if (!$Subscription)\r\n",
"{\r\n",
" $Subscription = Get-AzSubscription | Out-GridView -PassThru\r\n",
"}\r\n",
"\r\n",
"Set-AzContext -SubscriptionName $Subscription"
],
"metadata": {
"azdata_cell_guid": "17b57956-98cf-44de-9ab5-348469ddabf4"
},
"outputs": [],
"execution_count": null
},
{
"cell_type": "markdown",
"source": [
"### Resource Group Provisioning\n",
"\n",
"If the specified Azure Resource Group cannot be found, _New-AzResourceGroup_ will create new resource group in the given subscription."
],
"metadata": {
"azdata_cell_guid": "3ecc2a29-fb77-4f7f-8901-e9c5c71ce1a2"
}
},
{
"cell_type": "code",
"source": [
"$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. Creating...\"\r\n",
" $rg = New-AzResourceGroup -Name $ResourceGroup -Location $Location\r\n",
"}\r\n",
"\r\n",
"Write-Output \"Using Resource Group:\"\r\n",
"$rg | Format-Table"
],
"metadata": {
"azdata_cell_guid": "4837690a-2204-49ab-8a19-414a8ce782b6"
},
"outputs": [],
"execution_count": null
},
{
"cell_type": "markdown",
"source": [
"### Create SQL Server\n",
"\n",
"_New-AzSqlServer_ will create an Azure Sql Server instance to logically group databases in."
],
"metadata": {
"azdata_cell_guid": "2d951526-40dc-49cc-8668-c393eaf58000"
}
},
{
"cell_type": "code",
"source": [
"Write-Output \"Creating SqlServer with name $ServerName\"\r\n",
"New-AzSqlServer -ResourceGroupName $ResourceGroup `\r\n",
" -ServerName $ServerName `\r\n",
" -Location $Location `\r\n",
" -SqlAdministratorCredentials $(New-Object -TypeName System.Management.Automation.PSCredential `\r\n",
" -ArgumentList $AdminLogin, $(ConvertTo-SecureString -String $Password -AsPlainText -Force))"
],
"metadata": {
"azdata_cell_guid": "c45757ac-6a58-468d-a04c-04504f8a2e0e"
},
"outputs": [],
"execution_count": null
},
{
"cell_type": "markdown",
"source": [
"### Create a Server Firewall Rule\n",
"\n",
"_New-AzSqlServerFirewallRule_ creates a new firewall rule for the new SQL Server that allows a range of specified IPs."
],
"metadata": {
"azdata_cell_guid": "ba895abf-3176-48b5-9e49-a060b3f74370"
}
},
{
"cell_type": "code",
"source": [
"Write-Output \"Configuring firewall for Sql Server\"\r\n",
"New-AzSqlServerFirewallRule -ResourceGroupName $ResourceGroup `\r\n",
" -ServerName $ServerName `\r\n",
" -FirewallRuleName \"AllowedIPs\" -StartIpAddress $StartIp -EndIpAddress $EndIp"
],
"metadata": {
"azdata_cell_guid": "ceae5670-292f-4c45-9c10-4ac85baf2d07"
},
"outputs": [],
"execution_count": null
},
{
"cell_type": "markdown",
"source": [
"### Create SQL Database\r\n",
"_New-AzSqlDatabase_ command will create a new database in the server."
],
"metadata": {
"azdata_cell_guid": "b460ca8f-65a7-4d6c-94b7-6d7dd9655fad"
}
},
{
"cell_type": "code",
"source": [
"New-AzSqlDatabase -ResourceGroupName $ResourceGroup `\r\n",
" -ServerName $ServerName `\r\n",
" -DatabaseName $DatabaseName `\r\n",
" -Edition $DbEdition `\r\n",
" -VCore $DbCores `\r\n",
" -ComputeGeneration $DbComputeGen `\r\n",
" -MinimumCapacity $DbMinCapacity"
],
"metadata": {
"azdata_cell_guid": "dc3b2f6f-83ac-4a4d-9d81-2f534e90913e"
},
"outputs": [],
"execution_count": null
},
{
"cell_type": "markdown",
"source": [
"### Get Database Details\n",
"\n",
"_Get-AzSqlDatabase_ command gets database details on the server specified."
],
"metadata": {
"azdata_cell_guid": "0b35ed4f-1786-4102-a09a-a6a360fd20f2"
}
},
{
"cell_type": "code",
"source": [
"Get-AzSqlDatabase -ResourceGroupName $ResourceGroup -ServerName $ServerName -DatabaseName $DatabaseName"
],
"metadata": {
"azdata_cell_guid": "5001bf24-5f3f-434e-abf6-a5c21af4aa32"
},
"outputs": [],
"execution_count": null
},
{
"cell_type": "markdown",
"source": [
"## Next Steps\r\n",
"\r\n",
"### Update SQL Server Password\r\n",
"Do not forget to open the <a href=\"https://portal.azure.com\">Azure portal</a> to the specified Resource Group in an external browser and change the new server's password. It is not recommended to keep the database password used in this notebook because it stores results as plain text. \r\n",
"\r\n",
"### More Automation\r\n",
"Use ADS Notebooks to write custom scripts for:\r\n",
"* Commonly used Extract, Transform, Load operations\r\n",
"* Data migration and validation\r\n",
"* Storage backup\r\n",
"* Data integration\r\n",
"\r\n",
"### Related Notebooks\r\n",
"For existing database owners, Migrate a database to Azure SQLDB <a href=\"..\\offline-migration\\db-to-SQLDB.ipynb\">using this notebook</a>. "
],
"metadata": {
"azdata_cell_guid": "d8b88393-baba-428d-b136-7125be6d5630"
}
}
]
}