-
Notifications
You must be signed in to change notification settings - Fork 1
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
Felix Zieger
committed
Sep 9, 2024
1 parent
a69615e
commit 212d960
Showing
7 changed files
with
90 additions
and
10 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
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
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
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
42 changes: 42 additions & 0 deletions
42
modules/meshcloud-replicator-service-principal/set-enrollment-account-permission.ps1
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,42 @@ | ||
param ( | ||
[Parameter(Mandatory = $true), HelpMessage="The object ID of the replicator enterprise application"] | ||
[string] | ||
$principalId | ||
|
||
[Parameter(Mandatory = $true), HelpMessage="Your AAD tenant id"] | ||
[string] | ||
$aadTenantId | ||
|
||
[Parameter(Mandatory = $true), HelpMessage="You can find the billing account id in the Azure portal on the Cost Management + Billing overview page."] | ||
[Int] | ||
$billingAccountId | ||
|
||
|
||
[Parameter(Mandatory = $true), HelpMessage="You can find the enrollment account id in the Azure portal on the Detail page of your enrollment account."] | ||
[Int] | ||
$enrollmentAccountId | ||
) | ||
|
||
# Build the request | ||
$token = (Get-AzAccessToken -ResourceUrl 'https://management.azure.com').Token | ||
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]" | ||
$headers.Add("Content-Type", "application/json") | ||
$headers.Add("Authorization","Bearer $token") | ||
$billingRoleAssignmentName = (New-Guid).Guid | ||
|
||
$url = "https://management.azure.com/providers/Microsoft.Billing/billingAccounts/$billingAccountId/enrollmentAccounts/$enrollmentAccountId/billingRoleAssignments/$billingRoleAssignmentName`?api-version=2019-10-01-preview" | ||
|
||
# Subscription Creator. See https://learn.microsoft.com/en-us/azure/cost-management-billing/manage/assign-roles-azure-service-principals#permissions-that-can-be-assigned-to-the-spn | ||
$roleDefinitionId = "/providers/Microsoft.Billing/billingAccounts/$billingAccountId/enrollmentAccounts/$enrollmentAccountId/billingRoleDefinitions/a0bcee42-bf30-4d1b-926a-48d21664ef71" | ||
|
||
$body = "{ | ||
`"properties`": { | ||
`"principalId`": `"$principalId`", | ||
`"principalTenantId`": `"$aadTenantId`", | ||
`"roleDefinitionId`": `"$roleDefinitionId`"}`n}" | ||
|
||
# Send request | ||
Invoke-RestMethod $url -Method 'Put' -Headers $headers -Body $body | Format-List | ||
|
||
# Check that the creation was successfull | ||
Invoke-RestMethod $url -Method 'Get' -Headers $headers | Format-List |
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
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