Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions infra/ai-gateway/github-connection.bicep
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
targetScope = 'resourceGroup'

@description('AI Gateway resource name in the current resource group.')
param gatewayName string

@description('AI Gateway default hostname (without scheme).')
param runtimeHostname string

@description('AI Gateway API key resource name.')
param apiKeyName string = 'default'

@description('Resource group containing the Foundry project.')
param foundryAgentsResourceGroupName string

@description('Foundry AI Services account name.')
param foundryAgentsAccountName string

@description('Foundry project name.')
param foundryAgentsProjectName string

#disable-next-line BCP081
resource aiGateway 'Microsoft.ApiManagement/aigateways@2025-09-01-preview' existing = {
name: gatewayName
}

#disable-next-line BCP081
resource runtimeApiKey 'Microsoft.ApiManagement/aigateways/apiKeys@2025-09-01-preview' existing = {
parent: aiGateway
name: apiKeyName
}

module githubConnection '../foundry-agents/github-connection.bicep' = {
name: 'github-connection-${uniqueString(gatewayName, foundryAgentsProjectName)}'
scope: resourceGroup(foundryAgentsResourceGroupName)
params: {
aiServicesName: foundryAgentsAccountName
aiProjectName: foundryAgentsProjectName
gatewayUrl: 'https://${runtimeHostname}'
gatewayApiKey: runtimeApiKey.listSecrets().key
}
}

output connectionId string = githubConnection.outputs.connectionId
output connectionName string = githubConnection.outputs.connectionName
40 changes: 40 additions & 0 deletions infra/ai-gateway/monitoring.bicep
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
targetScope = 'resourceGroup'

param location string
param tags object = {}
param enableMonitoring bool = true
param appInsightsName string
param logAnalyticsWorkspaceName string

resource logAnalyticsWorkspace 'Microsoft.OperationalInsights/workspaces@2023-09-01' = if (enableMonitoring) {
name: logAnalyticsWorkspaceName
location: location
tags: tags
properties: {
retentionInDays: 30
features: {
enableLogAccessUsingOnlyResourcePermissions: true
}
sku: {
name: 'PerGB2018'
}
}
}

resource appInsights 'Microsoft.Insights/components@2020-02-02' = if (enableMonitoring) {
name: appInsightsName
location: location
kind: 'web'
tags: tags
properties: {
Application_Type: 'web'
WorkspaceResourceId: logAnalyticsWorkspace.id
#disable-next-line BCP037
AzureMonitorWorkspaceIngestionMode: 'Enabled'
}
}

output appInsightsId string = enableMonitoring ? appInsights.id : ''
output appInsightsName string = enableMonitoring ? appInsights.name : ''
output logAnalyticsWorkspaceId string = enableMonitoring ? logAnalyticsWorkspace.id : ''
output logAnalyticsWorkspaceName string = enableMonitoring ? logAnalyticsWorkspace.name : ''
64 changes: 64 additions & 0 deletions infra/avm/res/api-management/aigateway/api-key/main.bicep
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
metadata name = 'AI Gateway API Key'
metadata description = 'Configures a gateway-level API key without returning its secret values.'

@description('Required. Parent gateway name.')
param aiGatewayName string
@description('Required. API key resource name.')
param name string
@description('Optional. API key properties.')
param properties apiKeyPropertiesType = {}
@secure()
@description('Optional. Secure values for explicit primary and secondary key references.')
param secrets { *: string } = {}

#disable-next-line BCP081
resource gateway 'Microsoft.ApiManagement/aigateways@2025-09-01-preview' existing = {
name: aiGatewayName
}
#disable-next-line BCP081
resource apiKey 'Microsoft.ApiManagement/aigateways/apiKeys@2025-09-01-preview' = {
name: name
parent: gateway
properties: union(
{
displayName: properties.?displayName
state: properties.?state
expirationDate: properties.?expirationDate
},
properties.?primaryKeySecretName == null
? {}
: {
primaryKey: secrets[properties.primaryKeySecretName!]
},
properties.?secondaryKeySecretName == null
? {}
: {
secondaryKey: secrets[properties.secondaryKeySecretName!]
}
)
}

@description('The API key resource ID, not the key value.')
output resourceId string = apiKey.id
@description('The API key resource name.')
output name string = apiKey.name
@description('The resource group name.')
output resourceGroupName string = resourceGroup().name

@export()
@sealed()
@description('API key resource configuration.')
type apiKeyType = {
name: string
properties: apiKeyPropertiesType?
}
@export()
@sealed()
@description('API key metadata and optional secure input references.')
type apiKeyPropertiesType = {
displayName: string?
state: string?
expirationDate: string?
primaryKeySecretName: string?
secondaryKeySecretName: string?
}
Loading
Loading