Deploying Foundry Infrastructure with Bicep and the Azure CLI
This lesson shows how Foundry resources, projects, deployments, role assignments and private endpoints are deployed with Bicep and the Azure CLI.
Learning outcomes
After completing this lesson, you will be able to:
- Identify the resource types and properties for Foundry in Bicep.
- Describe project and deployment resources.
- Explain why deployments are chained with dependsOn.
- Identify the CLI options needed for project management.
The Foundry resource in Bicep
The Foundry resource is Microsoft.CognitiveServices/accounts with kind: 'AIServices'. The properties that matter for GenAIOps are the custom subdomain, project management, network access and local authentication.
param env string
param location string = resourceGroup().location
resource foundry 'Microsoft.CognitiveServices/accounts@2025-06-01' = {
name: 'ai-contoso-${env}'
location: location
kind: 'AIServices'
sku: { name: 'S0' }
identity: { type: 'SystemAssigned' }
properties: {
customSubDomainName: 'ai-contoso-${env}'
allowProjectManagement: true
publicNetworkAccess: env == 'prod' ? 'Disabled' : 'Enabled'
disableLocalAuth: true
}
}allowProjectManagement must be true for the resource to host projects and cannot be changed after creation, and the resource needs a managed identity before projects are created. The custom subdomain must be globally unique and is needed for Microsoft Entra authentication.
Projects and deployments
Projects and model deployments are child resources. Deployments are created one at a time, so a template with several deployments chains them with dependsOn to avoid conflicting updates on the parent resource.
resource project 'Microsoft.CognitiveServices/accounts/projects@2025-06-01' = {
parent: foundry
name: 'support'
location: location
identity: { type: 'SystemAssigned' }
properties: { displayName: 'Support assistant', description: 'Customer support agents' }
}
resource chat 'Microsoft.CognitiveServices/accounts/deployments@2025-06-01' = {
parent: foundry
name: 'chat'
sku: { name: 'GlobalStandard', capacity: 100 }
properties: {
model: { format: 'OpenAI', name: 'gpt-5-mini', version: '2025-08-07' }
versionUpgradeOption: 'NoAutoUpgrade'
}
}
resource embed 'Microsoft.CognitiveServices/accounts/deployments@2025-06-01' = {
parent: foundry
name: 'embed'
dependsOn: [ chat ]
sku: { name: 'GlobalStandard', capacity: 120 }
properties: { model: { format: 'OpenAI', name: 'text-embedding-3-small', version: '1' } }
}For a standard deployment, the SKU capacity is in thousands of tokens per minute, so 100 means 100,000 TPM. Pinning the version with NoAutoUpgrade makes model changes deliberate releases, which the deployment strategies module explains.
Role assignments and private endpoints
Access and networking belong in the same template, so a new environment is complete when the deployment finishes. Role assignments use deterministic names derived from scope, principal and role. Private endpoints use the account group ID for the Foundry resource, and a private DNS zone group links them to the three Foundry DNS zones.
param supportTeamGroupId string
param foundryUserRoleId string // role definition ID of Foundry User
resource teamAccess 'Microsoft.Authorization/roleAssignments@2022-04-01' = {
name: guid(project.id, supportTeamGroupId, foundryUserRoleId)
scope: project
properties: {
principalId: supportTeamGroupId
principalType: 'Group'
roleDefinitionId: subscriptionResourceId('Microsoft.Authorization/roleDefinitions', foundryUserRoleId)
}
}Passing role definition IDs as parameters, looked up once with az role definition list --name, keeps the template readable and lets it be reviewed without memorizing GUIDs.
The Azure CLI equivalent
The same environment can be created with the Azure CLI, which suits scripts, labs and quick experiments. Project commands require Azure CLI 2.80 or later.
az cognitiveservices account create --name ai-contoso-dev --resource-group rg-ai-dev \
--location swedencentral --kind AIServices --sku S0 --custom-domain ai-contoso-dev \
--assign-identity --allow-project-management true --yes
az cognitiveservices account project create --name ai-contoso-dev --resource-group rg-ai-dev \
--project-name support --location swedencentral
az cognitiveservices account deployment create --name ai-contoso-dev --resource-group rg-ai-dev \
--deployment-name chat --model-name gpt-5-mini --model-version 2025-08-07 --model-format OpenAI \
--sku-name GlobalStandard --sku-capacity 100Without --assign-identity, project creation fails, and --allow-project-management cannot be turned on later, so the resource would have to be recreated. Bicep remains the better choice for environments that must stay consistent, because a template describes the whole desired state and what-if shows drift.
A failing project deployment
A pipeline creates a Foundry resource with az cognitiveservices account create --kind AIServices --sku S0 --custom-domain ai-contoso-test and then runs az cognitiveservices account project create, which fails. The team wants the test environment created in one unattended run, identical to production.
The resource was created without --assign-identity and without --allow-project-management true. A managed identity can be added afterwards, but project management cannot be enabled after creation, so the resource must be recreated with both settings. Better still, replace the script with the Bicep template used for production, with a test parameters file, so that every setting, including identity, project management, deployments and role assignments, is the same.
Retrying the project command would fail the same way. Creating a hub-based project instead would produce a different platform from production. Granting the pipeline identity Owner does not change the resource's properties.
Why does creating a project fail on a Foundry resource created with az cognitiveservices account create --kind AIServices and no other options?
Show answer
Projects need the resource to have --allow-project-management true and a managed identity (--assign-identity), which must be set when the resource is created.
Exam Tips
Remember for the exam
- Microsoft.CognitiveServices/accounts with kind AIServices, allowProjectManagement and a managed identity.
- Projects are accounts/projects; deployments are accounts/deployments with a SKU and capacity.
- Chain deployments with dependsOn; pin versions with versionUpgradeOption.
- CLI: --assign-identity and --allow-project-management true are required at creation for projects.