Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[AKS] az aks create/update: Support UserAssigned Managed Identity for grafana linking in managed prometheus #29713

Merged
merged 3 commits into from
Aug 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,23 @@ def link_grafana_instance(cmd, raw_parameters, azure_monitor_workspace_resource_
)
headers = ['User-Agent=azuremonitormetrics.link_grafana_instance']
grafanaArmResponse = send_raw_request(cmd.cli_ctx, "GET", grafanaURI, body={}, headers=headers)
servicePrincipalId = grafanaArmResponse.json()["identity"]["principalId"]

# Check if 'identity' and 'type' exist in the response
identity_info = grafanaArmResponse.json().get("identity", {})
identity_type = identity_info.get("type", "").lower()

if identity_type == "systemassigned":
servicePrincipalId = identity_info.get("principalId")
elif identity_type == "userassigned":
yanzhudd marked this conversation as resolved.
Show resolved Hide resolved
user_assigned_identities = identity_info.get("userAssignedIdentities", {})
if not user_assigned_identities:
raise CLIError("No user-assigned identities found.")
servicePrincipalId = list(user_assigned_identities.values())[0]["principalId"]
else:
raise CLIError("Unsupported or missing identity type.")

if not servicePrincipalId:
raise CLIError("No service principal ID found for the specified identity.")
except CLIError as e:
raise CLIError(e)
# Add Role Assignment
Expand Down