Skip to content

ARM Script to Create SQL Resources with Approved Naming Convention and Tags #156

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

nataliagourova
Copy link
Contributor

@nataliagourova nataliagourova commented Feb 14, 2021

Purpose

This script creates a sql server and an empty sql db on Azure, based on user's inputs.

To test

Download the code, navigate to the .Automation/SQL folder and run the following command in Powershell with appropriate inputs:
.\azureDeploy.ps1 -tenantId <retrieveFromTheCohortsKeyVault> -subscriptionId <retrieveFromTheCohortsKeyVault> -applicationId <retrieve'automation-sp-appid'fromKeyVault/orYourAzurelogin> -secret <retrieve'automation-sp-appsecret'from KeyVault/orYourAzurePassword> -resourceGroupName testnsc-rg-dev-usw2-thursday -administratorLogin testnsc-admin-usw2-thursday -administratorLoginPassword Password123A$!@-location westus2 -serverName testnsc-sqlsrv-dev-usw2-test-thursday -sqlDBName testnsc-sqldb-dev-usw2-thursday -createdBy <yourName> -creatorsEmail <yourEmail>

You can choose to create a new resource group (rg), or point to the existing rg. Creation of the resource will not overwrite the resources already in the rg. Please delete all resources after testing.
It does take a while to create the server and db, you may need to give the script good 5mins to run.
When the script is done running, check the resource group and observe the server and db resources created.

To create an operational db, when a templateDB is available (in this case, nsc-sqldb-dev-usw2-thursday) in one of the Azure resource groups, this simple script may be run in PowerShell to create a brand new db and copy contents of the existing templateDB to a brand new db the script will create. Note: the script does not work for population of existing empty db resources:

$sourceResourceGroupName = "nsc-rg-dev-usw2-thursday”   
$targetResourceGroupname = "testnsc-rg-dev-usw2-thursday”
$sourceServerName = "nsc-sqlsrv-dev-usw2-thursday"
$targetServerName = "testnsc-sqlsrv-dev-usw2-thursday"
$targetDatabaseName = <"Any-new-name">
$sourceDatabaseName = "nsc-sqldb-dev-usw2-thursday"

New-AzSqlDatabaseCopy -ResourceGroupName $sourceResourceGroupName -ServerName $sourceServerName -DatabaseName $sourceDatabaseName -CopyResourceGroupName $targetResourceGroupname -CopyServerName $targetServerName -CopyDatabaseName $targetDatabaseName
DATE ACTIVITY TIME
2/09 Review ARM documentation on Microsoft's site 2 hr
2/11 Created issue, reviewed Sprint 1 & Sprint 3 code 2 hr
2/12 The source code from Sprint1 merged, resolved conflicts to create Sprint3 PR 3hr
2/13 Database population research and deployment 5hr
2/14 Update per reviewers comments 2hr
Total 13 hrs

@nataliagourova nataliagourova added task New task, feature or request team1 Issues for Practicum Team 1 labels Feb 14, 2021
@nataliagourova nataliagourova added this to the Sprint 03 milestone Feb 14, 2021
@nataliagourova nataliagourova self-assigned this Feb 14, 2021
Copy link
Collaborator

@unicornsleuth unicornsleuth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made a couple comments about the db name and the server name
I also think you should rename the files so that the folder is sql (lowercase) and the files are something like create_sql_server and sql_server_params or something similarly descriptive
Also, instead of using your personal username and password, you should be using the Service Principal applicationId and secret, also in the key vault.

Copy link
Contributor

@theKunte theKunte left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice update! Good work! I see you added the tags into your script and parametrized it! I removed my tags again and just added them in azure after running the script. I might add these into my ARM template later ;)

@@ -1,19 +1,23 @@
# Creates resource group and Azure SQL logical server

param(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nicely organized param!

Copy link
Contributor

@jak-ashuraliev jak-ashuraliev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall, looks good. Cleverly imported Login module, clean params, good and simple validations. Good work, Natalia!

@nataliagourova nataliagourova merged commit da9817b into North-Seattle-College:development Feb 17, 2021
@nataliagourova nataliagourova deleted the thirdSprint branch February 17, 2021 02:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
task New task, feature or request team1 Issues for Practicum Team 1
Projects
None yet
5 participants