Skip to content

Commit

Permalink
Azdev-ify changes for latest /bicep/core
Browse files Browse the repository at this point in the history
  • Loading branch information
zedy committed Nov 18, 2022
1 parent c783174 commit 88a2778
Show file tree
Hide file tree
Showing 45 changed files with 762 additions and 633 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -257,5 +257,6 @@ pub/

#Ignore marker-file used to know which docker files we have.
.eshopdocker_*
.devcontainer

.azure
6 changes: 0 additions & 6 deletions azure.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,3 @@ services:
project: ./src/Web
language: csharp
host: appservice
infra:
provider: ""
path: ""
module: ""
pipeline:
provider: ""
31 changes: 31 additions & 0 deletions infra/app/catalog-db.bicep
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
param name string
param location string = resourceGroup().location
param tags object = {}

param databaseName string = 'CatalogDB'
param keyVaultName string

@secure()
param sqlAdminPassword string
@secure()
param appUserPassword string

// Because databaseName is optional in main.bicep, we make sure the database name is set here.
var defaultDatabaseName = 'Todo'
var actualDatabaseName = !empty(databaseName) ? databaseName : defaultDatabaseName

module sqlServer1 '../core/database/sqlserver/sqlserver1.bicep' = {
name: 'sqlServer01'
params: {
name: name
location: location
tags: tags
databaseName: actualDatabaseName
keyVaultName: keyVaultName
sqlAdminPassword: sqlAdminPassword
appUserPassword: appUserPassword
}
}

output sqlCatalogConnectionStringKey string = sqlServer1.outputs.connectionStringKey
output sqlCatalogDatabase1Name string = sqlServer1.outputs.databaseName
25 changes: 0 additions & 25 deletions infra/app/dbCatalog.bicep

This file was deleted.

25 changes: 0 additions & 25 deletions infra/app/dbIdentity.bicep

This file was deleted.

31 changes: 31 additions & 0 deletions infra/app/identity-db.bicep
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
param name string
param location string = resourceGroup().location
param tags object = {}

param databaseName string = 'IdentityDB'
param keyVaultName string

@secure()
param sqlAdminPassword string
@secure()
param appUserPassword string

// Because databaseName is optional in main.bicep, we make sure the database name is set here.
var defaultDatabaseName = 'Todo'
var actualDatabaseName = !empty(databaseName) ? databaseName : defaultDatabaseName

module sqlServer2 '../core/database/sqlserver/sqlserver2.bicep' = {
name: 'sqlServer02'
params: {
name: name
location: location
tags: tags
databaseName: actualDatabaseName
keyVaultName: keyVaultName
sqlAdminPassword: sqlAdminPassword
appUserPassword: appUserPassword
}
}

output sqlCatalogConnectionStringKey string = sqlServer2.outputs.connectionStringKey
output sqlCatalogDatabase1Name string = sqlServer2.outputs.databaseName
23 changes: 14 additions & 9 deletions infra/app/web.bicep
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
param environmentName string
param name string
param location string = resourceGroup().location
param appServicePlanId string

param tags object = {}
param serviceName string = 'web'
param appCommandLine string = 'pm2 serve /home/site/wwwroot --no-daemon --spa'
param applicationInsightsName string = ''
param appServicePlanId string
param appSettings object = {}

module web '../core/host/appservice-dotnet.bicep' = {
name: '${serviceName}-appservice-dotnet-module'
module web '../core/host/appservice.bicep' = {
name: '${name}-deployment'
params: {
environmentName: environmentName
name: name
location: location
appServicePlanId: appServicePlanId
serviceName: serviceName
runtimeName: 'dotnetcore'
runtimeVersion: '6.0'
tags: union(tags, { 'azd-service-name': serviceName })
scmDoBuildDuringDeployment: false
}
}

output WEB_NAME string = web.outputs.name
output WEB_URI string = web.outputs.uri
output REACT_APP_WEB_BASE_URL string = web.outputs.uri
48 changes: 48 additions & 0 deletions infra/core/database/cosmos/cosmos-account.bicep
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
param name string
param location string = resourceGroup().location
param tags object = {}

param connectionStringKey string = 'AZURE-COSMOS-CONNECTION-STRING'
param keyVaultName string

@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' } ]
}
}

resource cosmosConnectionString 'Microsoft.KeyVault/vaults/secrets@2022-07-01' = {
parent: keyVault
name: connectionStringKey
properties: {
value: cosmos.listConnectionStrings().connectionStrings[0].connectionString
}
}

resource keyVault 'Microsoft.KeyVault/vaults@2022-07-01' existing = {
name: keyVaultName
}

output connectionStringKey string = connectionStringKey
output endpoint string = cosmos.properties.documentEndpoint
output id string = cosmos.id
output name string = cosmos.name
22 changes: 22 additions & 0 deletions infra/core/database/cosmos/mongo/cosmos-mongo-account.bicep
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
param name string
param location string = resourceGroup().location
param tags object = {}

param keyVaultName string
param connectionStringKey string = 'AZURE-COSMOS-CONNECTION-STRING'

module cosmos '../../cosmos/cosmos-account.bicep' = {
name: 'cosmos-account'
params: {
name: name
location: location
connectionStringKey: connectionStringKey
keyVaultName: keyVaultName
kind: 'MongoDB'
tags: tags
}
}

output connectionStringKey string = cosmos.outputs.connectionStringKey
output endpoint string = cosmos.outputs.endpoint
output id string = cosmos.outputs.id
46 changes: 46 additions & 0 deletions infra/core/database/cosmos/mongo/cosmos-mongo-db.bicep
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
param accountName string
param databaseName string
param location string = resourceGroup().location
param tags object = {}

param collections array = []
param connectionStringKey string = 'AZURE-COSMOS-CONNECTION-STRING'
param keyVaultName string

module cosmos 'cosmos-mongo-account.bicep' = {
name: 'cosmos-mongo-account'
params: {
name: accountName
location: location
keyVaultName: keyVaultName
tags: tags
connectionStringKey: connectionStringKey
}
}

resource database 'Microsoft.DocumentDB/databaseAccounts/mongodbDatabases@2022-08-15' = {
name: '${accountName}/${databaseName}'
tags: tags
properties: {
resource: { id: databaseName }
}

resource list 'collections' = [for collection in collections: {
name: collection.name
properties: {
resource: {
id: collection.id
shardKey: { _id: collection.shardKey }
indexes: [ { key: { keys: [ collection.indexKey ] } } ]
}
}
}]

dependsOn: [
cosmos
]
}

output connectionStringKey string = connectionStringKey
output databaseName string = databaseName
output endpoint string = cosmos.outputs.endpoint
21 changes: 21 additions & 0 deletions infra/core/database/cosmos/sql/cosmos-sql-account.bicep
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
param name string
param location string = resourceGroup().location
param tags object = {}

param keyVaultName string

module cosmos '../../cosmos/cosmos-account.bicep' = {
name: 'cosmos-account'
params: {
name: name
location: location
tags: tags
keyVaultName: keyVaultName
kind: 'GlobalDocumentDB'
}
}

output connectionStringKey string = cosmos.outputs.connectionStringKey
output endpoint string = cosmos.outputs.endpoint
output id string = cosmos.outputs.id
output name string = cosmos.outputs.name
73 changes: 73 additions & 0 deletions infra/core/database/cosmos/sql/cosmos-sql-db.bicep
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
param accountName string
param databaseName string
param location string = resourceGroup().location
param tags object = {}

param containers array = []
param keyVaultName string
param principalIds array = []

module cosmos 'cosmos-sql-account.bicep' = {
name: 'cosmos-sql-account'
params: {
name: accountName
location: location
tags: tags
keyVaultName: keyVaultName
}
}

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 roleDefintion '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: roleDefintion.outputs.id
principalId: principalId
}
dependsOn: [
cosmos
database
]
}]

output accountId string = cosmos.outputs.id
output accountName string = cosmos.outputs.name
output connectionStringKey string = cosmos.outputs.connectionStringKey
output databaseName string = databaseName
output endpoint string = cosmos.outputs.endpoint
output roleDefinitionId string = roleDefintion.outputs.id
Loading

0 comments on commit 88a2778

Please sign in to comment.