Skip to content

Commit f218f2c

Browse files
added dns for exisiting project
1 parent db5227a commit f218f2c

File tree

3 files changed

+133
-59
lines changed

3 files changed

+133
-59
lines changed

infra/main.bicep

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,46 @@ module existingAiFoundryAiServicesDeployments 'modules/ai-services-deployments.b
479479
}
480480
}
481481

482+
// ========== Private Endpoint for Existing AI Services ========== //
483+
// Always create private endpoint when using existing AI Services with private networking enabled
484+
var shouldCreatePrivateEndpoint = useExistingAiFoundryAiProject && enablePrivateNetworking
485+
486+
// Use existing DNS zones if provided, otherwise use newly created ones
487+
var privateDnsZoneIds = {
488+
cognitiveServices: avmPrivateDnsZones[dnsZoneIndex.cognitiveServices]!.outputs.resourceId
489+
openAI: avmPrivateDnsZones[dnsZoneIndex.openAI]!.outputs.resourceId
490+
aiServices: avmPrivateDnsZones[dnsZoneIndex.aiServices]!.outputs.resourceId
491+
}
492+
493+
module existingAiServicesPrivateEndpoint 'modules/private-endpoint.bicep' = if (shouldCreatePrivateEndpoint) {
494+
name: take('module.private-endpoint.${existingAiFoundryAiServices.name}', 64)
495+
scope: resourceGroup()
496+
params: {
497+
name: 'pep-${existingAiFoundryAiServices.name}'
498+
location: location
499+
subnetResourceId: network!.outputs.subnetPrivateEndpointsResourceId
500+
targetResourceId: existingAiFoundryAiServices.id
501+
groupIds: ['account']
502+
customNetworkInterfaceName: 'nic-${existingAiFoundryAiServices.name}'
503+
tags: tags
504+
privateDnsZoneGroupConfigs: [
505+
{
506+
name: 'ai-services-dns-zone-cognitiveservices'
507+
privateDnsZoneResourceId: privateDnsZoneIds.cognitiveServices
508+
}
509+
{
510+
name: 'ai-services-dns-zone-openai'
511+
privateDnsZoneResourceId: privateDnsZoneIds.openAI
512+
}
513+
{
514+
name: 'ai-services-dns-zone-aiservices'
515+
privateDnsZoneResourceId: privateDnsZoneIds.aiServices
516+
}
517+
]
518+
}
519+
}
520+
521+
482522
module aiFoundryAiServices 'br:mcr.microsoft.com/bicep/avm/res/cognitive-services/account:0.13.2' = if (!useExistingAiFoundryAiProject) {
483523
name: take('avm.res.cognitive-services.account.${aiFoundryAiServicesResourceName}', 64)
484524
params: {
@@ -584,7 +624,7 @@ module aiFoundryAiServicesProject 'modules/ai-project.bicep' = if (!useExistingA
584624
}
585625

586626
var aiFoundryAiProjectEndpoint = useExistingAiFoundryAiProject
587-
? existingAiFoundryAiServicesProject!.properties.endpoints['AI Foundry API']
627+
? 'https://${aiFoundryAiServicesResourceName}.services.ai.azure.com/api/projects/${aiFoundryAiProjectResourceName}'
588628
: aiFoundryAiServicesProject!.outputs.apiEndpoint
589629

590630
// ========== Search Service to AI Services Role Assignment ========== //
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
// ========== Private Endpoint Module ========== //
2+
@description('Name of the private endpoint')
3+
param name string
4+
5+
@description('Location for the private endpoint')
6+
param location string = resourceGroup().location
7+
8+
@description('Subnet resource ID where the private endpoint will be created')
9+
param subnetResourceId string
10+
11+
@description('Resource ID of the target resource for the private endpoint')
12+
param targetResourceId string
13+
14+
@description('Group IDs for the private endpoint connection')
15+
param groupIds array = ['account']
16+
17+
@description('Custom network interface name for the private endpoint')
18+
param customNetworkInterfaceName string = ''
19+
20+
@description('Private DNS zone group configurations')
21+
param privateDnsZoneGroupConfigs array = []
22+
23+
@description('Tags to apply to the private endpoint')
24+
param tags object = {}
25+
26+
// ========== Private Endpoint Resource ========== //
27+
resource privateEndpoint 'Microsoft.Network/privateEndpoints@2024-05-01' = {
28+
name: name
29+
location: location
30+
tags: tags
31+
properties: {
32+
subnet: {
33+
id: subnetResourceId
34+
}
35+
privateLinkServiceConnections: [
36+
{
37+
name: name
38+
properties: {
39+
privateLinkServiceId: targetResourceId
40+
groupIds: groupIds
41+
}
42+
}
43+
]
44+
customNetworkInterfaceName: !empty(customNetworkInterfaceName) ? customNetworkInterfaceName : null
45+
}
46+
}
47+
48+
// ========== Private DNS Zone Group ========== //
49+
resource privateDnsZoneGroup 'Microsoft.Network/privateEndpoints/privateDnsZoneGroups@2024-05-01' = if (!empty(privateDnsZoneGroupConfigs)) {
50+
name: 'default'
51+
parent: privateEndpoint
52+
properties: {
53+
privateDnsZoneConfigs: [
54+
for config in privateDnsZoneGroupConfigs: {
55+
name: config.name
56+
properties: {
57+
privateDnsZoneId: config.privateDnsZoneResourceId
58+
}
59+
}
60+
]
61+
}
62+
}
63+
64+
// ========== Outputs ========== //
65+
@description('Resource ID of the private endpoint')
66+
output resourceId string = privateEndpoint.id
67+
68+
@description('Name of the private endpoint')
69+
output name string = privateEndpoint.name
70+
71+
@description('Location of the private endpoint')
72+
output location string = privateEndpoint.location
73+
74+
@description('Network interface resource IDs associated with the private endpoint')
75+
output networkInterfaceResourceIds array = privateEndpoint.properties.networkInterfaces

infra/scripts/process_sample_data.sh

Lines changed: 17 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -12,34 +12,30 @@ aif_resource_id="${8}"
1212

1313
# Global variables to track original network access states
1414
original_storage_public_access=""
15-
original_storage_default_action=""
1615
original_keyvault_public_access=""
1716
original_foundry_public_access=""
1817
aif_resource_group=""
1918
aif_account_resource_id=""
19+
aif_subscription_id=""
2020

2121
# Function to enable public network access temporarily
2222
enable_public_access() {
2323
echo "=== Temporarily enabling public network access for services ==="
2424

2525
# Enable public access for Storage Account
26-
echo "Enabling public access for Storage Account: $storageAccount"
2726
original_storage_public_access=$(az storage account show \
2827
--name "$storageAccount" \
2928
--resource-group "$resourceGroupName" \
3029
--query "publicNetworkAccess" \
3130
-o tsv)
32-
original_storage_default_action=$(az storage account show \
33-
--name "$storageAccount" \
34-
--resource-group "$resourceGroupName" \
35-
--query "networkRuleSet.defaultAction" \
36-
-o tsv)
3731

3832
if [ "$original_storage_public_access" != "Enabled" ]; then
33+
echo "Enabling public access for Storage Account: $storageAccount"
3934
az storage account update \
4035
--name "$storageAccount" \
4136
--resource-group "$resourceGroupName" \
4237
--public-network-access Enabled \
38+
--default-action Allow \
4339
--output none
4440
if [ $? -eq 0 ]; then
4541
echo "✓ Storage Account public access enabled"
@@ -50,46 +46,28 @@ enable_public_access() {
5046
else
5147
echo "✓ Storage Account public access already enabled"
5248
fi
53-
54-
# Also ensure the default network action allows access
55-
if [ "$original_storage_default_action" != "Allow" ]; then
56-
echo "Setting Storage Account network default action to Allow"
57-
az storage account update \
58-
--name "$storageAccount" \
59-
--resource-group "$resourceGroupName" \
60-
--default-action Allow \
61-
--output none
62-
if [ $? -eq 0 ]; then
63-
echo "✓ Storage Account network default action set to Allow"
64-
else
65-
echo "✗ Failed to set Storage Account network default action"
66-
return 1
67-
fi
68-
else
69-
echo "✓ Storage Account network default action already set to Allow"
70-
fi
7149

7250
# Enable public access for AI Foundry
73-
# Extract the account resource ID (remove /projects/... part if present)
7451
aif_account_resource_id=$(echo "$aif_resource_id" | sed 's|/projects/.*||')
75-
aif_resource_name=$(basename "$aif_account_resource_id")
76-
# Extract resource group from the AI Foundry account resource ID
7752
aif_resource_group=$(echo "$aif_account_resource_id" | sed -n 's|.*/resourceGroups/\([^/]*\)/.*|\1|p')
78-
79-
original_foundry_public_access=$(az cognitiveservices account show \
80-
--name "$aif_resource_name" \
81-
--resource-group "$aif_resource_group" \
53+
# Extract subscription ID from AI Foundry resource ID
54+
aif_subscription_id=$(echo "$aif_account_resource_id" | sed -n 's|.*/subscriptions/\([^/]*\)/.*|\1|p')
55+
56+
original_foundry_public_access=$(MSYS_NO_PATHCONV=1 az resource show \
57+
--ids "$aif_account_resource_id" \
58+
--subscription "$aif_subscription_id" \
59+
--api-version 2024-10-01 \
8260
--query "properties.publicNetworkAccess" \
8361
--output tsv)
8462
if [ -z "$original_foundry_public_access" ] || [ "$original_foundry_public_access" = "null" ]; then
8563
echo "⚠ Info: Could not retrieve AI Foundry network access status."
8664
echo " AI Foundry network access might be managed differently."
8765
elif [ "$original_foundry_public_access" != "Enabled" ]; then
88-
echo "Current AI Foundry public access: $original_foundry_public_access"
89-
echo "Enabling public access for AI Foundry resource: $aif_resource_name (Resource Group: $aif_resource_group)"
66+
echo "Enabling public access for AI Foundry: $aif_resource_group"
9067
if MSYS_NO_PATHCONV=1 az resource update \
9168
--ids "$aif_account_resource_id" \
9269
--api-version 2024-10-01 \
70+
--subscription "$aif_subscription_id" \
9371
--set properties.publicNetworkAccess=Enabled \
9472
--set properties.apiProperties.qnaAzureSearchEndpointKey="" \
9573
--output none; then
@@ -100,24 +78,21 @@ enable_public_access() {
10078
else
10179
echo "✓ AI Foundry public access already enabled"
10280
fi
103-
104-
# Wait a bit for changes to take effect
105-
echo "Waiting for network access changes to propagate..."
106-
sleep 10
10781

10882
# Enable public access for Key Vault
109-
echo "Enabling public access for Key Vault: $keyvaultName"
11083
original_keyvault_public_access=$(az keyvault show \
11184
--name "$keyvaultName" \
11285
--resource-group "$resourceGroupName" \
11386
--query "properties.publicNetworkAccess" \
11487
-o tsv)
11588

11689
if [ "$original_keyvault_public_access" != "Enabled" ]; then
90+
echo "Enabling public access for Key Vault: $keyvaultName"
11791
az keyvault update \
11892
--name "$keyvaultName" \
11993
--resource-group "$resourceGroupName" \
12094
--public-network-access Enabled \
95+
--default-action Allow \
12196
--output none
12297
if [ $? -eq 0 ]; then
12398
echo "✓ Key Vault public access enabled"
@@ -131,7 +106,6 @@ enable_public_access() {
131106

132107
# Additional wait for all changes to propagate fully
133108
echo "Allowing additional time for all network access changes to propagate..."
134-
echo "Note: Changes may take up to 5 minutes to fully appear in Azure Portal"
135109
sleep 30
136110
echo "=== Public network access configuration completed ==="
137111
return 0
@@ -154,6 +128,7 @@ restore_network_access() {
154128
--name "$storageAccount" \
155129
--resource-group "$resourceGroupName" \
156130
--public-network-access "$restore_value" \
131+
--default-action Deny \
157132
--output none
158133
if [ $? -eq 0 ]; then
159134
echo "✓ Storage Account access restored"
@@ -164,23 +139,6 @@ restore_network_access() {
164139
echo "Storage Account access unchanged (already at desired state)"
165140
fi
166141

167-
# Restore Storage Account network default action
168-
if [ -n "$original_storage_default_action" ] && [ "$original_storage_default_action" != "Allow" ]; then
169-
echo "Restoring Storage Account network default action to: $original_storage_default_action"
170-
az storage account update \
171-
--name "$storageAccount" \
172-
--resource-group "$resourceGroupName" \
173-
--default-action "$original_storage_default_action" \
174-
--output none
175-
if [ $? -eq 0 ]; then
176-
echo "✓ Storage Account network default action restored"
177-
else
178-
echo "✗ Failed to restore Storage Account network default action"
179-
fi
180-
else
181-
echo "Storage Account network default action unchanged (already at desired state)"
182-
fi
183-
184142
# Restore Key Vault access
185143
if [ -n "$original_keyvault_public_access" ] && [ "$original_keyvault_public_access" != "Enabled" ]; then
186144
echo "Restoring Key Vault public access to: $original_keyvault_public_access"
@@ -194,6 +152,7 @@ restore_network_access() {
194152
--name "$keyvaultName" \
195153
--resource-group "$resourceGroupName" \
196154
--public-network-access "$restore_value" \
155+
--default-action Deny \
197156
--output none
198157
if [ $? -eq 0 ]; then
199158
echo "✓ Key Vault access restored"
@@ -211,6 +170,7 @@ restore_network_access() {
211170
if MSYS_NO_PATHCONV=1 az resource update \
212171
--ids "$aif_account_resource_id" \
213172
--api-version 2024-10-01 \
173+
--subscription "$aif_subscription_id" \
214174
--set properties.publicNetworkAccess="$original_foundry_public_access" \
215175
--set properties.apiProperties.qnaAzureSearchEndpointKey="" \
216176
--set properties.networkAcls.bypass="AzureServices" \
@@ -272,7 +232,6 @@ if [ -z "$aif_resource_id" ]; then
272232
fi
273233

274234
# Get subscription id from azd env or from environment variable
275-
276235
azSubscriptionId=$(azd env get-value AZURE_SUBSCRIPTION_ID) || azSubscriptionId="$AZURE_SUBSCRIPTION_ID"
277236

278237
# Check if all required arguments are provided

0 commit comments

Comments
 (0)