Your Terraform pipeline is green. The deployment completes without errors. You grab a coffee.
Ten minutes later you test the new RAG application and it throws 403 Forbidden. In the Azure Portal, under the OpenAI account’s Networking tab, the Shared Private Link from AI Search sits in Pending. Nobody told Terraform to approve it, and nobody told you it needed approving.
This breaks CI/CD for every team deploying a private RAG stack in a governed Azure tenant. Below: how to approve the pending connection from Terraform, replace static API keys with Identity Chaining, and wire up Private DNS so the stack passes a Zero-Trust audit.
Get the free Private Endpoint module on GitHub
The Two Failure Modes of Enterprise AI Deployments
Deploying OpenAI and AI Search in a sandbox takes an afternoon. Locking them down in an enterprise tenant with public_network_access_enabled = false and an active compliance framework is a different job. Two things reliably break a standard Terraform deployment.
1. The Pending Deadlock
AI Search has to call OpenAI to vectorize data. The azurerm provider can request the Shared Private Link connection, but it cannot approve it. The target resource (OpenAI) has to accept the inbound connection explicitly, and azurerm has no resource for approving inbound Cognitive Services connections. The pipeline stalls until someone clicks “Approve” in the Portal, which defeats the point of CI/CD.
2. The Public PaaS Trap
Once you set public_network_access_enabled = false and local_auth_enabled = false, the AI services disappear from the internet. If Private Endpoints, Private DNS and Managed Identities don’t line up exactly in Terraform, the application breaks without a useful error, and debugging a 403 against a private endpoint with no public access is painful.
Target Architecture
┌──────────────────────────────────────────────────────────────┐
│ Isolated AI VNet │
│ │
│ ┌─────────────────────┐ ┌────────────────────┐ │
│ │ Azure AI Search │ │ Azure OpenAI │ │
│ │ (Vector Database) │════════════▶│ (LLM & Embeddings) │ │
│ │ │ Shared Link │ │ │
│ │ [System Identity] │ Approved │ [Local Auth: OFF] │ │
│ └───────┬─────────────┘ └──────────┬─────────┘ │
│ │ RBAC: Cognitive Services OpenAI User │ │
│ └───────────────────────────────────────┘ │
│ ▼ ▼ │
│ [Private Endpoint] [Private Endpoint] │
└──────────┼─────────────────────────────────────┼─────────────┘
▼ ▼
privatelink.search.windows.net privatelink.openai.azure.com
Three engineering decisions make this work:
- AzAPI state machine: finds the Shared Private Link’s connection at runtime and approves it, no Portal access
- Identity Chaining: AI Search authenticates to OpenAI via Managed Identity, no static keys
- Private DNS: both services resolve to private IPs inside the VNet
Step 1: The AzAPI Auto-Approve State Machine
To break the Pending deadlock, we bypass azurerm and talk to the Azure Resource Manager REST API directly with the azapi provider. The snippets below target azapi 2.x (version = "~> 2.0"), where data source output is an object and body takes plain HCL. On azapi 1.x you would wrap output in jsondecode() and body in jsonencode().
Azure generates a random GUID for the incoming connection on the OpenAI side. We can’t hardcode that ID, so we read it at runtime in two steps.
First, request the Shared Private Link with a distinctive request_message, then read all Private Endpoint Connections on the OpenAI account:
resource "azurerm_search_shared_private_link_service" "openai_link" {
name = "spl-openai"
search_service_id = azurerm_search_service.search.id
subresource_name = "openai_account"
target_resource_id = azurerm_cognitive_account.openai.id
request_message = "terraform-spl-openai"
}
data "azapi_resource_list" "pe_connections" {
type = "Microsoft.CognitiveServices/accounts/privateEndpointConnections@2023-05-01"
parent_id = azurerm_cognitive_account.openai.id
response_export_values = ["value"]
depends_on = [
azurerm_search_shared_private_link_service.openai_link
]
}
The depends_on matters. Without it, Terraform can query the connection list before the Shared Private Link has been requested and get an empty list.
Second, pick out our connection and approve it:
locals {
spl_connection_ids = [
for conn in data.azapi_resource_list.pe_connections.output.value : conn.id
if conn.properties.privateLinkServiceConnectionState.description ==
azurerm_search_shared_private_link_service.openai_link.request_message
]
}
resource "azapi_update_resource" "approve_shared_link" {
type = "Microsoft.CognitiveServices/accounts/privateEndpointConnections@2023-05-01"
resource_id = one(local.spl_connection_ids)
body = {
properties = {
privateLinkServiceConnectionState = {
status = "Approved"
description = azurerm_search_shared_private_link_service.openai_link.request_message
}
}
}
}
Two details make this hold up beyond the first apply.
The filter matches on the request message, not on status == "Pending". After the first apply the connection is Approved, so a Pending filter would return an empty list on every later plan. For the same reason, the approval keeps the request message as its description, so the filter still finds the connection next time.
one() returns the single matching ID and fails loudly if there is none. An earlier version of this snippet wrapped the lookup in try(..., "") to fall back to an empty string. That doesn’t work: azapi rejects an empty resource_id as an invalid resource ID, so the run fails anyway, just with a less useful message. If no connection matches, you want the apply to stop, not an approval step that silently does nothing. Destroy needs no special handling: Terraform destroys the approval resource before the Shared Private Link it depends on, and destroying an azapi_update_resource only removes it from state.
After terraform apply, the link moves from Pending to Approved in under 30 seconds, without anyone opening the Portal.
Step 2: Identity Chaining - Killing Static API Keys
Approving the link lets AI Search reach OpenAI. If static admin_keys authenticate that traffic, you will fail a compliance audit. Keys leak, keys get committed to Git, and keys get rotated by someone else at 3am on a Friday.
The alternative is Identity Chaining: AI Search authenticates to OpenAI with its own Entra ID identity instead of a shared secret.
First, give AI Search a System Assigned Managed Identity and explicitly disable local authentication:
resource "azurerm_search_service" "search" {
name = var.search_service_name
resource_group_name = var.resource_group_name
location = var.location
sku = "standard"
public_network_access_enabled = false
local_authentication_enabled = false # No API keys - ever
identity {
type = "SystemAssigned"
}
}
Then grant that identity exactly the permissions it needs on OpenAI and nothing more:
resource "azurerm_role_assignment" "search_to_openai" {
scope = azurerm_cognitive_account.openai.id
role_definition_name = "Cognitive Services OpenAI User"
principal_id = azurerm_search_service.search.identity[0].principal_id
}
Cognitive Services OpenAI User is the least-privileged role for this case: AI Search can call the inference and embeddings APIs but cannot change the OpenAI account configuration. ISO 27001 Annex A.8 and NIS2 Article 21 both expect least-privilege access control of this kind.
When the AI Search instance is deleted, its system-assigned identity goes with it, and the role assignment no longer grants anything. There is no credential to rotate and no secret to store.
Step 3: Private DNS - The Last Trap
The last failure mode is DNS. Private Endpoints only work if clients resolve the service name to the endpoint’s private IP. If your-instance.openai.azure.com still resolves to the public IP because the Private DNS Zone isn’t linked to your VNet, the request goes to the public endpoint, which rejects it (public access is disabled), and you get another opaque 403.
Both services need their own Private DNS Zone linked to the VNet:
resource "azurerm_private_dns_zone" "openai_dns" {
name = "privatelink.openai.azure.com"
resource_group_name = var.resource_group_name
}
resource "azurerm_private_dns_zone" "search_dns" {
name = "privatelink.search.windows.net"
resource_group_name = var.resource_group_name
}
resource "azurerm_private_dns_zone_virtual_network_link" "openai_vnet_link" {
name = "link-openai-vnet"
resource_group_name = var.resource_group_name
private_dns_zone_name = azurerm_private_dns_zone.openai_dns.name
virtual_network_id = azurerm_virtual_network.vnet.id
registration_enabled = false
}
resource "azurerm_private_dns_zone_virtual_network_link" "search_vnet_link" {
name = "link-search-vnet"
resource_group_name = var.resource_group_name
private_dns_zone_name = azurerm_private_dns_zone.search_dns.name
virtual_network_id = azurerm_virtual_network.vnet.id
registration_enabled = false
}
registration_enabled = false is intentional. Auto-registration is for VM records and has no place in centrally managed Private DNS Zones in Hub & Spoke environments. Inside an existing Hub & Spoke topology, the DNS zones belong in the Hub and get linked across subscriptions, not deployed per workload.
The Result
With the AzAPI approval step, Identity Chaining and Private DNS in place, the stack:
- Deploys end-to-end without any manual Portal approval
- Uses no static API keys; authentication is identity-based
- Has no public network exposure
- Satisfies ISO 27001 Annex A.8 and NIS2 Article 21 network and identity controls
The AzAPI approval pattern is worth knowing if you’re stuck on a Shared Private Link that won’t leave Pending; the same lookup-and-approve approach works for other private endpoint connections that need approval on the target side. The shipped module goes further and drops the workaround: instead of a Shared Private Link that needs programmatic approval, it puts both services behind Private Endpoints and has AI Search authenticate to OpenAI via Managed Identity and RBAC. With nothing pending, there’s no approval step to automate. Private Endpoints, Private DNS and Identity Chaining ship in one free, MIT-licensed module (azurerm only, no azapi).
If the DNS/private-networking side of this is the unfamiliar part, Netzwerke: Verstehen, Einrichten, Administrieren* covers the underlying concepts well.