-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Expand file tree
/
Copy pathazure-deploy-01.ps1
More file actions
35 lines (35 loc) · 1.93 KB
/
azure-deploy-01.ps1
File metadata and controls
35 lines (35 loc) · 1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# 1. Deploy database
$adminSqlLogin = "cloudadmin"
$password = Read-Host "Your username is 'cloudadmin'. Please enter a password for your Azure SQL Database server that meets the password requirements"
# Prompt for local ip address
$ipAddress = Read-Host "Disconnect your VPN, open PowerShell on your machine and run '(Invoke-WebRequest -Uri "https://ipinfo.io/ip").Content'. Please enter the value (include periods) next to 'Address': "
# Get resource group and location and random string
$resourceGroupName = "Sandbox resource group name"
$resourceGroup = Get-AzResourceGroup | Where ResourceGroupName -like $resourceGroupName
$uniqueID = Get-Random -Minimum 100000 -Maximum 1000000
$location = $resourceGroup.Location
# The logical server name has to be unique in the system
$serverName = "bus-server$($uniqueID)"
# The sample database name
$databaseName = "bus-db"
# Create a new server with a system wide unique server name
$server = New-AzSqlServer -ResourceGroupName $resourceGroupName `
-ServerName $serverName
-Location $location
-SqlAdministratorCredentials $(New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $adminSqlLogin, $(ConvertTo-SecureString -String $password -AsPlainText -Force))
# Create a server firewall rule that allows access from the specified IP range and all Azure services
$serverFirewallRule = New-AzSqlServerFirewallRule
-ResourceGroupName $resourceGroupName
-ServerName $serverName
-FirewallRuleName "AllowedIPs"
-StartIpAddress $ipAddress -EndIpAddress $ipAddress
$allowAzureIpsRule = New-AzSqlServerFirewallRule
-ResourceGroupName $resourceGroupName
-ServerName $serverName
-AllowAllAzureIPs
# Create a database
$database = New-AzSqlDatabase -ResourceGroupName $resourceGroupName
-ServerName $serverName
-DatabaseName $databaseName
-Edition "GeneralPurpose" -Vcore 4 -ComputeGeneration "Gen5"
-ComputeModel Serverless -MinimumCapacity 0.5