-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.bicep
More file actions
184 lines (163 loc) · 4.85 KB
/
Copy pathmain.bicep
File metadata and controls
184 lines (163 loc) · 4.85 KB
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
@description('Specifies the prefix for the name of the Azure resources.')
@minLength(2)
param prefix string = take(uniqueString(resourceGroup().id), 4)
@description('Specifies the suffix for the name of the Azure resources.')
@minLength(2)
param suffix string = take(uniqueString(resourceGroup().id), 4)
@description('Specifies the location for all resources.')
param location string = resourceGroup().location
@description('Specifies the sku of the Azure Storage account.')
param storageAccountSku string = 'Standard_LRS'
@description('Specifies the name of the blob container.')
param containerName string = 'activities'
@description('Specifies the SKU for the container registry.')
@allowed([
'Basic'
'Standard'
'Premium'
])
param acrSku string = 'Basic'
@description('Specifies the name of the container image.')
param imageName string = 'vacation-planner'
@description('Specifies the tag of the container image.')
param imageTag string = 'v1'
@description('Specifies the number of CPU cores for the container.')
param cpuCores int = 1
@description('Specifies the memory in GB for the container.')
param memoryInGb int = 1
@description('Specifies the DNS name label for the container group.')
param dnsNameLabel string = '${prefix}-aci-planner-${suffix}'
@description('Specifies the login name passed to the app.')
param loginName string = 'paolo'
@description('Specifies the tags to be applied to the resources.')
param tags object = {
environment: 'test'
iac: 'bicep'
}
var storageAccountName = '${prefix}acistorage${suffix}'
var keyVaultName = '${prefix}acikv${suffix}'
var acrName = '${prefix}aciacr${suffix}'
var aciGroupName = '${prefix}-aci-planner-${suffix}'
// Storage Account
resource storageAccount 'Microsoft.Storage/storageAccounts@2025-01-01' = {
name: storageAccountName
location: location
tags: tags
sku: {
name: storageAccountSku
}
kind: 'StorageV2'
properties: {
accessTier: 'Hot'
}
}
resource blobServices 'Microsoft.Storage/storageAccounts/blobServices@2025-01-01' = {
parent: storageAccount
name: 'default'
}
resource blobContainer 'Microsoft.Storage/storageAccounts/blobServices/containers@2025-01-01' = {
parent: blobServices
name: containerName
}
// Key Vault
resource keyVault 'Microsoft.KeyVault/vaults@2023-07-01' = {
name: keyVaultName
location: location
tags: tags
properties: {
sku: {
family: 'A'
name: 'standard'
}
tenantId: subscription().tenantId
enableRbacAuthorization: true
accessPolicies: []
}
}
// Store the storage connection string in Key Vault
resource storageConnSecret 'Microsoft.KeyVault/vaults/secrets@2023-07-01' = {
parent: keyVault
name: 'storage-conn'
properties: {
value: 'DefaultEndpointsProtocol=http;AccountName=${storageAccountName};AccountKey=${storageAccount.listKeys().keys[0].value};BlobEndpoint=${storageAccount.properties.primaryEndpoints.blob}'
}
}
// Container Registry
resource containerRegistry 'Microsoft.ContainerRegistry/registries@2023-07-01' = {
name: acrName
location: location
tags: tags
sku: {
name: acrSku
}
properties: {
adminUserEnabled: true
}
}
// Container Instance
resource containerGroup 'Microsoft.ContainerInstance/containerGroups@2023-05-01' = {
name: aciGroupName
location: location
tags: tags
properties: {
containers: [
{
name: aciGroupName
properties: {
image: '${containerRegistry.properties.loginServer}/${imageName}:${imageTag}'
resources: {
requests: {
cpu: cpuCores
memoryInGB: memoryInGb
}
}
ports: [
{
port: 80
protocol: 'TCP'
}
]
environmentVariables: [
{
name: 'AZURE_STORAGE_CONNECTION_STRING'
secureValue: storageConnSecret.properties.secretUri
}
{
name: 'BLOB_CONTAINER_NAME'
value: containerName
}
{
name: 'LOGIN_NAME'
value: loginName
}
]
}
}
]
osType: 'Linux'
restartPolicy: 'Always'
ipAddress: {
type: 'Public'
dnsNameLabel: dnsNameLabel
ports: [
{
port: 80
protocol: 'TCP'
}
]
}
imageRegistryCredentials: [
{
server: containerRegistry.properties.loginServer
username: containerRegistry.listCredentials().username
password: containerRegistry.listCredentials().passwords[0].value
}
]
}
}
output storageAccountName string = storageAccount.name
output keyVaultName string = keyVault.name
output acrName string = containerRegistry.name
output acrLoginServer string = containerRegistry.properties.loginServer
output aciGroupName string = containerGroup.name
output fqdn string = containerGroup.properties.ipAddress.fqdn