forked from JetBrains/teamcity-azure-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
prepareCustomData.ps1
29 lines (24 loc) · 927 Bytes
/
prepareCustomData.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
param (
[string]$cloudConfigFile = 'cloud-config.yaml'
)
if (!(Test-Path $cloudConfigFile)) {
Write-Host "Cloud config file '$cloudConfigFile' is not accessible"
exit 1
}
$replacementTokens = @{
'\u0027' = "'";
'\u003e' = '>';
"%RDSHost%" = "',variables('dbServerName'),'";
"%RDSPassword%" = "',parameters('databasePassword'),'";
"%RDSDataBase%" = "',variables('dbName'),'";
"%StorageAccount%" = "',variables('storageAccountName'),'";
"%StorageKey%" = "',listKeys(variables('storageAccountName'), '2017-10-01').keys[0].value,'";
"%FileShare%" = "',variables('storageFileShare'),'";
}
$content = Get-Content -Path $cloudConfigFile -Raw
$json = ConvertTo-Json $content.replace("'", "''")
$json = $json.substring(1, $json.length - 2)
Foreach ($key in $replacementTokens.keys) {
$json = $json.replace($key, $replacementTokens.Item($key))
}
Write-Host "[base64(concat('$json'))]"