2222 CLIInternalError ,
2323)
2424from azure .cli .core import get_default_cli # type: ignore[import-unresolved]
25+ from azure .cli .command_modules .role import graph_client_factory # type: ignore[import-unresolved]
2526from knack .log import get_logger
2627
2728logger = get_logger (__name__ )
2829
2930
3031_TEMPLATE_RESOURCE = ("templates" , "infra" , "main.json" )
3132
33+ _MANAGED_RESOURCE_APP_IDS = {
34+ "AzureLocal" : "1322e676-dee7-41ee-a874-ac923822781c" ,
35+ "AzureEdgeOnboardingService" : "47cb7c39-a99c-4dab-b91c-3a45ea22b1a8" ,
36+ }
37+
38+
39+ def _resolve_additional_identities (cli_ctx ) -> list [dict ]:
40+ graph_client = graph_client_factory (cli_ctx )
41+ identities : list [dict ] = []
42+ for name , app_id in _MANAGED_RESOURCE_APP_IDS .items ():
43+ result = graph_client .service_principal_list (filter = f"appId eq '{ app_id } '" )
44+ if len (result ) == 0 :
45+ az_error = CLIInternalError (
46+ f"Service principal for '{ name } ' (appId: { app_id } ) was not found in this tenant."
47+ )
48+ raise az_error
49+ identities .append ({
50+ "servicePrincipalObjectId" : result [0 ]["id" ],
51+ "name" : name ,
52+ })
53+ return identities
54+
3255
3356@contextmanager
3457def _template_file ():
@@ -341,6 +364,8 @@ def handle(self):
341364 rg = self .ctx .args .resource_group .to_serialized_data () if has_value (self .ctx .args .resource_group ) else site_name
342365 rg_location = _create_resource_group (cli , rg , location_arg )
343366
367+ additional_identities = _resolve_additional_identities (self .cli_ctx )
368+
344369 deployment_name = f"site-quickstart-{ site_name } "
345370
346371 with _template_file () as template :
@@ -360,6 +385,12 @@ def handle(self):
360385 config_name = self .ctx .args .config_name .to_serialized_data ()
361386 invoke_args .extend (["--parameters" , f"configName={ config_name } " ])
362387
388+ if additional_identities :
389+ invoke_args .extend ([
390+ "--parameters" ,
391+ json .dumps ({"additionalIdentitiesMetadata" : {"value" : additional_identities }}),
392+ ])
393+
363394 if logger .isEnabledFor (logging .DEBUG ):
364395 defaults_version = _get_configuration_defaults_version (template )
365396 logger .debug ("Quickstart configuration defaults version: %s" , defaults_version )
0 commit comments