To create an app in Azure Active Directory (Azure AD) using an ARM template, you can follow these steps:
Create an ARM template file (e.g., app-registration.json) with the following content:
json Copy code
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"appName": {
"type": "string",
"metadata": {
"description": "Name of the app registration"
}
},
"appRedirectUri": {
"type": "string",
"defaultValue": "https://localhost"
}
},
"resources": [
{
"type": "Microsoft.Authorization/policyAssignments",
"apiVersion": "2019-09-01",
"name": "[concat('assign-', parameters('appName'))]",
"properties": {
"displayName": "[concat('Assign ', parameters('appName'), ' to Azure AD')]",
"policyDefinitionId": "/providers/Microsoft.Authorization/policyDefinitions/8d3de2ea-a4ed-4f7d-8b97-2d8e5dc4fbc1",
"scope": "/providers/Microsoft.Management/managementGroups/{your-management-group-id}"
}
},
{
"type": "Microsoft.Graph/applications",
"apiVersion": "1.6",
"name": "[parameters('appName')]",
"location": "global",
"properties": {
"displayName": "[parameters('appName')]",
"signInAudience": "AzureADMyOrg",
"web": {
"redirectUris": [
"[parameters('appRedirectUri')]"
]
}
}
}
]
}
Modify the template as per your requirements. You can add more parameters or customize the properties of the app registration resource.
If you want to assign a custom policy to the app registration, replace {your-management-group-id} with your actual management group ID in the "scope" property of the "Microsoft.Authorization/policyAssignments" resource.
Save the ARM template file.
Use Azure PowerShell or Azure CLI to deploy the ARM template. Here's an example using Azure PowerShell:
powershell Copy code
$resourceGroupName = "your-resource-group-name"
$deploymentName = "app-registration-deployment"
$appName = "your-app-name"
$appRedirectUri = "https://your-app-redirect-uri"
New-AzResourceGroupDeployment -Name $deploymentName `
-ResourceGroupName $resourceGroupName `
-TemplateFile "app-registration.json" `
-appName $appName `
-appRedirectUri $appRedirectUri
Replace your-resource-group-name, your-app-name, and https://your-app-redirect-uri with your desired values.
Wait for the deployment to complete. Once finished, the app registration will be created in Azure AD with the specified name and redirect URI.
Note: Make sure you have the necessary permissions to create resources and policy assignments in Azure AD and the specified management group.