-
Notifications
You must be signed in to change notification settings - Fork 26
feat: add identity and role assignment lib steps #1197
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
base: v2
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| import azure_pipelines.ap.steps | ||
|
|
||
| CreateManagedIdentity = lambda serviceConnection: str, subscription: str, resourceGroup: str, name: str, exportVar: str = "IDENTITY" -> steps.Step { | ||
| script = """ | ||
| az identity create \\ | ||
| --resource-group "${resourceGroup}" \\ | ||
| --name "${name}" \\ | ||
| --subscription "${subscription}" | ||
|
|
||
| IDENTITY=$(az identity show \\ | ||
| --resource-group "${resourceGroup}" \\ | ||
| --name "${name}" \\ | ||
| --subscription "${subscription}") | ||
| echo "##vso[task.setvariable variable=${exportVar}_CLIENT_ID]$(echo "$IDENTITY" | jq -r '.clientId')" | ||
| echo "##vso[task.setvariable variable=${exportVar}_ID]$(echo "$IDENTITY" | jq -r '.id')" | ||
| """ | ||
| AzCli(serviceConnection, "Create managed identity ${name}", script) | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| import azure_pipelines.ap.steps | ||
|
|
||
| CreateRoleAssignment = lambda serviceConnection: str, scope: str, role: str, assignee: str, subscription: str -> steps.Step { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This function doesn't provide much value, would it be easier if the user just call AzCli with the script directly?
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When create a function, ask yourself, what does this function encapsulate?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is intended to be invoked multiple times, since the 3 input variables ( scope, role, assignee) can differ per call. Wrapping it as a function avoids duplicating the same CLI script logic. |
||
| script = """ | ||
| az role assignment create \\ | ||
| --scope "${scope}" \\ | ||
| --role "${role}" \\ | ||
| --assignee "${assignee}" \\ | ||
| --subscription "${subscription}" | ||
| """ | ||
| AzCli(serviceConnection, "Assign role ${role} to ${assignee}", script) | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IIUC, you always need to create managed identity, then assign role, then bind it to a service account. Does it make sense to encapsulate the 3 steps into one?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not for my case. I’m not binding it to a service account, and the role assignments target different resources and roles.