Skip to content

Commit 7ece850

Browse files
committed
Infrastructure script with event hub, azure container registry and azure container service with Kubernetes
1 parent df7aad0 commit 7ece850

File tree

3 files changed

+330
-0
lines changed

3 files changed

+330
-0
lines changed

Create-Infrastructure.ps1

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#Requires -Version 3.0
2+
#Requires -Module AzureRM.Resources
3+
4+
Param(
5+
[Parameter(Mandatory=$True)]
6+
[string]
7+
$EnvironmentTag,
8+
9+
[string]
10+
$ResourceGroupLocation = "North Europe"
11+
)
12+
13+
# stop the script on first error
14+
$ErrorActionPreference = 'Stop'
15+
16+
#******************************************************************************
17+
# Dependencies
18+
#******************************************************************************
19+
20+
. "DeviceCache.Infrastructure/Common-Functions.ps1"
21+
22+
#******************************************************************************
23+
# Script body
24+
#******************************************************************************
25+
26+
$resourceGroupName = "ca-devcache-$EnvironmentTag-rg"
27+
CreateResourceGroupIfNotPresent -resourceGroupName $ResourceGroupName -resourceGroupLocation $ResourceGroupLocation
28+
29+
$eventHubTemplateFile = [System.IO.Path]::GetFullPath([System.IO.Path]::Combine($PSScriptRoot, "DeviceCache.Infrastructure/EventHub.json"))
30+
$clusterTemplateFile = [System.IO.Path]::GetFullPath([System.IO.Path]::Combine($PSScriptRoot, "DeviceCache.Infrastructure/Cluster.json"))
31+
32+
$automationKeyVaultName = "ca-automation-$EnvironmentTag"
33+
$automationKeyVault = Get-AzureRmKeyVault -VaultName $automationKeyVaultName -ErrorAction SilentlyContinue
34+
35+
if (-not $automationKeyVault) {
36+
throw "Automation key vault not found. Make sure you run the Create-Prerequisites.ps1 script first."
37+
}
38+
39+
$clusterManagerId = (Get-AzureKeyVaultSecret -VaultName $automationKeyVaultName -SecretName servicePrincipalId).SecretValueText
40+
$clusterManagerKey = (Get-AzureKeyVaultSecret -VaultName $automationKeyVaultName -SecretName servicePrincipalPassword).SecretValue
41+
$sshPublicKey = (Get-AzureKeyVaultSecret -VaultName $automationKeyVaultName -SecretName machineSshPublicKey).SecretValueText
42+
43+
$keyVaultName = "ca-devcache-$EnvironmentTag"
44+
Create-KeyVault -KeyVaultName $keyVaultName -ResourceGroupName $resourceGroupName -ResourceGroupLocation $ResourceGroupLocation
45+
46+
$eventHubTemplateParameters = New-Object -TypeName Hashtable
47+
$eventHubTemplateParameters["EnvironmentTag"] = $EnvironmentTag
48+
49+
$clusterTemplateParameters = New-Object -TypeName Hashtable
50+
$clusterTemplateParameters["EnvironmentTag"] = $EnvironmentTag
51+
$clusterTemplateParameters["ManagementPrincipalId"] = $clusterManagerId
52+
$clusterTemplateParameters["ManagementPrincipalKey"] = $clusterManagerKey
53+
$clusterTemplateParameters["SshPublicKey"] = $sshPublicKey
54+
55+
DeployTemplate -ResourceGroupName $resourceGroupName -TemplateFileFullPath $eventHubTemplateFile -TemplateParameters $eventHubTemplateParameters
56+
DeployTemplate -ResourceGroupName $resourceGroupName -TemplateFileFullPath $clusterTemplateFile -TemplateParameters $clusterTemplateParameters
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
{
2+
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
3+
"contentVersion": "1.0.0.0",
4+
"parameters": {
5+
"EnvironmentTag": {
6+
"type": "string"
7+
},
8+
"ManagementPrincipalId": {
9+
"type": "string"
10+
},
11+
"ManagementPrincipalKey": {
12+
"type": "securestring"
13+
},
14+
"SshPublicKey": {
15+
"type": "string"
16+
}
17+
},
18+
"variables": {
19+
"registryImagesStorage": "[concat('cadevcache', parameters('EnvironmentTag'), 'images')]",
20+
"registryName": "[concat('cadevcache', parameters('EnvironmentTag'), 'registry')]",
21+
22+
"linuxVmAdminUser": "coffeepot",
23+
24+
"orchestratorEngine": "Kubernetes",
25+
"masterCount": 1,
26+
"minionCount": 5,
27+
"minionMachineSize": "Standard_A2",
28+
29+
"minionsEndpointDNSNamePrefix": "[concat(parameters('EnvironmentTag'),'minions')]",
30+
"mastersEndpointDNSNamePrefix": "[concat(parameters('EnvironmentTag'),'masters')]",
31+
"useServicePrincipalDictionary": {
32+
"DCOS": 0,
33+
"Swarm": 0,
34+
"Kubernetes": 1
35+
},
36+
"useServicePrincipal": "[variables('useServicePrincipalDictionary')[variables('orchestratorEngine')]]",
37+
"servicePrincipalFields": [
38+
null,
39+
{
40+
"ClientId": "[parameters('ManagementPrincipalId')]",
41+
"Secret": "[parameters('ManagementPrincipalKey')]"
42+
}
43+
]
44+
},
45+
"resources": [
46+
{
47+
"name": "[variables('registryImagesStorage')]",
48+
"type": "Microsoft.Storage/storageAccounts",
49+
"location": "[resourceGroup().location]",
50+
"apiVersion": "2016-12-01",
51+
"tags": {
52+
"containerregistry": "[variables('registryName')]",
53+
"displayName": "registry images storage"
54+
},
55+
"sku": {
56+
"name": "Standard_LRS"
57+
},
58+
"kind": "Storage",
59+
"properties": {
60+
"encryption": {
61+
"services": {
62+
"blob": {
63+
"enabled": true
64+
}
65+
},
66+
"keySource": "Microsoft.Storage"
67+
}
68+
}
69+
},
70+
{
71+
"name": "[variables('registryName')]",
72+
"type": "Microsoft.ContainerRegistry/registries",
73+
"location": "[resourceGroup().location]",
74+
"tags": {
75+
"displayName": "registry"
76+
},
77+
"apiVersion": "2017-03-01",
78+
"sku": {
79+
"name": "Basic"
80+
},
81+
"dependsOn": [
82+
"[resourceId('Microsoft.Storage/storageAccounts', variables('registryImagesStorage'))]"
83+
],
84+
"properties": {
85+
"adminUserEnabled": false,
86+
"storageAccount": {
87+
"name": "[variables('registryImagesStorage')]",
88+
"accessKey": "[listKeys(resourceId('Microsoft.Storage/storageAccounts', variables('registryImagesStorage')), '2016-12-01').keys[0].value]"
89+
}
90+
}
91+
},
92+
{
93+
"apiVersion": "2016-09-30",
94+
"type": "Microsoft.ContainerService/containerServices",
95+
"location": "[resourceGroup().location]",
96+
"name": "[concat('containerservice-', resourceGroup().name)]",
97+
"tags" : {
98+
"displayName": "acs"
99+
},
100+
"properties": {
101+
"orchestratorProfile": {
102+
"orchestratorType": "[variables('orchestratorEngine')]"
103+
},
104+
"masterProfile": {
105+
"count": "[variables('masterCount')]",
106+
"dnsPrefix": "[variables('mastersEndpointDNSNamePrefix')]"
107+
},
108+
"agentPoolProfiles": [
109+
{
110+
"name": "agentpools",
111+
"count": "[variables('minionCount')]",
112+
"vmSize": "[variables('minionMachineSize')]",
113+
"dnsPrefix": "[variables('minionsEndpointDNSNamePrefix')]"
114+
}
115+
],
116+
"linuxProfile": {
117+
"adminUsername": "[variables('linuxVmAdminUser')]",
118+
"ssh": {
119+
"publicKeys": [
120+
{
121+
"keyData": "[parameters('SshPublicKey')]"
122+
}
123+
]
124+
}
125+
},
126+
"servicePrincipalProfile": "[variables('servicePrincipalFields')[variables('useServicePrincipal')]]"
127+
}
128+
}
129+
],
130+
"outputs": {}
131+
}
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
{
2+
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
3+
"contentVersion": "1.0.0.0",
4+
"parameters": {
5+
"EnvironmentTag": {
6+
"type": "string"
7+
}
8+
},
9+
"variables": {
10+
"keyVaultApiVersion": "2015-06-01",
11+
"keyVaultName": "[concat('ca-devcache-', parameters('environmentTag'))]",
12+
13+
"eventHubApiVersion": "2015-08-01",
14+
"namespaceName": "[concat('ca-devcache-', parameters('environmentTag'), '-namespace')]",
15+
"eventHubName": "[concat('ca-devcache-', parameters('environmentTag'), '-hub')]",
16+
"eventHubSendConnectionStringKeyName": "eventHubSendConnectionString",
17+
"eventHubReceiveConnectionStringKeyName": "eventHubReceiveConnectionString",
18+
"sendRuleName": "sendRule",
19+
"receiveRuleName": "receiveRule",
20+
"sendAuthRuleResourceId": "[resourceId('Microsoft.EventHub/namespaces/eventhubs/authorizationRules', variables('namespaceName'), variables('eventHubName'), variables('sendRuleName'))]",
21+
"receiveAuthRuleResourceId": "[resourceId('Microsoft.EventHub/namespaces/eventhubs/authorizationRules', variables('namespaceName'), variables('eventHubName'), variables('receiveRuleName'))]",
22+
23+
"storageApiVersion": "2016-01-01",
24+
"consumerCoordinationStorage": "[concat('cadevcache', parameters('environmentTag'), 'storage')]",
25+
"storageSecretKeyName": "storageConnection"
26+
},
27+
"resources": [
28+
{
29+
"apiVersion": "[variables('eventHubApiVersion')]",
30+
"name": "[variables('namespaceName')]",
31+
"type": "Microsoft.EventHub/Namespaces",
32+
"tags": { "displayName": "Event Hub namespace & hub" },
33+
"location": "[resourceGroup().location]",
34+
"sku": {
35+
"name": "Standard",
36+
"tier": "Standard",
37+
"capacity": 20
38+
},
39+
"resources": [
40+
{
41+
"apiVersion": "[variables('eventHubApiVersion')]",
42+
"name": "[variables('eventHubName')]",
43+
"type": "EventHubs",
44+
"dependsOn": [
45+
"[concat('Microsoft.EventHub/namespaces/', variables('namespaceName'))]"
46+
],
47+
"properties": {
48+
"path": "[variables('eventHubName')]",
49+
"MessageRetentionInDays": "1",
50+
"PartitionCount": 20
51+
},
52+
"resources": [
53+
{
54+
"apiVersion": "[variables('eventHubApiVersion')]",
55+
"name": "devcacheConsumers",
56+
"type": "ConsumerGroups",
57+
"dependsOn": [
58+
"[variables('eventHubName')]"
59+
]
60+
},
61+
{
62+
"type": "authorizationRules",
63+
"name": "[variables('receiveRuleName')]",
64+
"apiVersion": "[variables('eventHubApiVersion')]",
65+
"properties": {
66+
"rights": [
67+
"Listen"
68+
]
69+
},
70+
"resources": [],
71+
"dependsOn": [
72+
"[variables('eventHubName')]"
73+
]
74+
},
75+
{
76+
"type": "authorizationRules",
77+
"name": "[variables('sendRuleName')]",
78+
"apiVersion": "[variables('eventHubApiVersion')]",
79+
"properties": {
80+
"rights": [
81+
"Send"
82+
]
83+
},
84+
"resources": [],
85+
"dependsOn": [
86+
"[variables('eventHubName')]"
87+
]
88+
}
89+
]
90+
}
91+
]
92+
},
93+
{
94+
"type": "Microsoft.Storage/storageAccounts",
95+
"name": "[variables('consumerCoordinationStorage')]",
96+
"tags": { "displayName": "Consumer coordination storage" },
97+
"apiVersion": "[variables('storageApiVersion')]",
98+
"location": "[resourceGroup().location]",
99+
"sku": {
100+
"name": "Standard_LRS"
101+
},
102+
"kind": "Storage",
103+
"properties": {}
104+
},
105+
{
106+
"type": "Microsoft.KeyVault/vaults/secrets",
107+
"apiVersion": "[variables('keyVaultApiVersion')]",
108+
"name": "[concat(variables('keyVaultName'), '/', variables('consumerCoordinationStorage'))]",
109+
"tags": { "displayName": "Storage secret entry in key vault" },
110+
"properties": {
111+
"value": "[listKeys(resourceId('Microsoft.Storage/storageAccounts', variables('consumerCoordinationStorage')), providers('Microsoft.Storage', 'storageAccounts').apiVersions[0]).keys[0].value]"
112+
},
113+
"dependsOn": [
114+
"[concat('Microsoft.Storage/storageAccounts/', variables('consumerCoordinationStorage'))]"
115+
]
116+
},
117+
{
118+
"type": "Microsoft.KeyVault/vaults/secrets",
119+
"apiVersion": "[variables('keyVaultApiVersion')]",
120+
"name": "[concat(variables('keyVaultName'), '/', variables('eventHubSendConnectionStringKeyName'))]",
121+
"tags": { "displayName": "Event hub send connection string secret entry in key vault" },
122+
"properties": {
123+
"value": "[listkeys(variables('sendAuthRuleResourceId'), variables('eventHubApiVersion')).primaryConnectionString]"
124+
},
125+
"dependsOn": [
126+
"[concat('Microsoft.EventHub/namespaces/', variables('namespaceName'))]"
127+
]
128+
},
129+
{
130+
"type": "Microsoft.KeyVault/vaults/secrets",
131+
"apiVersion": "[variables('keyVaultApiVersion')]",
132+
"name": "[concat(variables('keyVaultName'), '/', variables('eventHubReceiveConnectionStringKeyName'))]",
133+
"tags": { "displayName": "Event hub receive connection string secret entry in key vault" },
134+
"properties": {
135+
"value": "[listkeys(variables('receiveAuthRuleResourceId'), variables('eventHubApiVersion')).primaryConnectionString]"
136+
},
137+
"dependsOn": [
138+
"[concat('Microsoft.EventHub/namespaces/', variables('namespaceName'))]"
139+
]
140+
}
141+
],
142+
"outputs": {}
143+
}

0 commit comments

Comments
 (0)