-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathazuredeploymentbootstrapper.ps1
60 lines (47 loc) · 2.58 KB
/
azuredeploymentbootstrapper.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
# Use this script to set up your Azure environment and GitHub Actions, so you can deploy explain powershell to Azure with GitHub Actions.
# You can also use this
[cmdletbinding()]
param(
[parameter(mandatory)]
$SubscriptionId,
[parameter(mandatory)]
$ResourceGroupName,
[parameter(mandatory, HelpMessage="For valid values, see 'az account list-locations'")]
$AzureLocation
)
$spnName = $ResourceGroupName
az account show --output none
if ($LASTEXITCODE) {
az login --output none
}
$ghStatus = gh auth status
if ($ghStatus.StartsWith("You are not logged into")) {
gh auth login --hostname github.com --git-protocol string https --web
}
az account set --subscription $SubscriptionId
az group create --location $AzureLocation --name $ResourceGroupName --output none
$existingFunctionAppName = az functionapp list --resource-group $resourcegroupname --query '[].name' --output tsv | Where-Object { $_ -like "fa$resourcegroupname*" }
if (-not $existingFunctionAppName) {
"Generating new names for FunctionApp and Storage Account.."
$rnd = Get-Random -Maximum 1000
if ($null -eq $FunctionAppName) {
$FunctionAppName = "fa$ResourceGroupName$rnd"
}
if ($null -eq $StorageAccountName) {
$StorageAccountName = "sa$ResourceGroupName$rnd"
}
$ResourceGroupName | gh secret set RESOURCE_GROUP_NAME
$FunctionAppName | gh secret set FUNCTION_APP_NAME
$StorageAccountName | gh secret set STORAGE_ACCOUNT_NAME
$explanation = @"
You can now go to your explainpowershell fork on GitHub. Under Actions, run the 'Deploy Azure Infra' workflow, then the 'Deploy app to Azure' workflow and run `./explainpowershell.helpwriter.ps1 -Force -IsProduction -ResourceGroupName $ResourceGroupName -StorageAccountName $StorageAccountName`. The Url where you can reach your version of the project can be found in the Azure Portal. Go to resource group '`$ResourceGroupName'. Under the storage account resource that was deployed, find the 'Static Website' entry in the menu. It is the Url for 'Primary Endpoint'. Alternatively, you can retrieve it with `az`:
`$myStorageAccountName = '$StorageAccountName'
(az storage account show --name `$myStorageAccountName | convertfrom-json).primaryEndpoints.web
"@
Write-Host -ForegroundColor Green $explanation
}
else {
"Found existing FunctionApp set-up '$existingFunctionAppName', only refreshing Azure Service Principal."
}
$spn = az ad sp create-for-rbac --name $spnName --role contributor --scopes /subscriptions/$SubscriptionId/resourceGroups/$ResourceGroupName --sdk-aut
$spn | gh secret set AZURE_SERVICE_PRINCIPAL