2
2
# CRUD an Azure Subscription
3
3
#
4
4
# Requires the following environment variables:
5
- # - $env:tenant
6
5
# - $env:name
7
6
# - $env:type - string, either "MS-AZR-0148P" (dev/test) or "MS-AZR-0017P" (normal/prod)
8
7
#
9
8
10
9
$credential = New-Object System.Management.Automation.PSCredential ($env: azsub_client_id , (ConvertTo-SecureString $env: azsub_client_secret - AsPlainText - Force))
11
- Connect-AzAccount - Credential $credential - Tenant $env: tenant - ServicePrincipal
10
+ Connect-AzAccount - Credential $credential - Tenant $env: azsub_tenant_id - ServicePrincipal
12
11
13
12
$ErrorActionPreference = ' Stop'
14
13
$old_state = [System.IO.File ]::OpenText(" /dev/stdin" ).ReadToEnd() | ConvertFrom-Json
15
- if ($null -ne $old_state ) {
14
+ if ($null -ne $old_state ) {
16
15
Write-Output " Old state:"
17
16
$old_state | ConvertTo-Json | Write-Output
18
17
}
@@ -21,7 +20,7 @@ function Create {
21
20
22
21
# Check if subscription name already used in this tenant
23
22
Write-Output " Checking for existing subscription with name $env: name ..."
24
- $subscription = Get-AzSubscription - TenantId $env: tenant - SubscriptionName $env: name - ErrorAction SilentlyContinue
23
+ $subscription = Get-AzSubscription - TenantId $env: azsub_tenant_id - SubscriptionName $env: name - ErrorAction SilentlyContinue
25
24
$subscription | ConvertTo-Json | Write-Output
26
25
27
26
# Create new subscription
@@ -31,7 +30,7 @@ function Create {
31
30
$account | ConvertTo-Json | Write-Output
32
31
Write-Output " Creating subscription..."
33
32
try {
34
- $subscription = New-AzSubscription - OfferType $env: type - Name $env: name - EnrollmentAccountObjectId $account [0 ].ObjectId - ErrorAction Stop
33
+ $subscription = New-AzSubscription - OfferType $env: type - Name $env: name - EnrollmentAccountObjectId $account [0 ].ObjectId - ErrorAction Stop
35
34
}
36
35
catch {
37
36
Write-Error " Error: Error when attempting to update subscription name: $ ( $_.Exception.Response ) "
@@ -46,16 +45,16 @@ function Create {
46
45
}
47
46
48
47
# Emit refreshed state
49
- @ { id = $subscription.Id ; tenant = $subscription .TenantId ; name = $subscription.Name } | ConvertTo-Json | Write-Output
48
+ @ { id = $subscription.Id ; name = $subscription.Name } | ConvertTo-Json | Write-Output
50
49
51
50
52
51
}
53
52
54
53
function Read {
55
- $subscription = Get-AzSubscription - TenantId $old_state .tenant - SubscriptionId $old_state.id - ErrorAction Stop
54
+ $subscription = Get-AzSubscription - TenantId $env: azsub_tenant_id - SubscriptionId $old_state.id - ErrorAction Stop
56
55
57
56
# Emit refreshed state
58
- @ { id = $subscription.Id ; tenant = $subscription .TenantId ; name = $subscription.Name } | ConvertTo-Json | Write-Output
57
+ @ { id = $subscription.Id ; name = $subscription.Name } | ConvertTo-Json | Write-Output
59
58
}
60
59
61
60
function Update {
@@ -86,7 +85,7 @@ function Update {
86
85
87
86
# Emit refreshed state
88
87
Write-Host " New state:"
89
- @ { id = $old_state.id ; tenant = $ env: tenant ; name = $env: name } | ConvertTo-Json | Write-Output
88
+ @ { id = $old_state.id ; name = $env: name } | ConvertTo-Json | Write-Output
90
89
}
91
90
92
91
function Delete {
0 commit comments