-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathazuredeploy.bicep
151 lines (140 loc) · 4.06 KB
/
azuredeploy.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
param location string = resourceGroup().location
param logAnalyticsWorkspaceName string
param applicationInsightsName string
param containerRegistryName string
param containerAppsEnvironmentName string
param containerAppName string
param sqlServerName string
param sqlDatabaseName string
param sqlAdministratorsGroupName string
param sqlAdministratorsGroupObjectId string
param sqlDatabaseSkuName string
resource logAnalyticsWorkspace 'Microsoft.OperationalInsights/workspaces@2022-10-01' = {
name: logAnalyticsWorkspaceName
location: location
}
resource applicationInsights 'Microsoft.Insights/components@2020-02-02' = {
name: applicationInsightsName
location: location
kind: 'web'
properties: {
Application_Type: 'web'
WorkspaceResourceId: logAnalyticsWorkspace.id
}
}
resource containerRegistry 'Microsoft.ContainerRegistry/registries@2021-09-01' = {
name: containerRegistryName
location: location
sku: {
name: 'Basic'
}
properties: {
adminUserEnabled: true
networkRuleBypassOptions: 'AzureServices'
}
}
resource containerAppsEnvironment 'Microsoft.App/managedEnvironments@2022-03-01' = {
name: containerAppsEnvironmentName
location: location
properties: {
appLogsConfiguration: {
destination: 'log-analytics'
logAnalyticsConfiguration: {
customerId: logAnalyticsWorkspace.properties.customerId
sharedKey: logAnalyticsWorkspace.listKeys().primarySharedKey
}
}
daprAIConnectionString: applicationInsights.properties.ConnectionString
}
}
resource containerApp 'Microsoft.App/containerApps@2022-03-01' = {
name: containerAppName
location: location
identity: {
type: 'SystemAssigned'
}
properties: {
managedEnvironmentId: containerAppsEnvironment.id
configuration: {
ingress: {
external: true
targetPort: 80
transport: 'auto'
}
registries: [
{
identity: 'system'
server: containerRegistry.properties.loginServer
}
]
}
template: {
revisionSuffix: ''
containers: [
{
image: '${containerRegistry.properties.loginServer}/api:1.0.0'
name: 'api'
env: [
{
name: 'ConnectionStrings__Comics'
value: 'Server=tcp:${sqlServer.properties.fullyQualifiedDomainName},1433;Database=${sqlDatabaseName};Authentication=Active Directory Default;'
}
]
resources: {
cpu: json('0.25')
memory: '0.5Gi'
}
}
]
scale: {
minReplicas: 1
maxReplicas: 1
}
}
}
}
var acrPullRole = subscriptionResourceId('Microsoft.Authorization/roleDefinitions', '7f951dda-4ed3-4680-a7ca-43fe172d538d')
resource containerAppsRoleAssignment 'Microsoft.Authorization/roleAssignments@2022-04-01' = {
name: guid(containerApp.id, containerRegistry.id, acrPullRole)
properties: {
principalId: containerApp.identity.principalId
principalType: 'ServicePrincipal'
roleDefinitionId: acrPullRole
}
}
resource sqlServer 'Microsoft.Sql/servers@2021-11-01' = {
name: sqlServerName
location: location
identity: {
type: 'SystemAssigned'
}
properties: {
minimalTlsVersion: '1.2'
publicNetworkAccess: 'Enabled'
administrators: {
azureADOnlyAuthentication: true
administratorType: 'ActiveDirectory'
principalType: 'Group'
login: sqlAdministratorsGroupName
sid: sqlAdministratorsGroupObjectId
tenantId: subscription().tenantId
}
}
resource firewallRule 'firewallRules' = {
name: 'AllowAllWindowsAzureIps'
properties: {
startIpAddress: '0.0.0.0'
endIpAddress: '0.0.0.0'
}
}
resource sqlDatabase 'databases' = {
name: sqlDatabaseName
location: location
sku: {
name: sqlDatabaseSkuName
}
properties: {}
}
}
output sqlConnectionString string = 'Server=tcp:${sqlServer.properties.fullyQualifiedDomainName},1433;Database=${sqlDatabaseName};Authentication=Active Directory Default;'
output containerAppManagedIdentityId string = containerApp.identity.principalId