-
Notifications
You must be signed in to change notification settings - Fork 3
/
Create-CloudClusterPrerequisites.ps1
53 lines (39 loc) · 2 KB
/
Create-CloudClusterPrerequisites.ps1
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#Requires -Version 3.0
#Requires -Module AzureRM.Resources
Param(
[Parameter(Mandatory=$True)]
[string]
$EnvironmentTag,
[Parameter(Mandatory=$True)]
[string]
$MachineSshPublicKey,
[Parameter(Mandatory=$True)]
[pscredential]
$ServicePrincipalCredentials,
[string]
$ResourceGroupLocation = "North Europe"
)
# stop the script on first error
$ErrorActionPreference = 'Stop'
#******************************************************************************
# Dependencies
#******************************************************************************
. "DeviceCache.Infrastructure/Common-Functions.ps1"
#******************************************************************************
# Script body
#******************************************************************************
$resourceGroupName = "ca-devcache-$EnvironmentTag-rg"
CreateResourceGroupIfNotPresent -ResourceGroupName $ResourceGroupName -ResourceGroupLocation $ResourceGroupLocation
Write-Host "Setting up key vault with secrets..."
Write-Host "Creating the vault..."
$automationKeyVaultName = "ca-automation-$EnvironmentTag"
Create-KeyVault -KeyVaultName $automationKeyVaultName -ResourceGroupName $resourceGroupName -ResourceGroupLocation $ResourceGroupLocation
Write-Host "Populating the secrets..."
$automationTemplateFile = [System.IO.Path]::GetFullPath([System.IO.Path]::Combine($PSScriptRoot, "DeviceCache.Infrastructure/AutomationSecrets.json"))
Write-Host "Template located at $automationTemplateFile"
$automationTemplateParameters = New-Object -TypeName Hashtable
$automationTemplateParameters["KeyVaultName"] = $automationKeyVaultName
$automationTemplateParameters["MachineSshPublicKey"] = $MachineSshPublicKey
$automationTemplateParameters["ServicePrincipalId"] = $ServicePrincipalCredentials.UserName
$automationTemplateParameters["ServicePrincipalPassword"] = $ServicePrincipalCredentials.Password
DeployTemplate -ResourceGroupName $resourceGroupName -TemplateFileFullPath $automationTemplateFile -TemplateParameters $automationTemplateParameters