-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.ps1
More file actions
49 lines (37 loc) · 1.42 KB
/
deploy.ps1
File metadata and controls
49 lines (37 loc) · 1.42 KB
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
param(
[Parameter(Mandatory = $true)]
[string]$SubscriptionId,
[Parameter(Mandatory = $true)]
[string]$ResourceGroupName,
[Parameter(Mandatory = $false)]
[string]$Location = "eastus",
[Parameter(Mandatory = $false)]
[string]$ParameterFile = "infra/bicep/parameters.dev.json",
[Parameter(Mandatory = $false)]
[switch]$DryRun
)
$ErrorActionPreference = "Stop"
Write-Host "Setting Azure subscription context..."
az account set --subscription $SubscriptionId | Out-Null
if ($DryRun) {
Write-Host "Dry run enabled. Checking that resource group '$ResourceGroupName' exists..."
$rgExists = az group exists --name $ResourceGroupName
if ($rgExists -ne "true") {
throw "Resource group '$ResourceGroupName' does not exist. Create it first, then run dry run again."
}
Write-Host "Running what-if preview..."
az deployment group what-if `
--resource-group $ResourceGroupName `
--template-file "infra/bicep/main.bicep" `
--parameters "@$ParameterFile"
Write-Host "Dry run complete. No resources were created or updated."
exit 0
}
Write-Host "Ensuring resource group '$ResourceGroupName' exists in '$Location'..."
az group create --name $ResourceGroupName --location $Location | Out-Null
Write-Host "Deploying infrastructure..."
az deployment group create `
--resource-group $ResourceGroupName `
--template-file "infra/bicep/main.bicep" `
--parameters "@$ParameterFile"
Write-Host "Deployment complete."