diff --git a/src/azure-cli/azure/cli/command_modules/role/_help.py b/src/azure-cli/azure/cli/command_modules/role/_help.py index 237f64eeff9..a7d35cad782 100644 --- a/src/azure-cli/azure/cli/command_modules/role/_help.py +++ b/src/azure-cli/azure/cli/command_modules/role/_help.py @@ -419,8 +419,8 @@ text: az ad sp create-for-rbac - name: Create using a custom display name. text: az ad sp create-for-rbac -n "MyApp" - - name: Create with a Contributor role assignments on specified scope. - text: az ad sp create-for-rbac -n "MyApp" --role Contributor --scopes /subscriptions/{SubID}/resourceGroups/{ResourceGroup1} /subscriptions/{SubID}/resourceGroups/{ResourceGroup2} + - name: Create with a Contributor role assignments on specified scopes. To retrieve current subscription ID, run `az account show --query id --output tsv`. + text: az ad sp create-for-rbac -n "MyApp" --role Contributor --scopes /subscriptions/{subscriptionId}/resourceGroups/{resourceGroup1} /subscriptions/{subscriptionId}/resourceGroups/{resourceGroup2} - name: Create using a self-signed certificate. text: az ad sp create-for-rbac --create-cert - name: Create using a self-signed certificate, and store it within KeyVault. diff --git a/src/azure-cli/azure/cli/command_modules/role/custom.py b/src/azure-cli/azure/cli/command_modules/role/custom.py index 21467e943fe..6add6341bd3 100644 --- a/src/azure-cli/azure/cli/command_modules/role/custom.py +++ b/src/azure-cli/azure/cli/command_modules/role/custom.py @@ -39,6 +39,9 @@ logger = get_logger(__name__) +SCOPE_WARNING = "In a future release, --scopes argument will become required for creating a role assignment. " \ + "Please explicitly specify --scopes." + # pylint: disable=too-many-lines @@ -1403,7 +1406,11 @@ def create_service_principal_for_rbac( graph_client = _graph_client_factory(cmd.cli_ctx) role_client = _auth_client_factory(cmd.cli_ctx).role_assignments - scopes = scopes or ['/subscriptions/' + role_client.config.subscription_id] + + if role and not scopes: + logger.warning(SCOPE_WARNING) + scopes = ['/subscriptions/' + role_client.config.subscription_id] + years = years or 1 _RETRY_TIMES = 36 existing_sps = None