Skip to content

Commit

Permalink
Merge pull request #1673 from craddm/factor-storage
Browse files Browse the repository at this point in the history
Factor out storage creation from SHM scripts
  • Loading branch information
JimMadge authored Dec 1, 2023
2 parents edd7a9a + f655718 commit 2fc12d7
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ Invoke-Command -ScriptBlock { & "$(Join-Path $PSScriptRoot 'Setup_SHM_Monitoring
Invoke-Command -ScriptBlock { & "$(Join-Path $PSScriptRoot 'Setup_SHM_Firewall.ps1')" -shmId $shmId }


# Setup SHM storage accounts
# --------------------------
Invoke-Command -ScriptBlock { & "$(Join-Path $PSScriptRoot 'Setup_SHM_Storage_Accounts.ps1')" -shmId $shmId }


# Setup SHM domain controllers
# ----------------------------
Invoke-Command -ScriptBlock { & "$(Join-Path $PSScriptRoot 'Setup_SHM_DC.ps1')" -shmId $shmId }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,28 +24,7 @@ Import-Module $PSScriptRoot/../../common/Templates -Force -ErrorAction Stop
$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
}

$storageAccount = Get-AzStorageAccount -ResourceGroupName $config.storage.artifacts.rg -Name $config.storage.artifacts.accountName

# Upload DSC scripts
# ------------------
Expand Down
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

0 comments on commit 2fc12d7

Please sign in to comment.