-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ce3e828
commit ec36169
Showing
3 changed files
with
46 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
$location = 'australiaeast' | ||
$loc = 'aue' | ||
$rg = 'numberservice-rg' | ||
$tags = 'project=NumberService', 'repo=DanielLarsenNZ/NumberService' | ||
$insights = 'numberservice-insights' | ||
$cosmos = 'numberservice' | ||
$cosmosDB = 'NumberService' | ||
$container='Numbers' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,25 @@ | ||
# Deploy NumberService resources | ||
|
||
$ErrorActionPreference = 'Stop' | ||
. ./_vars.ps1 | ||
|
||
$location = 'australiaeast' | ||
$loc = 'aue' | ||
$rg = 'numberservice-rg' | ||
$tags = 'project=NumberService', 'repo=DanielLarsenNZ/NumberService' | ||
$cosmos = 'numberservice' | ||
$cosmosDB = 'NumberService' | ||
$throughput = 400 | ||
$container='Numbers' | ||
$pk = '/id' | ||
$insights = 'numberservice-insights' | ||
$functionApp = "numberservice-$loc" | ||
$repo = 'https://github.com/DanielLarsenNZ/NumberService.git' | ||
$storage = "numservfn$loc" | ||
|
||
$primaryCosmosLocation = 'australiaeast' | ||
$secondaryCosmosLocation = 'australiasoutheast' | ||
|
||
# RESOURCE GROUP | ||
az group create -n $rg --location $location --tags $tags | ||
|
||
|
||
# COSMOS DB ACCOUNT | ||
az cosmosdb create -n $cosmos -g $rg --default-consistency-level Session ` | ||
--locations regionName=$location failoverPriority=0 isZoneRedundant=True | ||
--locations regionName=$primaryCosmosLocation failoverPriority=0 isZoneRedundant=True ` | ||
--locations regionName=$secondaryCosmosLocation failoverPriority=1 isZoneRedundant=False ` | ||
--enable-automatic-failover $true ` | ||
--enable-multiple-write-locations $true | ||
az cosmosdb sql database create -a $cosmos -g $rg -n $cosmosDB --throughput $throughput | ||
az cosmosdb sql container create -a $cosmos -g $rg -d $cosmosDB -n $container -p $pk | ||
$connString = ( az cosmosdb keys list -n $cosmos -g $rg --type 'connection-strings' | ConvertFrom-Json ).connectionStrings[0].connectionString | ||
|
||
|
||
# STORAGE ACCOUNT | ||
az storage account create -n $storage -g $rg --tags $tags --location $location --sku 'Standard_LRS' | ||
|
||
$env:NUMBERS_COSMOS_CONNSTRING = ( az cosmosdb keys list -n $cosmos -g $rg --type 'connection-strings' | ConvertFrom-Json ).connectionStrings[0].connectionString | ||
|
||
# APPLICATION INSIGHTS | ||
$instrumentationKey = ( az monitor app-insights component create --app $insights --location $location -g $rg --tags $tags | ConvertFrom-Json ).instrumentationKey | ||
|
||
|
||
# FUNCTION APP | ||
az functionapp create -n $functionApp -g $rg --consumption-plan-location $location --functions-version 3 ` | ||
--app-insights $insights --app-insights-key $instrumentationKey -s $storage | ||
az functionapp config appsettings set -n $functionApp -g $rg --settings ` | ||
"CosmosDbConnectionString=$connString" ` | ||
"CosmosDbDatabaseId=$cosmosDB" ` | ||
"CosmosDbContainerId=$container" | ||
az functionapp deployment source config -n $functionApp -g $rg --repo-url $repo --branch 'main' | ||
|
||
# Tear down | ||
# az group delete -n $rg --yes | ||
$env:NUMBERS_APP_INSIGHTS_IKEY = ( az monitor app-insights component create --app $insights --location $location -g $rg --tags $tags | ConvertFrom-Json ).instrumentationKey |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
[CmdletBinding()] | ||
param ( | ||
[Parameter(Mandatory = $true)] [ValidateSet('australiaeast', 'australiasoutheast')] $FunctionLocation | ||
) | ||
|
||
. ./_vars.ps1 | ||
|
||
$loc = switch ($FunctionLocation) { | ||
'australiaeast' { 'aue' } | ||
'australiasoutheast' { 'ase' } | ||
default { throw "$FunctionLocation is not supported" } | ||
} | ||
|
||
$functionApp = "numberservice-$loc" | ||
$repo = 'https://github.com/DanielLarsenNZ/NumberService.git' | ||
$storage = "numservfn$loc" | ||
|
||
# STORAGE ACCOUNT | ||
az storage account create -n $storage -g $rg --tags $tags --location $FunctionLocation --sku 'Standard_LRS' | ||
|
||
|
||
# FUNCTION APP | ||
az functionapp create -n $functionApp -g $rg --consumption-plan-location $FunctionLocation --functions-version 3 ` | ||
--app-insights $insights --app-insights-key $env:NUMBERS_APP_INSIGHTS_IKEY -s $storage | ||
az functionapp config appsettings set -n $functionApp -g $rg --settings ` | ||
"CosmosDbConnectionString=$env:NUMBERS_COSMOS_CONNSTRING" ` | ||
"CosmosDbDatabaseId=$cosmosDB" ` | ||
"CosmosDbContainerId=$container" | ||
az functionapp deployment source config -n $functionApp -g $rg --repo-url $repo --branch 'main' |