-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathCreate-Infrastructure.ps1
68 lines (49 loc) · 3.2 KB
/
Create-Infrastructure.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#Requires -Version 3.0
#Requires -Module AzureRM.Resources
Param(
[Parameter(Mandatory=$True)]
[string]
$EnvironmentTag,
[string]
$ResourceGroupLocation = "North Europe",
[switch]
$SkipClusterInCloud
)
# 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
$eventHubTemplateFile = [System.IO.Path]::GetFullPath([System.IO.Path]::Combine($PSScriptRoot, "DeviceCache.Infrastructure/EventHub.json"))
$registryTemplateFile = [System.IO.Path]::GetFullPath([System.IO.Path]::Combine($PSScriptRoot, "DeviceCache.Infrastructure/Registry.json"))
$clusterTemplateFile = [System.IO.Path]::GetFullPath([System.IO.Path]::Combine($PSScriptRoot, "DeviceCache.Infrastructure/Cluster.json"))
$keyVaultName = "ca-devcache-$EnvironmentTag"
Create-KeyVault -KeyVaultName $keyVaultName -ResourceGroupName $resourceGroupName -ResourceGroupLocation $ResourceGroupLocation
$eventHubTemplateParameters = New-Object -TypeName Hashtable
$eventHubTemplateParameters["EnvironmentTag"] = $EnvironmentTag
DeployTemplate -ResourceGroupName $resourceGroupName -TemplateFileFullPath $eventHubTemplateFile -TemplateParameters $eventHubTemplateParameters
$registryTemplateParameters = New-Object -TypeName Hashtable
$registryTemplateParameters["EnvironmentTag"] = $EnvironmentTag
DeployTemplate -ResourceGroupName $resourceGroupName -TemplateFileFullPath $registryTemplateFile -TemplateParameters $registryTemplateParameters
if (-not $SkipClusterInCloud) {
$automationKeyVaultName = "ca-automation-$EnvironmentTag"
$automationKeyVault = Get-AzureRmKeyVault -VaultName $automationKeyVaultName -ErrorAction SilentlyContinue
if (-not $automationKeyVault) {
throw "Automation key vault required for the cluster not found. Make sure you run the Create-CloudClusterPrerequisites script first."
}
$clusterManagerId = (Get-AzureKeyVaultSecret -VaultName $automationKeyVaultName -SecretName servicePrincipalId).SecretValueText
$clusterManagerKey = (Get-AzureKeyVaultSecret -VaultName $automationKeyVaultName -SecretName servicePrincipalPassword).SecretValue
$sshPublicKey = (Get-AzureKeyVaultSecret -VaultName $automationKeyVaultName -SecretName machineSshPublicKey).SecretValueText
$clusterTemplateParameters = New-Object -TypeName Hashtable
$clusterTemplateParameters["EnvironmentTag"] = $EnvironmentTag
$clusterTemplateParameters["ManagementPrincipalId"] = $clusterManagerId
$clusterTemplateParameters["ManagementPrincipalKey"] = $clusterManagerKey
$clusterTemplateParameters["SshPublicKey"] = $sshPublicKey
DeployTemplate -ResourceGroupName $resourceGroupName -TemplateFileFullPath $clusterTemplateFile -TemplateParameters $clusterTemplateParameters
}