-
Notifications
You must be signed in to change notification settings - Fork 5
/
main.bicep
124 lines (105 loc) · 3.75 KB
/
main.bicep
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
targetScope = 'subscription'
@minLength(1)
@maxLength(64)
@description('Name of the environment that can be used as part of naming resource convention.')
param environmentName string
@minLength(1)
@description('Primary location for all resources.')
param location string
@description('Id of the principal to assign database and application roles.')
param principalId string = ''
// Optional parameters
param cosmosDbAccountName string = ''
param containerRegistryName string = ''
param containerAppsEnvName string = ''
param containerAppsAppName string = ''
param userAssignedIdentityName string = ''
// serviceName is used as value for the tag (azd-service-name) azd uses to identify deployment host
param serviceName string = 'web'
var abbreviations = loadJsonContent('abbreviations.json')
var resourceToken = toLower(uniqueString(subscription().id, environmentName, location))
var tags = {
'azd-env-name': environmentName
repo: 'https://github.com/azure-samples/cosmos-db-nosql-dotnet-quickstart'
}
resource resourceGroup 'Microsoft.Resources/resourceGroups@2022-09-01' = {
name: environmentName
location: location
tags: tags
}
module identity 'app/identity.bicep' = {
name: 'identity'
scope: resourceGroup
params: {
identityName: !empty(userAssignedIdentityName) ? userAssignedIdentityName : '${abbreviations.userAssignedIdentity}-${resourceToken}'
location: location
tags: tags
}
}
module database 'app/database.bicep' = {
name: 'database'
scope: resourceGroup
params: {
accountName: !empty(cosmosDbAccountName) ? cosmosDbAccountName : '${abbreviations.cosmosDbAccount}-${resourceToken}'
location: location
tags: tags
}
}
module data 'app/data.bicep' = {
name: 'data'
scope: resourceGroup
params: {
databaseAccountName: database.outputs.accountName
tags: tags
}
}
module registry 'app/registry.bicep' = {
name: 'registry'
scope: resourceGroup
params: {
registryName: !empty(containerRegistryName) ? containerRegistryName : '${abbreviations.containerRegistry}${resourceToken}'
location: location
tags: tags
}
}
module web 'app/web.bicep' = {
name: serviceName
scope: resourceGroup
params: {
envName: !empty(containerAppsEnvName) ? containerAppsEnvName : '${abbreviations.containerAppsEnv}-${resourceToken}'
appName: !empty(containerAppsAppName) ? containerAppsAppName : '${abbreviations.containerAppsApp}-${resourceToken}'
databaseAccountEndpoint: database.outputs.endpoint
userAssignedManagedIdentity: {
resourceId: identity.outputs.resourceId
clientId: identity.outputs.clientId
}
location: location
tags: tags
serviceTag: serviceName
}
}
module security 'app/security.bicep' = {
name: 'security'
scope: resourceGroup
params: {
databaseAccountName: database.outputs.accountName
appPrincipalId: identity.outputs.principalId
userPrincipalId: !empty(principalId) ? principalId : null
}
}
// Database outputs
output AZURE_COSMOS_ENDPOINT string = database.outputs.endpoint
output AZURE_COSMOS_DATABASE_NAME string = data.outputs.database.name
output AZURE_COSMOS_CONTAINER_NAMES array = map(data.outputs.containers, c => c.name)
// Container outputs
output AZURE_CONTAINER_REGISTRY_ENDPOINT string = registry.outputs.endpoint
output AZURE_CONTAINER_REGISTRY_NAME string = registry.outputs.name
// Application outputs
output AZURE_CONTAINER_APP_ENDPOINT string = web.outputs.endpoint
output AZURE_CONTAINER_ENVIRONMENT_NAME string = web.outputs.envName
// Identity outputs
output AZURE_USER_ASSIGNED_IDENTITY_NAME string = identity.outputs.name
// Security outputs
output AZURE_NOSQL_ROLE_DEFINITION_ID string = security.outputs.roleDefinitions.nosql
// Application environment variables
output AZURE_COSMOS_DB_NOSQL_ENDPOINT string = database.outputs.endpoint