-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathmain.bicep
209 lines (193 loc) · 4.8 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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
targetScope = 'resourceGroup'
@minLength(4)
@maxLength(8)
@description('stack name, will prefix all the ressource deployement names and will be available in all tags')
param stackName string = 'acapdemo'
@description('stack location')
param stackLocation string = 'westeurope'
// process params to overcome some naming constraints
var lowerStackName = toLower(stackName)
// network infrastructure definition, if required update to fit your CIDR
var stackVNetCIDR = '10.5.0.0/16'
var stackVNetSubnets = [
{
name: 'subnet-base'
prefix: '10.5.0.0/20'
}
{
name: 'subnet-jump'
prefix: '10.5.16.0/20'
}
{
name: 'subnet-caenv-infra-backend'
prefix: '10.5.32.0/20'
}
{
name: 'subnet-caenv-infra-client'
prefix: '10.5.64.0/20'
}
]
// some tags for the deployed ressources, mandatory to locate & clean the provisionned resources
var stackTags = {
Stack: stackName
Scope: 'DevTest'
Tech: 'ContainerApps'
Stream: 'Awareness'
ResLocator: 'MSFT_ACA_PRIVATE_DEMO'
}
// vnet infra
module vnet './modules/vnet.bicep' = {
name: '${stackName}-vnet'
params: {
vnetName: '${stackName}-vnet'
vnetPrefix: stackVNetCIDR
vnetSubnets: stackVNetSubnets
vNetTags: stackTags
vNetLocation: stackLocation
}
}
var lawName = '${stackName}-law'
// log analytics workspace
module law './modules/law.bicep' = {
name: lawName
params: {
lawTags: stackTags
lawLocation: stackLocation
lawName: lawName
}
}
// ACA env for the backend service
var caBackendName = '${stackName}-caenv-backend'
module cabackend './modules/caenv.bicep' = {
name: caBackendName
params: {
caEnvLawName:lawName
caEnvName: caBackendName
caEnvLocation: stackLocation
caEnvPrivate: true
caEnvZoneRedundant: false
caEnvTags: stackTags
caEnvVnetInfraSubnetId: vnet.outputs.vnetSubnets[2].id
}
}
// Private DNS zone for the helloer environnement, required to hit the app
module cabackendns './modules/caenvdns.bicep' = {
name: '${stackName}-${caBackendName}-dns'
params: {
caEnvName: caBackendName
caEnvDnsTags: stackTags
caEnvDnsDomain: cabackend.outputs.caEnvDefaultDomain
caEnvDnsStaticIp: cabackend.outputs.caEnvStaticIp
caEnvDnsVnetId: vnet.outputs.vnetId
}
}
// ACA env for the greeter (client app illustration)
var caClientName = '${lowerStackName}-caenv-client'
module caclient './modules/caenv.bicep' = {
name: caClientName
params: {
caEnvLawName:lawName
caEnvName: caClientName
caEnvLocation: stackLocation
caEnvPrivate: true
caEnvZoneRedundant: false
caEnvTags: stackTags
caEnvVnetInfraSubnetId: vnet.outputs.vnetSubnets[3].id
}
}
// Helloer app, will serve the http calls
var backendAppName = '${lowerStackName}-helloer'
module cahelloer './modules/ca.bicep' = {
name: backendAppName
params: {
caAppName: backendAppName
caAppTags: stackTags
caAppMinReplicas: 1
caAppMaxReplicas: 1
caAppEnvLocation: stackLocation
caAppManagedEnvironmentId: cabackend.outputs.caEnvId
caAppIngress: {
allowInsecure: true
external: true
targetPort: 80
traffic: [
{
weight: 100
latestRevision: true
}
]
}
caAppContainers: [
{
image: 'docker.io/zlatkoa/helloer:1.0.3'
name: backendAppName
resources: {
cpu: 1
memory: '2.0Gi'
}
env: [
{
name: 'HELLOER_PORT'
value: '80'
}
{
name: 'HELLOER_BACKEND_TYPE'
value: backendAppName
}
]
probes: [
{
type: 'readiness'
httpGet: {
scheme: 'http'
path: '/health'
port: 80
}
}
{
type: 'liveness'
httpGet: {
path: '/health'
port: 80
}
}
]
}
]
}
}
// Greeter client app, will call the backend (helloer) on the follwing url
var helloerUrl = 'https://${backendAppName}.${cabackend.outputs.caEnvDefaultDomain}/connectivity/local'
module cagreeter './modules/ca.bicep' = {
name: '${lowerStackName}-ca-greeter'
params: {
caAppName: '${lowerStackName}-greeter'
caAppTags: stackTags
caAppMinReplicas: 1
caAppMaxReplicas: 1
caAppEnvLocation: stackLocation
caAppManagedEnvironmentId: caclient.outputs.caEnvId
caAppIngress: {}
caAppContainers: [
{
image: 'docker.io/zlatkoa/pgreeter:1.0.2'
name: '${lowerStackName}-greeter'
resources: {
cpu: 1
memory: '2.0Gi'
}
env: [
{
name: 'GREET_URL'
value: helloerUrl
}
{
name: 'GREET_SLEEP'
value: '10'
}
]
probes: []
}
]
}
}