|
1 | | -# Copyright (c) Microsoft Corporation. |
| 1 | +# Copyright (c) Microsoft Corporation. |
2 | 2 | # Licensed under the MIT license. |
3 | 3 |
|
4 | 4 | #https://patorjk.com/software/taag |
@@ -502,6 +502,38 @@ try { |
502 | 502 |
|
503 | 503 | # 2.Connect to AKS cluster |
504 | 504 | try { |
| 505 | + Write-Host "Checking if user already has AKS Cluster Admin role..." -ForegroundColor Cyan |
| 506 | + # ----------------------------------------- |
| 507 | + # Check and assign AKS RBAC Cluster Admin role |
| 508 | + # ----------------------------------------- |
| 509 | + |
| 510 | + $subscriptionId = (az account show --query id -o tsv) |
| 511 | + $resourceGroup = $deploymentResult.ResourceGroupName |
| 512 | + $aksName = $deploymentResult.AksName |
| 513 | + |
| 514 | + # Get current signed-in user |
| 515 | + $currentUser = az ad signed-in-user show --query id -o tsv |
| 516 | + |
| 517 | + # Get AKS resource ID |
| 518 | + $aksResourceId = az aks show --resource-group $resourceGroup --name $aksName --subscription $subscriptionId --query id -o tsv |
| 519 | + |
| 520 | + # Check if role already assigned |
| 521 | + $roleCheck = az role assignment list ` |
| 522 | + --assignee $currentUser ` |
| 523 | + --role "Azure Kubernetes Service RBAC Cluster Admin" ` |
| 524 | + --scope $aksResourceId ` |
| 525 | + --query "[].id" -o tsv |
| 526 | + |
| 527 | + if (-not $roleCheck) { |
| 528 | + Write-Host "Assigning 'Azure Kubernetes Service RBAC Cluster Admin' role to current user..." |
| 529 | + az role assignment create ` |
| 530 | + --assignee $currentUser ` |
| 531 | + --role "Azure Kubernetes Service RBAC Cluster Admin" ` |
| 532 | + --scope $aksResourceId | Out-Null |
| 533 | + Write-Host "Role assignment complete." |
| 534 | + } else { |
| 535 | + Write-Host "User already has 'Azure Kubernetes Service RBAC Cluster Admin' role." |
| 536 | + } |
505 | 537 | Write-Host "Connecting to AKS cluster..." -ForegroundColor Cyan |
506 | 538 | az aks get-credentials --resource-group $deploymentResult.ResourceGroupName --name $deploymentResult.AksName --overwrite-existing |
507 | 539 | Write-Host "Connected to AKS cluster." -ForegroundColor Green |
|
0 commit comments