forked from jasontaylordev/CleanArchitecture
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.bicep
174 lines (155 loc) · 5.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
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
targetScope = 'subscription'
@minLength(1)
@maxLength(64)
@description('Name of the the environment which is used to generate a short unique hash used in all resources.')
param environmentName string
@minLength(1)
@description('Primary location for all resources')
param location string
@description('Id of the user or app to assign application roles')
param principalId string
// Optional parameters to override the default azd resource naming conventions.
// Add the following to main.parameters.json to provide values:
// "resourceGroupName": {
// "value": "myGroupName"
// }
param resourceGroupName string = ''
param logAnalyticsName string = ''
param applicationInsightsName string = ''
param applicationInsightsDashboardName string = ''
param keyVaultName string = ''
param appServiceName string = ''
param dbServerName string = ''
param dbName string = ''
@secure()
param dbAdminPassword string
@secure()
param dbAppUserPassword string
var abbrs = loadJsonContent('./abbreviations.json')
// 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
}
// Generate a unique token to be used in naming resources.
var resourceToken = toLower(uniqueString(subscription().id, environmentName, location))
// Name of the service defined in azure.yaml
// A tag named azd-service-name with this value should be applied to the service host resource, such as:
// Microsoft.Web/sites for appservice, function
// Example usage:
// tags: union(tags, { 'azd-service-name': apiServiceName })
var webServiceName = 'web'
// Organize resources in a resource group
resource rg 'Microsoft.Resources/resourceGroups@2021-04-01' = {
name: !empty(resourceGroupName) ? resourceGroupName : '${abbrs.resourcesResourceGroups}${environmentName}'
location: location
tags: tags
}
// Add resources to be provisioned below.
module monitoring 'core/monitor/monitoring.bicep' = {
name: 'monitoring'
params: {
location: location
tags: tags
logAnalyticsName: !empty(logAnalyticsName) ? logAnalyticsName : '${abbrs.operationalInsightsWorkspaces}${resourceToken}'
applicationInsightsName: !empty(applicationInsightsName) ? applicationInsightsName : '${abbrs.insightsComponents}${resourceToken}'
applicationInsightsDashboardName: !empty(applicationInsightsDashboardName) ? applicationInsightsDashboardName : '${abbrs.portalDashboards}${resourceToken}'
}
scope: rg
}
module keyVault 'core/security/keyvault.bicep' = {
name: 'keyvault'
params: {
location: location
tags: tags
name: !empty(keyVaultName) ? keyVaultName : '${abbrs.keyVaultVaults}${resourceToken}'
principalId: principalId
}
scope: rg
}
module web 'services/web.bicep' = {
name: 'web'
params: {
name: !empty(appServiceName) ? appServiceName : '${abbrs.webSitesAppService}${resourceToken}'
location: location
tags: tags
serviceName: webServiceName
applicationInsightsName: monitoring.outputs.applicationInsightsName
keyVaultName: keyVault.outputs.name
}
scope: rg
}
//#if (UsePostgreSQL)
module pgsqldatabase 'core/database/postgresql/flexibleserver.bicep' = {
name: 'pgsql-database'
params: {
name: !empty(dbServerName) ? dbServerName : '${abbrs.postgreSQLServers}${resourceToken}'
location: location
tags: tags
sku: {
name: 'Standard_B1ms'
tier: 'Burstable'
}
storage: {
storageSizeGB: 32
}
version: '14'
appUserLogin: 'appUser'
appUserLoginPassword: dbAppUserPassword
administratorLogin: 'pgsqlAdmin'
administratorLoginPassword: dbAdminPassword
databaseName:!empty(dbName) ? dbName : '${abbrs.postgreSQLServersDatabases}${resourceToken}'
allowAzureIPsFirewall: true
keyVaultName: keyVault.outputs.name
connectionStringKey: 'ConnectionStrings--CleanArchitectureDb'
}
scope: rg
}
//#endif
//#if (UseSqlServer)
module database 'core/database/sqlserver/sqlserver.bicep' = {
name: 'database'
params: {
name: !empty(dbServerName) ? dbServerName : '${abbrs.sqlServers}${resourceToken}'
location: location
tags: tags
databaseName: !empty(dbName) ? dbName : '${abbrs.sqlServersDatabases}${resourceToken}'
keyVaultName: keyVault.outputs.name
connectionStringKey: 'ConnectionStrings--CleanArchitectureDb'
sqlAdminPassword: dbAdminPassword
appUserPassword: dbAppUserPassword
}
scope: rg
}
//#endif
module webKeyVaultAccess 'core/security/keyvault-access.bicep' = {
name: 'webKeyVaultAccess'
params: {
keyVaultName: keyVault.outputs.name
principalId: web.outputs.identityPrincipalId
}
scope: rg
}
// Add outputs from the deployment here, if needed.
//
// This allows the outputs to be referenced by other bicep deployments in the deployment pipeline,
// or by the local machine as a way to reference created resources in Azure for local development.
// Secrets should not be added here.
//
// Outputs are automatically saved in the local azd environment .env file.
// To see these outputs, run `azd env get-values`, or `azd env get-values --output json` for json output.
output AZURE_LOCATION string = location
output AZURE_TENANT_ID string = tenant().tenantId
output AZURE_KEY_VAULT_NAME string = keyVault.outputs.name
output AZURE_KEY_VAULT_ENDPOINT string = keyVault.outputs.endpoint
output APPLICATIONINSIGHTS_CONNECTION_STRING string = monitoring.outputs.applicationInsightsConnectionString
//#if (UseSqlServer)
output AZURE_SQL_CONNECTION_STRING_KEY string = database.outputs.connectionStringKey
//#endif
//#if (UsePostgreSQL)
output AZURE_PSQL_CONNECTION_STRING_KEY string = pgsqldatabase.outputs.connectionStringKey
//#endif
output WEB_BASE_URI string = web.outputs.uri