Skip to content

Commit a1f8bb7

Browse files
author
sethsteenken
committed
Merge branch 'feat/addPostgreFabricMirror' of https://github.com/microsoft/Deploy-Your-AI-Application-In-Production into feat/addPostgreFabricMirror
2 parents 2daac4a + e7df29b commit a1f8bb7

6 files changed

Lines changed: 90 additions & 8 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ __pycache__
1414
# Local-only Bicep parameter overrides
1515
infra/*.local.bicepparam
1616
infra/*.local.bicepparam.json
17+
copy.main.bicepparam

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ Supporting documentation
223223
|----------|-------------|
224224
| [Deployment Guide](./docs/DeploymentGuide.md) | Complete deployment instructions |
225225
| [Post Deployment Steps](./docs/post_deployment_steps.md) | Verify your deployment |
226+
| [PostgreSQL Mirroring](./docs/postgresql_mirroring.md) | Create the Fabric connection and mirror PostgreSQL |
226227
| [Parameter Guide](./docs/PARAMETER_GUIDE.md) | Configure deployment parameters |
227228
| [Quota Check Guide](./docs/quota_check.md) | Check Azure OpenAI quota availability |
228229

docs/postgresql_mirroring.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# PostgreSQL Mirroring to Fabric
2+
3+
This guide explains how to complete PostgreSQL mirroring in Microsoft Fabric after deployment.
4+
5+
## Why a Fabric Connection Is Required
6+
7+
The Fabric mirroring API requires a Fabric "connection" object that stores the PostgreSQL endpoint and credentials. The mirror call only accepts a `connectionId` and database name, so a valid Fabric connection must exist before mirroring can be created.
8+
9+
## Prerequisites
10+
11+
- Deployment finished, and PostgreSQL Flexible Server exists.
12+
- Post-provision prep ran (it creates the `fabric_user` role and sets required PostgreSQL flags).
13+
- You can sign in to Fabric (app.fabric.microsoft.com) with access to the workspace.
14+
15+
## Step 1: Confirm PostgreSQL Details
16+
17+
Get the PostgreSQL server FQDN and database name:
18+
19+
- FQDN: from `azd env get-value postgreSqlServerFqdn`
20+
- Database name: `postgres` (default) or your custom DB
21+
22+
## Step 2: Create the Fabric Connection (UI)
23+
24+
1. Open the Fabric workspace.
25+
2. Go to **Settings** -> **Manage connections and gateways**.
26+
3. Select **New connection** -> **PostgreSQL**.
27+
4. Enter:
28+
- Server: PostgreSQL FQDN
29+
- Database: your database name
30+
- User: `fabric_user`
31+
- Password: value from Key Vault secret `postgres-fabric-user-password`
32+
5. Save and copy the **Connection ID**.
33+
34+
## Step 3: Set the Connection ID in azd
35+
36+
```powershell
37+
azd env set-value fabricPostgresConnectionId "<connection-id>"
38+
azd env set-value POSTGRES_DATABASE_NAME "postgres"
39+
```
40+
41+
## Step 4: Create the Mirror
42+
43+
Run the mirror script:
44+
45+
```powershell
46+
./scripts/automationScripts/FabricWorkspace/Mirror/create_postgresql_mirror.ps1
47+
```
48+
49+
## Verify
50+
51+
- In Fabric, a mirrored database named `pg-mirror-<env>` should appear.
52+
- Re-running the script is safe; it will skip if the mirror already exists.
53+
54+
## Notes
55+
56+
- The deployment now skips the mirror step until a valid Fabric connection exists, so `azd up` will no longer fail on this step.
57+
- If you rotate passwords, update the Fabric connection in the workspace.

infra/main.bicep

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,8 @@ param postgreSqlVersion string = '16'
295295

296296
@description('PostgreSQL storage size in GB.')
297297
param postgreSqlStorageSizeGB int = 32
298+
@description('Generated value used when postgreSqlAdminPassword is left as the placeholder token.')
299+
param generatedPostgreSqlAdminPassword string = newGuid()
298300

299301
// ========================================
300302
// FABRIC CAPACITY DEPLOYMENT
@@ -327,6 +329,10 @@ var effectiveKeyVaultResourceId = !empty(keyVaultResourceId)
327329
? keyVaultResourceId
328330
: resourceId('Microsoft.KeyVault/vaults', keyVaultName)
329331

332+
var effectivePostgreSqlAdminPassword = postgreSqlAdminPassword == '$(secretOrRandomPassword)'
333+
? '${uniqueString(subscription().id, resourceGroup().id, postgreSqlServerName)}!${replace(generatedPostgreSqlAdminPassword, '-', '')}'
334+
: postgreSqlAdminPassword
335+
330336
resource keyVault 'Microsoft.KeyVault/vaults@2023-07-01' existing = {
331337
name: last(split(effectiveKeyVaultResourceId, '/'))
332338
}
@@ -372,7 +378,7 @@ module postgreSqlFlexibleServer 'br/public:avm/res/db-for-postgre-sql/flexible-s
372378
skuName: postgreSqlSkuName
373379
tier: postgreSqlTier
374380
administratorLogin: postgreSqlAdminLogin
375-
administratorLoginPassword: postgreSqlAdminPassword
381+
administratorLoginPassword: effectivePostgreSqlAdminPassword
376382
managedIdentities: {
377383
systemAssigned: true
378384
}
@@ -387,7 +393,7 @@ module postgreSqlFlexibleServer 'br/public:avm/res/db-for-postgre-sql/flexible-s
387393
resource postgreSqlAdminSecret 'Microsoft.KeyVault/vaults/secrets@2023-07-01' = if (deployPostgreSql && enablePostgreSqlKeyVaultSecret) {
388394
name: '${keyVault.name}/${postgreSqlAdminSecretName}'
389395
properties: {
390-
value: postgreSqlAdminPassword
396+
value: effectivePostgreSqlAdminPassword
391397
}
392398
}
393399

infra/main.bicepparam

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ using './main.bicep'
77
param environmentName = readEnvironmentVariable('AZURE_ENV_NAME', '')
88
param location = readEnvironmentVariable('AZURE_LOCATION', '')
99
param cosmosLocation = readEnvironmentVariable('AZURE_COSMOS_LOCATION', '')
10+
// Entra object ID of the identity to grant RBAC (user, group, service principal, or UAI). Set this if Graph lookup is blocked.
11+
param principalId = ''
12+
param principalType = 'User'
1013

1114
// ========================================
1215
// OPTIONAL INPUTS (Existing Resources)
@@ -21,7 +24,7 @@ param useExistingVNet = false
2124
param existingVnetResourceId = readEnvironmentVariable('EXISTING_VNET_RESOURCE_ID', '')
2225

2326
// Optional additional Entra object IDs to grant Search roles.
24-
param aiSearchAdditionalAccessObjectIds = ['b87eb6d7-7812-43b9-815a-223830f60b44']
27+
param aiSearchAdditionalAccessObjectIds = ['']
2528

2629
// ========================================
2730
// OPTIONAL INPUTS (Configuration)
@@ -70,8 +73,8 @@ param postgreSqlStorageSizeGB = 32
7073
// ========================================
7174

7275
param deployGroundingWithBing = false
73-
param deployAiFoundry = false
74-
param deployAiFoundrySubnet = true
76+
param deployAiFoundry = true
77+
param deployAiFoundrySubnet = false
7578
param deployAppConfig = true
7679
param deployKeyVault = true
7780
param deployVmKeyVault = readEnvironmentVariable('DEPLOY_VM_KEY_VAULT', 'true') == 'true'
@@ -90,7 +93,7 @@ param sideBySideDeploy = readEnvironmentVariable('SIDE_BY_SIDE', 'true') == 'tru
9093
param deploySoftware = false
9194
param deployApim = false
9295
param deployAfProject = true
93-
param deployAAfAgentSvc = true
96+
param deployAAfAgentSvc = false
9497
param enableAgenticRetrieval = readEnvironmentVariable('ENABLE_AGENTIC_RETRIEVAL', 'false') == 'true'
9598

9699
// ========================================
@@ -296,14 +299,14 @@ param fabricWorkspaceName = '' // optional (helpful for naming/UX)
296299
param fabricCapacitySku = 'F2'
297300

298301
// Fabric capacity admin members (email addresses or object IDs).
299-
param fabricCapacityAdmins = []
302+
param fabricCapacityAdmins = ['']
300303

301304
// ========================================
302305
// PURVIEW PARAMETERS (Optional)
303306
// ========================================
304307

305308
// Existing Purview account resource ID (in different subscription if needed).
306-
param purviewAccountResourceId = '/subscriptions/48ab3756-f962-40a8-b0cf-b33ddae744bb/resourceGroups/Governance/providers/Microsoft.Purview/accounts/swantekPurview'
309+
param purviewAccountResourceId = ''
307310

308311
// Purview collection name (leave empty to auto-generate from environment name).
309312
param purviewCollectionName = ''

scripts/automationScripts/FabricWorkspace/mirror/create_postgresql_mirror.ps1

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,20 @@ if (-not $fabricToken) { Warn "Cannot acquire Fabric API token; ensure az login.
140140
$fabricHeaders = New-SecureHeaders -Token $fabricToken
141141
$apiRoot = 'https://api.fabric.microsoft.com/v1'
142142

143+
# Guard: skip until the Fabric PostgreSQL connection exists
144+
if ($ConnectionId) {
145+
try {
146+
$connections = Invoke-SecureRestMethod -Uri "$apiRoot/connections" -Headers $fabricHeaders -Method Get -Description "Fabric connections"
147+
$match = $connections.value | Where-Object { $_.id -eq $ConnectionId }
148+
if (-not $match) {
149+
Warn "FABRIC_POSTGRES_CONNECTION_ID not found in Fabric. Create the connection and rerun."
150+
exit 0
151+
}
152+
} catch {
153+
Warn "Unable to validate Fabric connection ID; continuing with mirror attempt."
154+
}
155+
}
156+
143157
if ($postgreSqlSystemAssignedPrincipalId) {
144158
$roleAssignmentBody = @{
145159
principal = @{

0 commit comments

Comments
 (0)