-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathresources.bicep
More file actions
97 lines (87 loc) · 2.57 KB
/
resources.bicep
File metadata and controls
97 lines (87 loc) · 2.57 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
@description('The name of the Azure Container Registry')
param acrName string
@description('The SKU of the Azure Container Registry')
param acrSku string
@description('The name of the App Service Plan')
param appServicePlanName string
@description('The name of the Web App')
param webAppName string
@description('The location for all resources')
param location string
@description('The container image to deploy')
param containerImage string
// Deploy the Azure Container Registry
resource acr 'Microsoft.ContainerRegistry/registries@2023-01-01-preview' = {
name: acrName
location: location
sku: {
name: acrSku
}
properties: {
adminUserEnabled: false // Use managed identity instead
publicNetworkAccess: 'Disabled'
networkRuleBypassOptions: 'AzureServices'
}
}
// Deploy the App Service Plan
resource appServicePlan 'Microsoft.Web/serverfarms@2024-04-01' = {
name: appServicePlanName
location: location
sku: {
name: 'S1'
tier: 'Standard'
}
properties: {
reserved: true // Indicates Linux
}
}
// Deploy the Web App
resource webApp 'Microsoft.Web/sites@2024-04-01' = {
name: webAppName
location: location
identity: {
type: 'SystemAssigned'
}
tags: {
'azd-service-name': webAppName
}
properties: {
serverFarmId: appServicePlan.id
httpsOnly: true
siteConfig: {
minTlsVersion: '1.2'
ftpsState: 'Disabled'
alwaysOn: true
acrUseManagedIdentityCreds: true // Use managed identity for ACR authentication
appSettings: [
{
name: 'DOCKER_REGISTRY_SERVER_URL'
value: 'https://${acr.name}.azurecr.io'
}
{
name: 'WEBSITES_ENABLE_APP_SERVICE_STORAGE'
value: 'false'
}
{
name: 'DOCKER_CUSTOM_IMAGE_NAME'
value: containerImage
}
]
linuxFxVersion: 'DOCKER|${containerImage}' // Specify the container image
}
}
}
// Assign AcrPull role to the Web App's managed identity
resource acrPullRoleAssignment 'Microsoft.Authorization/roleAssignments@2022-04-01' = {
name: guid(acr.id, webApp.id, 'AcrPull')
scope: acr
properties: {
roleDefinitionId: subscriptionResourceId('Microsoft.Authorization/roleDefinitions', '7f951dda-4ed3-4680-a7ca-43fe172d538d') // AcrPull role ID
principalId: webApp.identity.principalId
principalType: 'ServicePrincipal'
}
}
output webAppName string = webApp.name
output webAppUrl string = 'https://${webApp.properties.defaultHostName}'
output acrLoginServer string = acr.properties.loginServer
output webAppPrincipalId string = webApp.identity.principalId