Complete the code to create a service principal using Azure CLI.
az ad sp create-for-rbac --name [1]
The --name parameter specifies the name of the service principal. Here, "MyAppSP" is a clear, descriptive name.
Complete the code to assign the 'Contributor' role to the service principal.
az role assignment create --assignee [1] --role Contributor --scope /subscriptions/00000000-0000-0000-0000-000000000000
The --assignee parameter requires the application ID (appId) of the service principal to assign the role correctly.
Fix the error in the command to list service principals filtered by display name.
az ad sp list --filter "displayName eq '[1]'"
The filter is case-sensitive and must match the exact display name of the service principal, which is "MyAppSP".
Fill both blanks to create a service principal and output its appId and password.
sp=$(az ad sp create-for-rbac --name [1] --query [2] -o json) echo $sp
The --query parameter extracts the appId and password fields from the JSON output. The name must match the service principal name.
Fill all three blanks to assign a role to a service principal with a specific scope and output the assignment ID.
assignment=$(az role assignment create --assignee [1] --role [2] --scope [3] --query id -o tsv) echo $assignment
The --assignee is the service principal's appId, --role is the role name, and --scope is the resource group path. The command outputs the assignment ID.