forked from microsoft/sample-app-aoai-chatGPT
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update azd flow for vectors and CosmosDB (microsoft#210)
- Loading branch information
Showing
20 changed files
with
319 additions
and
56 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
metadata description = 'Creates an Azure Cosmos DB account.' | ||
param name string | ||
param location string = resourceGroup().location | ||
param tags object = {} | ||
|
||
@allowed([ 'GlobalDocumentDB', 'MongoDB', 'Parse' ]) | ||
param kind string | ||
|
||
resource cosmos 'Microsoft.DocumentDB/databaseAccounts@2022-08-15' = { | ||
name: name | ||
kind: kind | ||
location: location | ||
tags: tags | ||
properties: { | ||
consistencyPolicy: { defaultConsistencyLevel: 'Session' } | ||
locations: [ | ||
{ | ||
locationName: location | ||
failoverPriority: 0 | ||
isZoneRedundant: false | ||
} | ||
] | ||
databaseAccountOfferType: 'Standard' | ||
enableAutomaticFailover: false | ||
enableMultipleWriteLocations: false | ||
apiProperties: (kind == 'MongoDB') ? { serverVersion: '4.0' } : {} | ||
capabilities: [ { name: 'EnableServerless' } ] | ||
} | ||
} | ||
|
||
output endpoint string = cosmos.properties.documentEndpoint | ||
output id string = cosmos.id | ||
output name string = cosmos.name |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
metadata description = 'Creates an Azure Cosmos DB for NoSQL account.' | ||
param name string | ||
param location string = resourceGroup().location | ||
param tags object = {} | ||
|
||
module cosmos '../../cosmos/cosmos-account.bicep' = { | ||
name: 'cosmos-account' | ||
params: { | ||
name: name | ||
location: location | ||
tags: tags | ||
kind: 'GlobalDocumentDB' | ||
} | ||
} | ||
|
||
output endpoint string = cosmos.outputs.endpoint | ||
output id string = cosmos.outputs.id | ||
output name string = cosmos.outputs.name |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
metadata description = 'Creates an Azure Cosmos DB for NoSQL account with a database.' | ||
param accountName string | ||
param databaseName string | ||
param location string = resourceGroup().location | ||
param tags object = {} | ||
|
||
param containers array = [] | ||
param principalIds array = [] | ||
|
||
module cosmos 'cosmos-sql-account.bicep' = { | ||
name: 'cosmos-sql-account' | ||
params: { | ||
name: accountName | ||
location: location | ||
tags: tags | ||
} | ||
} | ||
|
||
resource database 'Microsoft.DocumentDB/databaseAccounts/sqlDatabases@2022-05-15' = { | ||
name: '${accountName}/${databaseName}' | ||
properties: { | ||
resource: { id: databaseName } | ||
} | ||
|
||
resource list 'containers' = [for container in containers: { | ||
name: container.name | ||
properties: { | ||
resource: { | ||
id: container.id | ||
partitionKey: { paths: [ container.partitionKey ] } | ||
} | ||
options: {} | ||
} | ||
}] | ||
|
||
dependsOn: [ | ||
cosmos | ||
] | ||
} | ||
|
||
module roleDefinition 'cosmos-sql-role-def.bicep' = { | ||
name: 'cosmos-sql-role-definition' | ||
params: { | ||
accountName: accountName | ||
} | ||
dependsOn: [ | ||
cosmos | ||
database | ||
] | ||
} | ||
|
||
// We need batchSize(1) here because sql role assignments have to be done sequentially | ||
@batchSize(1) | ||
module userRole 'cosmos-sql-role-assign.bicep' = [for principalId in principalIds: if (!empty(principalId)) { | ||
name: 'cosmos-sql-user-role-${uniqueString(principalId)}' | ||
params: { | ||
accountName: accountName | ||
roleDefinitionId: roleDefinition.outputs.id | ||
principalId: principalId | ||
} | ||
dependsOn: [ | ||
cosmos | ||
database | ||
] | ||
}] | ||
|
||
output accountId string = cosmos.outputs.id | ||
output accountName string = cosmos.outputs.name | ||
output databaseName string = databaseName | ||
output endpoint string = cosmos.outputs.endpoint | ||
output roleDefinitionId string = roleDefinition.outputs.id |
19 changes: 19 additions & 0 deletions
19
infra/core/database/cosmos/sql/cosmos-sql-role-assign.bicep
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
metadata description = 'Creates a SQL role assignment under an Azure Cosmos DB account.' | ||
param accountName string | ||
|
||
param roleDefinitionId string | ||
param principalId string = '' | ||
|
||
resource role 'Microsoft.DocumentDB/databaseAccounts/sqlRoleAssignments@2022-05-15' = { | ||
parent: cosmos | ||
name: guid(roleDefinitionId, principalId, cosmos.id) | ||
properties: { | ||
principalId: principalId | ||
roleDefinitionId: roleDefinitionId | ||
scope: cosmos.id | ||
} | ||
} | ||
|
||
resource cosmos 'Microsoft.DocumentDB/databaseAccounts@2022-08-15' existing = { | ||
name: accountName | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
metadata description = 'Creates a SQL role definition under an Azure Cosmos DB account.' | ||
param accountName string | ||
|
||
resource roleDefinition 'Microsoft.DocumentDB/databaseAccounts/sqlRoleDefinitions@2022-08-15' = { | ||
parent: cosmos | ||
name: guid(cosmos.id, accountName, 'sql-role') | ||
properties: { | ||
assignableScopes: [ | ||
cosmos.id | ||
] | ||
permissions: [ | ||
{ | ||
dataActions: [ | ||
'Microsoft.DocumentDB/databaseAccounts/readMetadata' | ||
'Microsoft.DocumentDB/databaseAccounts/sqlDatabases/containers/items/*' | ||
'Microsoft.DocumentDB/databaseAccounts/sqlDatabases/containers/*' | ||
] | ||
notDataActions: [] | ||
} | ||
] | ||
roleName: 'Reader Writer' | ||
type: 'CustomRole' | ||
} | ||
} | ||
|
||
resource cosmos 'Microsoft.DocumentDB/databaseAccounts@2022-08-15' existing = { | ||
name: accountName | ||
} | ||
|
||
output id string = roleDefinition.id |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
param accountName string | ||
param location string = resourceGroup().location | ||
param tags object = {} | ||
|
||
param databaseName string = 'db_conversation_history' | ||
param collectionName string = 'conversations' | ||
param principalIds array = [] | ||
|
||
param containers array = [ | ||
{ | ||
name: collectionName | ||
id: collectionName | ||
partitionKey: '/id' | ||
} | ||
] | ||
|
||
module cosmos 'core/database/cosmos/sql/cosmos-sql-db.bicep' = { | ||
name: 'cosmos-sql' | ||
params: { | ||
accountName: accountName | ||
databaseName: databaseName | ||
location: location | ||
containers: containers | ||
tags: tags | ||
principalIds: principalIds | ||
} | ||
} | ||
|
||
|
||
output databaseName string = cosmos.outputs.databaseName | ||
output containerName string = containers[0].name | ||
output accountName string = cosmos.outputs.accountName | ||
output endpoint string = cosmos.outputs.endpoint |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.