-
Notifications
You must be signed in to change notification settings - Fork 170
/
main.bicept
174 lines (158 loc) · 4.71 KB
/
main.bicept
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
{{define "main.bicep" -}}
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
{{range .Parameters}}
{{- if .Secret}}
@secure()
{{- end}}
param {{.Name}} {{.Type}}
{{- end}}
@description('Id of the user or app to assign application roles')
param principalId string
// Tags that should be applied to all resources.
//
// Note that 'azd-service-name' tags should be applied separately to service host resources.
// Example usage:
// tags: union(tags, { 'azd-service-name': <service name in azure.yaml> })
var tags = {
'azd-env-name': environmentName
}
var abbrs = loadJsonContent('./abbreviations.json')
var resourceToken = toLower(uniqueString(subscription().id, environmentName, location))
resource rg 'Microsoft.Resources/resourceGroups@2022-09-01' = {
name: 'rg-${environmentName}'
location: location
tags: tags
}
module monitoring './shared/monitoring.bicep' = {
name: 'monitoring'
params: {
location: location
tags: tags
logAnalyticsName: '${abbrs.operationalInsightsWorkspaces}${resourceToken}'
applicationInsightsName: '${abbrs.insightsComponents}${resourceToken}'
}
scope: rg
}
module dashboard './shared/dashboard-web.bicep' = {
name: 'dashboard'
params: {
name: '${abbrs.portalDashboards}${resourceToken}'
applicationInsightsName: monitoring.outputs.applicationInsightsName
location: location
tags: tags
}
scope: rg
}
module registry './shared/registry.bicep' = {
name: 'registry'
params: {
location: location
tags: tags
name: '${abbrs.containerRegistryRegistries}${resourceToken}'
}
scope: rg
}
module keyVault './shared/keyvault.bicep' = {
name: 'keyvault'
params: {
location: location
tags: tags
name: '${abbrs.keyVaultVaults}${resourceToken}'
principalId: principalId
}
scope: rg
}
module appsEnv './shared/apps-env.bicep' = {
name: 'apps-env'
params: {
name: '${abbrs.appManagedEnvironments}${resourceToken}'
location: location
tags: tags
applicationInsightsName: monitoring.outputs.applicationInsightsName
logAnalyticsWorkspaceName: monitoring.outputs.logAnalyticsWorkspaceName
}
scope: rg
}
{{- if (or .DbCosmosMongo .DbPostgres)}}
resource vault 'Microsoft.KeyVault/vaults@2022-07-01' existing = {
name: keyVault.outputs.name
scope: rg
}
{{- end}}
{{- if .DbCosmosMongo}}
module cosmosDb './app/db-cosmos-mongo.bicep' = {
name: 'cosmosDb'
params: {
accountName: '${abbrs.documentDBDatabaseAccounts}${resourceToken}'
location: location
tags: tags
keyVaultName: keyVault.outputs.name
}
scope: rg
}
{{- end}}
{{- if .DbPostgres}}
module postgresDb './app/db-postgres.bicep' = {
name: 'postgresDb'
params: {
serverName: '${abbrs.dBforPostgreSQLServers}${resourceToken}'
location: location
tags: tags
databasePassword: databasePassword
keyVaultName: keyVault.outputs.name
allowAllIPsFirewall: true
}
scope: rg
}
{{- end}}
{{- range .Services}}
module {{bicepName .Name}} './app/{{.Name}}.bicep' = {
name: '{{.Name}}'
params: {
name: '${abbrs.appContainerApps}{{containerAppName .Name}}-${resourceToken}'
location: location
tags: tags
identityName: '${abbrs.managedIdentityUserAssignedIdentities}{{containerAppName .Name}}-${resourceToken}'
applicationInsightsName: monitoring.outputs.applicationInsightsName
containerAppsEnvironmentName: appsEnv.outputs.name
containerRegistryName: registry.outputs.name
exists: {{bicepName .Name}}Exists
appDefinition: {{bicepName .Name}}Definition
{{- if .DbCosmosMongo}}
cosmosDbConnectionString: vault.getSecret(cosmosDb.outputs.connectionStringKey)
{{- end}}
{{- if .DbPostgres}}
databaseName: postgresDb.outputs.databaseName
databaseHost: postgresDb.outputs.databaseHost
databaseUser: postgresDb.outputs.databaseUser
databasePassword: vault.getSecret(postgresDb.outputs.databaseConnectionKey)
{{- end}}
{{- if (and .Frontend .Frontend.Backends)}}
apiUrls: [
{{- range .Frontend.Backends}}
{{bicepName .Name}}.outputs.uri
{{- end}}
]
{{- end}}
{{- if (and .Backend .Backend.Frontends)}}
allowedOrigins: [
{{- range .Backend.Frontends}}
'https://${abbrs.appContainerApps}{{containerAppName .Name}}-${resourceToken}.${appsEnv.outputs.domain}'
{{- end}}
]
{{- end}}
}
scope: rg
}
{{- end}}
output AZURE_CONTAINER_REGISTRY_ENDPOINT string = registry.outputs.loginServer
output AZURE_KEY_VAULT_NAME string = keyVault.outputs.name
output AZURE_KEY_VAULT_ENDPOINT string = keyVault.outputs.endpoint
{{ end}}