-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1673 from craddm/factor-storage
Factor out storage creation from SHM scripts
- Loading branch information
Showing
3 changed files
with
46 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
deployment/safe_haven_management_environment/setup/Setup_SHM_Storage_Accounts.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
param( | ||
[Parameter(Mandatory = $true, HelpMessage = "Enter SHM ID (e.g. use 'testa' for Turing Development Safe Haven A)")] | ||
[string]$shmId | ||
) | ||
|
||
Import-Module Az.Accounts -ErrorAction Stop | ||
Import-Module $PSScriptRoot/../../common/AzureResources -Force -ErrorAction Stop | ||
Import-Module $PSScriptRoot/../../common/AzureStorage -Force -ErrorAction Stop | ||
Import-Module $PSScriptRoot/../../common/Configuration -Force -ErrorAction Stop | ||
Import-Module $PSScriptRoot/../../common/Logging -Force -ErrorAction Stop | ||
|
||
# Get config and original context before changing subscription | ||
# ------------------------------------------------------------ | ||
$config = Get-ShmConfig -shmId $shmId | ||
$originalContext = Get-AzContext | ||
$null = Set-AzContext -SubscriptionId $config.subscriptionName -ErrorAction Stop | ||
|
||
# Ensure that boot diagnostics resource group and storage account exist | ||
# --------------------------------------------------------------------- | ||
$null = Deploy-ResourceGroup -Name $config.storage.bootdiagnostics.rg -Location $config.location | ||
$null = Deploy-StorageAccount -Name $config.storage.bootdiagnostics.accountName -ResourceGroupName $config.storage.bootdiagnostics.rg -Location $config.location | ||
|
||
|
||
# Ensure that artifacts resource group and storage account exist | ||
# -------------------------------------------------------------- | ||
$null = Deploy-ResourceGroup -Name $config.storage.artifacts.rg -Location $config.location | ||
$storageAccount = Deploy-StorageAccount -Name $config.storage.artifacts.accountName -ResourceGroupName $config.storage.artifacts.rg -Location $config.location | ||
|
||
|
||
# Create blob storage containers | ||
# ------------------------------ | ||
Add-LogMessage -Level Info "Ensuring that blob storage containers exist..." | ||
foreach ($containerName in $config.storage.artifacts.containers.Values) { | ||
$null = Deploy-StorageContainer -Name $containerName -StorageAccount $storageAccount | ||
$null = Clear-StorageContainer -Name $containerName -StorageAccount $storageAccount | ||
} | ||
|
||
# Switch back to original subscription | ||
# ------------------------------------ | ||
$null = Set-AzContext -Context $originalContext -ErrorAction Stop |