Skip to content

Commit 4b05c73

Browse files
author
Guneet Aggarwal
committed
feat: configuration creation in using 'az site quickstart' will now create MRG with service principals from graph api
1 parent 4a62196 commit 4b05c73

2 files changed

Lines changed: 42 additions & 2 deletions

File tree

src/site/azext_site/aaz/latest/site/_quickstart.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,36 @@
2222
CLIInternalError,
2323
)
2424
from 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]
2526
from knack.log import get_logger
2627

2728
logger = 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
3457
def _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)

src/site/azext_site/templates/infra/main.json

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
},
99
"configApiVersion": {
1010
"type": "string",
11-
"defaultValue": "2025-06-01"
11+
"defaultValue": "2025-12-01-preview"
1212
},
1313
"configChildApiVersion": {
1414
"type": "string",
@@ -121,6 +121,10 @@
121121
}
122122
}
123123
}
124+
},
125+
"additionalIdentitiesMetadata": {
126+
"type": "array",
127+
"defaultValue": []
124128
}
125129
},
126130
"variables": {
@@ -151,7 +155,12 @@
151155
"apiVersion": "[parameters('configApiVersion')]",
152156
"name": "[parameters('configName')]",
153157
"location": "[parameters('location')]",
154-
"properties": {},
158+
"properties": {
159+
"managedResourcesConfiguration": {
160+
"enabled": true,
161+
"additionalIdentitiesMetadata": "[parameters('additionalIdentitiesMetadata')]"
162+
}
163+
},
155164
"resources": [
156165
{
157166
"type": "NetworkConfigurations",

0 commit comments

Comments
 (0)