Skip to content

Instantly share code, notes, and snippets.

@pamelafox
Last active February 24, 2025 21:49
Show Gist options
  • Save pamelafox/7023101368d3157eb8dc6b291240ae9d to your computer and use it in GitHub Desktop.
Save pamelafox/7023101368d3157eb8dc6b291240ae9d to your computer and use it in GitHub Desktop.
Azure AI Project/Hub (start with main.bicep)
@minLength(1)
@description('Primary location for all resources')
param location string
@description('The AI Hub resource name.')
param hubName string
@description('The AI Project resource name.')
param projectName string
@description('The Storage Account resource ID.')
param storageAccountId string = ''
@description('The Application Insights resource ID.')
param applicationInsightsId string = ''
@description('The Azure Search resource name.')
param searchServiceName string = ''
@description('The Azure Search connection name.')
param searchConnectionName string = ''
param tags object = {}
module hub './hub.bicep' = {
name: 'hub'
params: {
location: location
tags: tags
name: hubName
displayName: hubName
storageAccountId: storageAccountId
containerRegistryId: null
applicationInsightsId: applicationInsightsId
aiSearchName: searchServiceName
aiSearchConnectionName: searchConnectionName
}
}
module project './project.bicep' = {
name: 'project'
params: {
location: location
tags: tags
name: projectName
displayName: projectName
hubName: hub.outputs.name
}
}
output projectName string = project.outputs.name
@description('The AI Foundry Hub Resource name')
param name string
@description('The display name of the AI Foundry Hub Resource')
param displayName string = name
@description('The storage account ID to use for the AI Foundry Hub Resource')
param storageAccountId string = ''
@description('The application insights ID to use for the AI Foundry Hub Resource')
param applicationInsightsId string = ''
@description('The container registry ID to use for the AI Foundry Hub Resource')
param containerRegistryId string = ''
@description('The Azure Cognitive Search service name to use for the AI Foundry Hub Resource')
param aiSearchName string = ''
@description('The Azure Cognitive Search service connection name to use for the AI Foundry Hub Resource')
param aiSearchConnectionName string = ''
@description('The SKU name to use for the AI Foundry Hub Resource')
param skuName string = 'Basic'
@description('The SKU tier to use for the AI Foundry Hub Resource')
@allowed(['Basic', 'Free', 'Premium', 'Standard'])
param skuTier string = 'Basic'
@description('The public network access setting to use for the AI Foundry Hub Resource')
@allowed(['Enabled','Disabled'])
param publicNetworkAccess string = 'Enabled'
param location string = resourceGroup().location
param tags object = {}
resource hub 'Microsoft.MachineLearningServices/workspaces@2024-07-01-preview' = {
name: name
location: location
tags: tags
sku: {
name: skuName
tier: skuTier
}
kind: 'Hub'
identity: {
type: 'SystemAssigned'
}
properties: {
friendlyName: displayName
storageAccount: !empty(storageAccountId) ? storageAccountId : null
applicationInsights: !empty(applicationInsightsId) ? applicationInsightsId : null
containerRegistry: !empty(containerRegistryId) ? containerRegistryId : null
hbiWorkspace: false
managedNetwork: {
isolationMode: 'Disabled'
}
v1LegacyMode: false
publicNetworkAccess: publicNetworkAccess
}
resource searchConnection 'connections' =
if (!empty(aiSearchName)) {
name: aiSearchConnectionName
properties: {
category: 'CognitiveSearch'
authType: 'ApiKey'
isSharedToAll: true
target: 'https://${search.name}.search.windows.net/'
credentials: {
key: !empty(aiSearchName) ? search.listAdminKeys().primaryKey : ''
}
}
}
}
resource search 'Microsoft.Search/searchServices@2021-04-01-preview' existing =
if (!empty(aiSearchName)) {
name: aiSearchName
}
output name string = hub.name
output id string = hub.id
output principalId string = hub.identity.principalId
// You would create a resourceGroup in your Bicep and a Log Analytics workspace
module ai 'core/ai/ai-environment.bicep' = {
name: 'ai'
scope: resourceGroup
params: {
location: 'swedencentral'
tags: tags
hubName: 'aihub-${resourceToken}'
projectName: 'aiproj-${resourceToken}'
applicationInsightsId: monitoring.outputs.applicationInsightsId
}
}
@description('The AI Foundry Hub Resource name')
param name string
@description('The display name of the AI Foundry Hub Resource')
param displayName string = name
@description('The name of the AI Foundry Hub Resource where this project should be created')
param hubName string
@description('The SKU name to use for the AI Foundry Hub Resource')
param skuName string = 'Basic'
@description('The SKU tier to use for the AI Foundry Hub Resource')
@allowed(['Basic', 'Free', 'Premium', 'Standard'])
param skuTier string = 'Basic'
@description('The public network access setting to use for the AI Foundry Hub Resource')
@allowed(['Enabled','Disabled'])
param publicNetworkAccess string = 'Enabled'
param location string = resourceGroup().location
param tags object = {}
resource project 'Microsoft.MachineLearningServices/workspaces@2024-01-01-preview' = {
name: name
location: location
tags: tags
sku: {
name: skuName
tier: skuTier
}
kind: 'Project'
identity: {
type: 'SystemAssigned'
}
properties: {
friendlyName: displayName
hbiWorkspace: false
v1LegacyMode: false
publicNetworkAccess: publicNetworkAccess
hubResourceId: hub.id
}
}
module mlServiceRoleDataScientist '../security/role.bicep' = {
name: 'ml-service-role-data-scientist'
params: {
principalId: project.identity.principalId
roleDefinitionId: 'f6c7c914-8db3-469d-8ca1-694a8f32e121'
principalType: 'ServicePrincipal'
}
}
module mlServiceRoleSecretsReader '../security/role.bicep' = {
name: 'ml-service-role-secrets-reader'
params: {
principalId: project.identity.principalId
roleDefinitionId: 'ea01e6af-a1c1-4350-9563-ad00f8c72ec5'
principalType: 'ServicePrincipal'
}
}
resource hub 'Microsoft.MachineLearningServices/workspaces@2024-01-01-preview' existing = {
name: hubName
}
output id string = project.id
output name string = project.name
output principalId string = project.identity.principalId
output discoveryUrl string = project.properties.discoveryUrl
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment