Skip to content

Task7 azurestoragescript #8

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

Dylan-Riley
Copy link
Contributor

Resolves #7

@Dylan-Riley Dylan-Riley added the team2 Issues for Practicum Team 2 label Jan 9, 2021
@Dylan-Riley Dylan-Riley added this to the Sprint 01 milestone Jan 9, 2021
@Dylan-Riley Dylan-Riley self-assigned this Jan 9, 2021
@Dylan-Riley
Copy link
Contributor Author

Dylan-Riley commented Jan 9, 2021

Required:

* Powershell

* Powershell module Az version 0.7 or later:  `Get-InstalledModule -Name "Az"` to check
  
  * See [Introducing the Azure Az PowerShell Module](https://docs.microsoft.com/en-us/powershell/azure/install-Az-ps?view=azps-5.3.0)

Script can be found in [REPO]\Automation\create_Azure_StorageAccount.ps1

Open up a PowerShell window
Sign in to Azure through PowerShell: Connect-AzAccount Follow instructions on screen
In the Powershell window type "&" space and then drag the script file, this should auto fill in the command & "[PATH TO FILE]\create_Azure_StorageAccount.ps1"
Run the command
You will see basic Write-Host output as script runs
Resource Group and Storage Account names are declared as variables in script
Script will check if resource group exists, then create it if it doesn't
Script will check if a Storage Account with that name exists

* If it doesn't exist, script will create a storage account in the above resource group in US West 2 configured for Read-Access geo-redundant storage, using general purpose V2 storage.

* If it does exist print a message saying so

Output of script also saved in a text file create_Azure_StorageAccountlog.log
I'm honestly not sure how .gitignore files are shared amongst pulls, recommend making sure the .log file is ignored.
To run script again and make sure it works open Azure Console and delete either nsc-ad440-winter2021-Th-StorageRG Resource Group or nscad440thsa Storage Account

@1jc
Copy link
Contributor

1jc commented Jan 14, 2021

Looks good reviewed by 1jc Team2. Ready for Pull and Merge.

@1jc
Copy link
Contributor

1jc commented Jan 14, 2021

1jc checked individual coding for task several times 1jc

@1jc 1jc merged commit 2079462 into North-Seattle-College:development Jan 14, 2021
Write-Host "Create Azure Storage Account"

# Name of resource group
$resourceGroup = "nsc-ad440-winter2021-Th-StorageRG"
Copy link
Contributor

Choose a reason for hiding this comment

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

@theanticrumpet Hard coding the name of the resource group is not a group practice. This makes the script inflexible - i.e. once you use it you cannot reuse it again if the resource groups. It is better if you make those at least input parameters for the script.

CC:// @1jc

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was a little hesitant to do what you suggested in slack where I take multiple inputs and combine them into the RG name since that would just lead to a bunch of similarly named but different RGs. Would prompting for the RG name be sufficient?

# Name of resource group
$resourceGroup = "nsc-ad440-winter2021-Th-StorageRG"
# Location for Azure resources
$location = "westus2"
Copy link
Contributor

Choose a reason for hiding this comment

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

@theanticrumpet Same comment as above

CC:// @1jc

# Location for Azure resources
$location = "westus2"
#Name of storage account
$storageAccountName = "nscad440thsa"
Copy link
Contributor

Choose a reason for hiding this comment

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

@theanticrumpet Same comment as above

CC:// @1jc

$storageAccountName = "nscad440thsa"

#Check if the resource group exists
Get-AzResourceGroup -Name $resourceGroup -ErrorVariable noRG -ErrorAction SilentlyContinue
Copy link
Contributor

Choose a reason for hiding this comment

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

@theanticrumpet I do not see a logic to sign into the Azure account. This line will fail if I try to run the script. There should be logic to sign into Azure and select the right tenant and subscription.

CC:// @1jc


#Check if storage account exists
#Returns a CheckNameAvailabilityResult object, use property NameAvailable to get boolean value of if the name is available
$doesntExist = Get-AzStorageAccountNameAvailability -Name $storageAccountName
Copy link
Contributor

Choose a reason for hiding this comment

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

@theanticrumpet I would prefer that you use ARM template to create the storage account instead doing this manually in the script. ARM templates provide additional benefits like for example checking if the resource exist, can be run asynchronously etc.

I would suggest you investigate that option.

CC:// @1jc

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Definitely looks like I've got more reading to do on general Azure + Powershell scripting instead of specific functions

Write-Host "Storage Account $storageAccountName already exists"
}

Read-Host -Prompt "Press enter to continue"
Copy link
Contributor

Choose a reason for hiding this comment

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

This line will block the script for executing without manual interaction. Not a good practice for automation scripts. CI/CD and other automation systems will not be able to use your script.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Wait, do I want to take user input or not? Wouldn't the previous examples of requiring user input (EG: for resource group) also halt? Should I just make the whole thing take command line arguments as well?

Choose a reason for hiding this comment

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

I might be wrong but for those dynamic variables you can use the Key Vault and share them within your team.

andluc21 added a commit that referenced this pull request Jan 29, 2021
created files, updated index.html
farhadbahrehmandhenry pushed a commit that referenced this pull request Jan 30, 2021
NSC repo changes toddy into theKunte fork
Kemet2016 added a commit that referenced this pull request Mar 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
team2 Issues for Practicum Team 2
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Task] Implement script to create an Azure Storage account
4 participants