Skip to content

Commit 02af2bf

Browse files
committed
add bicep codes for deploying storage account
1 parent 0d86dc9 commit 02af2bf

File tree

4 files changed

+207
-2
lines changed

4 files changed

+207
-2
lines changed

infra/artifacts/azuredeploy.json

Lines changed: 136 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"_generator": {
66
"name": "bicep",
77
"version": "0.29.47.4906",
8-
"templateHash": "2885509356264964242"
8+
"templateHash": "3135606789741441731"
99
}
1010
},
1111
"parameters": {
@@ -143,6 +143,20 @@
143143
"metadata": {
144144
"description": "Specifies the name of the Azure Cosmos DB resource."
145145
}
146+
},
147+
"storageAccountName": {
148+
"type": "string",
149+
"defaultValue": "[format('{0}storageaccount', parameters('prefix'))]",
150+
"metadata": {
151+
"description": "Specifies the name of the Azure Storage Account resource."
152+
}
153+
},
154+
"storageAccountContainerNames": {
155+
"type": "array",
156+
"defaultValue": [],
157+
"metadata": {
158+
"description": "Specifies the name of the Azure Storage Account containers."
159+
}
146160
}
147161
},
148162
"resources": [
@@ -902,6 +916,125 @@
902916
}
903917
}
904918
}
919+
},
920+
{
921+
"type": "Microsoft.Resources/deployments",
922+
"apiVersion": "2022-09-01",
923+
"name": "storageAccount",
924+
"properties": {
925+
"expressionEvaluationOptions": {
926+
"scope": "inner"
927+
},
928+
"mode": "Incremental",
929+
"parameters": {
930+
"name": {
931+
"value": "[parameters('storageAccountName')]"
932+
},
933+
"containerNames": {
934+
"value": "[parameters('storageAccountContainerNames')]"
935+
},
936+
"location": {
937+
"value": "[parameters('location')]"
938+
},
939+
"tags": {
940+
"value": "[parameters('tags')]"
941+
}
942+
},
943+
"template": {
944+
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
945+
"contentVersion": "1.0.0.0",
946+
"metadata": {
947+
"_generator": {
948+
"name": "bicep",
949+
"version": "0.29.47.4906",
950+
"templateHash": "15880869177723600522"
951+
}
952+
},
953+
"parameters": {
954+
"name": {
955+
"type": "string",
956+
"metadata": {
957+
"description": "Specifies the name of the storage account."
958+
}
959+
},
960+
"containerNames": {
961+
"type": "array",
962+
"defaultValue": [],
963+
"metadata": {
964+
"description": "Specifies an array of containers to create."
965+
}
966+
},
967+
"location": {
968+
"type": "string",
969+
"defaultValue": "[resourceGroup().location]",
970+
"metadata": {
971+
"description": "Specifies the location."
972+
}
973+
},
974+
"tags": {
975+
"type": "object",
976+
"defaultValue": {},
977+
"metadata": {
978+
"description": "Specifies the resource tags."
979+
}
980+
}
981+
},
982+
"resources": [
983+
{
984+
"copy": {
985+
"name": "containers",
986+
"count": "[length(parameters('containerNames'))]"
987+
},
988+
"type": "Microsoft.Storage/storageAccounts/blobServices/containers",
989+
"apiVersion": "2023-05-01",
990+
"name": "[format('{0}/{1}/{2}', parameters('name'), 'default', parameters('containerNames')[copyIndex()])]",
991+
"properties": {
992+
"publicAccess": "None",
993+
"defaultEncryptionScope": "$account-encryption-key",
994+
"denyEncryptionScopeOverride": false
995+
},
996+
"dependsOn": [
997+
"[resourceId('Microsoft.Storage/storageAccounts/blobServices', parameters('name'), 'default')]"
998+
]
999+
},
1000+
{
1001+
"type": "Microsoft.Storage/storageAccounts/blobServices",
1002+
"apiVersion": "2023-05-01",
1003+
"name": "[format('{0}/{1}', parameters('name'), 'default')]",
1004+
"properties": {
1005+
"deleteRetentionPolicy": {
1006+
"enabled": false,
1007+
"allowPermanentDelete": false
1008+
}
1009+
},
1010+
"dependsOn": [
1011+
"[resourceId('Microsoft.Storage/storageAccounts', parameters('name'))]"
1012+
]
1013+
},
1014+
{
1015+
"type": "Microsoft.Storage/storageAccounts",
1016+
"apiVersion": "2023-05-01",
1017+
"name": "[parameters('name')]",
1018+
"location": "[parameters('location')]",
1019+
"tags": "[parameters('tags')]",
1020+
"sku": {
1021+
"name": "Standard_LRS"
1022+
},
1023+
"kind": "StorageV2"
1024+
}
1025+
],
1026+
"outputs": {
1027+
"id": {
1028+
"type": "string",
1029+
"value": "[resourceId('Microsoft.Storage/storageAccounts', parameters('name'))]"
1030+
},
1031+
"name": {
1032+
"type": "string",
1033+
"value": "[parameters('name')]"
1034+
}
1035+
}
1036+
}
1037+
}
9051038
}
9061039
],
9071040
"outputs": {
@@ -915,7 +1048,8 @@
9151048
"aiServicesEndpoint": "[reference(resourceId('Microsoft.Resources/deployments', 'aiServices'), '2022-09-01').outputs.endpoint.value]",
9161049
"aiSearchName": "[reference(resourceId('Microsoft.Resources/deployments', 'aiSearch'), '2022-09-01').outputs.name.value]",
9171050
"cosmosDbAccountName": "[reference(resourceId('Microsoft.Resources/deployments', 'cosmosDb'), '2022-09-01').outputs.accountName.value]",
918-
"cosmosDbAccountEndpoint": "[reference(resourceId('Microsoft.Resources/deployments', 'cosmosDb'), '2022-09-01').outputs.accountEndpoint.value]"
1051+
"cosmosDbAccountEndpoint": "[reference(resourceId('Microsoft.Resources/deployments', 'cosmosDb'), '2022-09-01').outputs.accountEndpoint.value]",
1052+
"storageAccountName": "[reference(resourceId('Microsoft.Resources/deployments', 'storageAccount'), '2022-09-01').outputs.name.value]"
9191053
}
9201054
}
9211055
}

infra/main.bicep

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,12 @@ param aiSearchName string = '${prefix}aisearch'
6666
@description('Specifies the name of the Azure Cosmos DB resource.')
6767
param cosmosDbName string = '${prefix}cosmosdb'
6868

69+
@description('Specifies the name of the Azure Storage Account resource.')
70+
param storageAccountName string = '${prefix}storageaccount'
71+
72+
@description('Specifies the name of the Azure Storage Account containers.')
73+
param storageAccountContainerNames array = []
74+
6975
// Resources
7076
module workspace 'modules/logAnalytics.bicep' = {
7177
name: 'workspace'
@@ -121,6 +127,16 @@ module cosmosDb './modules/cosmosDb.bicep' = {
121127
}
122128
}
123129

130+
module storageAccount './modules/storageAccount.bicep' = {
131+
name: 'storageAccount'
132+
params: {
133+
name: storageAccountName
134+
containerNames: storageAccountContainerNames
135+
location: location
136+
tags: tags
137+
}
138+
}
139+
124140
output deploymentInfo object = {
125141
subscriptionId: subscription().subscriptionId
126142
resourceGroupName: resourceGroup().name
@@ -130,4 +146,5 @@ output deploymentInfo object = {
130146
aiSearchName: aiSearch.outputs.name
131147
cosmosDbAccountName: cosmosDb.outputs.accountName
132148
cosmosDbAccountEndpoint: cosmosDb.outputs.accountEndpoint
149+
storageAccountName: storageAccount.outputs.name
133150
}

infra/main.bicepparam

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ param openAiDeployments = [
2626
}
2727
}
2828
]
29+
30+
param storageAccountContainerNames = [
31+
'audio'
32+
]
33+
2934
param tags = {
3035
environment: 'development'
3136
iac: 'bicep'

infra/modules/storageAccount.bicep

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// Parameters
2+
@description('Specifies the name of the storage account.')
3+
param name string
4+
5+
@description('Specifies an array of containers to create.')
6+
param containerNames array = []
7+
8+
@description('Specifies the location.')
9+
param location string = resourceGroup().location
10+
11+
@description('Specifies the resource tags.')
12+
param tags object = {}
13+
14+
// Resources
15+
resource storageAccount 'Microsoft.Storage/storageAccounts@2023-05-01' = {
16+
name: name
17+
location: location
18+
tags: tags
19+
sku: {
20+
name: 'Standard_LRS'
21+
}
22+
kind: 'StorageV2'
23+
24+
// Containers live inside of a blob service
25+
resource blobService 'blobServices' = {
26+
name: 'default'
27+
properties: {
28+
deleteRetentionPolicy: {
29+
enabled: false
30+
allowPermanentDelete: false
31+
}
32+
}
33+
// Creating containers with provided names
34+
resource containers 'containers' = [
35+
for containerName in containerNames: {
36+
name: containerName
37+
properties: {
38+
publicAccess: 'None'
39+
defaultEncryptionScope: '$account-encryption-key'
40+
denyEncryptionScopeOverride: false
41+
}
42+
}
43+
]
44+
}
45+
}
46+
47+
// Outputs
48+
output id string = storageAccount.id
49+
output name string = storageAccount.name

0 commit comments

Comments
 (0)