Skip to content

Commit ab89511

Browse files
authored
Merge pull request #84 from Azure-Samples/avm_updates
Use AVM for Keyvault, Private DNS Zones, VNET and Private Endpoints
2 parents 0bc3528 + 3954b0d commit ab89511

14 files changed

+184
-398
lines changed

{{cookiecutter.__src_folder_name}}/infra/aca.bicep

+8-8
Original file line numberDiff line numberDiff line change
@@ -23,27 +23,27 @@ param dbserverPassword string
2323
param postgresServiceId string
2424
{% endif %}
2525

26+
resource keyVault 'Microsoft.KeyVault/vaults@2022-07-01' existing = {
27+
name: keyVaultName
28+
}
29+
2630
resource webIdentity 'Microsoft.ManagedIdentity/userAssignedIdentities@2023-01-31' = {
2731
name: identityName
2832
location: location
2933
}
3034

31-
resource keyVault 'Microsoft.KeyVault/vaults@2022-07-01' existing = {
32-
name: keyVaultName
33-
}
34-
35-
// Give the app access to KeyVault
36-
module webKeyVaultAccess './core/security/keyvault-access.bicep' = {
37-
name: 'web-keyvault-access'
35+
module keyVaultRoleAssignment 'core/security/role.bicep' = {
36+
name: 'webRoleAssignment'
3837
params: {
39-
keyVaultName: keyVault.name
4038
principalId: webIdentity.properties.principalId
39+
roleDefinitionId: '4633458b-17de-408a-b874-0445c86b69e6' // Key Vault Secrets User
4140
}
4241
}
4342

4443
{% if cookiecutter.project_host == "aca" %}
4544
module app 'core/host/container-app-upsert.bicep' = {
4645
name: '${serviceName}-container-app-module'
46+
dependsOn: [keyVaultRoleAssignment]
4747
params: {
4848
name: name
4949
location: location

{{cookiecutter.__src_folder_name}}/infra/appservice.bicep

+5-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ param dbserverDomainName string
1111
param dbserverUser string
1212
param dbserverDatabaseName string
1313
{% endif %}
14+
param virtualNetworkSubnetId string = ''
1415

1516
resource applicationInsights 'Microsoft.Insights/components@2020-02-02' existing = {
1617
name: applicationInsightsName
@@ -60,15 +61,17 @@ module web 'core/host/appservice.bicep' = {
6061
AZURE_COSMOS_CONNECTION_STRING: '@Microsoft.KeyVault(VaultName=${keyVaultName};SecretName=AZURE-COSMOS-CONNECTION-STRING)'
6162
{% endif %}
6263
}
64+
virtualNetworkSubnetId: virtualNetworkSubnetId
6365
}
6466
}
6567

6668
// Give the app access to KeyVault
67-
module webKeyVaultAccess './core/security/keyvault-access.bicep' = {
69+
module webKeyVaultAccess './core/security/role.bicep' = {
6870
name: 'web-keyvault-access'
6971
params: {
70-
keyVaultName: keyVaultName
7172
principalId: web.outputs.identityPrincipalId
73+
principalType: 'ServicePrincipal'
74+
roleDefinitionId: '00482a5a-887f-4fb3-b363-3b7fe8e74483'
7275
}
7376
}
7477

{{cookiecutter.__src_folder_name}}/infra/core/host/appservice.bicep

+2
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ param scmDoBuildDuringDeployment bool = false
3636
param use32BitWorkerProcess bool = false
3737
param ftpsState string = 'FtpsOnly'
3838
param healthCheckPath string = ''
39+
param virtualNetworkSubnetId string = ''
3940

4041
resource appService 'Microsoft.Web/sites@2022-03-01' = {
4142
name: name
@@ -65,6 +66,7 @@ resource appService 'Microsoft.Web/sites@2022-03-01' = {
6566
}
6667
clientAffinityEnabled: clientAffinityEnabled
6768
httpsOnly: true
69+
virtualNetworkSubnetId: virtualNetworkSubnetId
6870
}
6971

7072
identity: { type: managedIdentity ? 'SystemAssigned' : 'None' }

{{cookiecutter.__src_folder_name}}/infra/core/host/container-apps-environment.bicep

-41
This file was deleted.

{{cookiecutter.__src_folder_name}}/infra/core/host/container-apps.bicep

+23-8
Original file line numberDiff line numberDiff line change
@@ -7,34 +7,49 @@ param containerAppsEnvironmentName string
77
param containerRegistryName string
88
param containerRegistryResourceGroupName string = ''
99
param containerRegistryAdminUserEnabled bool = false
10-
param logAnalyticsWorkspaceName string
11-
param applicationInsightsName string = ''
10+
param logAnalyticsWorkspaceResourceId string
11+
param applicationInsightsName string = '' // Not used here, was used for DAPR
12+
param virtualNetworkSubnetId string = ''
1213

13-
module containerAppsEnvironment 'container-apps-environment.bicep' = {
14+
@description('Optional user assigned identity IDs to assign to the resource')
15+
param userAssignedIdentityResourceIds array = []
16+
17+
module containerAppsEnvironment 'br/public:avm/res/app/managed-environment:0.5.2' = {
1418
name: '${name}-container-apps-environment'
1519
params: {
20+
// Required parameters
21+
logAnalyticsWorkspaceResourceId: logAnalyticsWorkspaceResourceId
22+
23+
managedIdentities: empty(userAssignedIdentityResourceIds) ? {
24+
systemAssigned: true
25+
} : {
26+
userAssignedResourceIds: userAssignedIdentityResourceIds
27+
}
28+
1629
name: containerAppsEnvironmentName
30+
// Non-required parameters
31+
infrastructureResourceGroupName: containerRegistryResourceGroupName
32+
infrastructureSubnetId: virtualNetworkSubnetId
33+
// internal: true
1734
location: location
1835
tags: tags
19-
logAnalyticsWorkspaceName: logAnalyticsWorkspaceName
20-
applicationInsightsName: applicationInsightsName
2136
}
2237
}
2338

24-
module containerRegistry 'container-registry.bicep' = {
39+
module containerRegistry 'br/public:avm/res/container-registry/registry:0.3.1' = {
2540
name: '${name}-container-registry'
2641
scope: !empty(containerRegistryResourceGroupName) ? resourceGroup(containerRegistryResourceGroupName) : resourceGroup()
2742
params: {
2843
name: containerRegistryName
2944
location: location
30-
adminUserEnabled: containerRegistryAdminUserEnabled
45+
acrAdminUserEnabled: containerRegistryAdminUserEnabled
3146
tags: tags
3247
}
3348
}
3449

3550
output defaultDomain string = containerAppsEnvironment.outputs.defaultDomain
3651
output environmentName string = containerAppsEnvironment.outputs.name
37-
output environmentId string = containerAppsEnvironment.outputs.id
52+
output environmentId string = containerAppsEnvironment.outputs.resourceId
3853

3954
output registryLoginServer string = containerRegistry.outputs.loginServer
4055
output registryName string = containerRegistry.outputs.name

{{cookiecutter.__src_folder_name}}/infra/core/host/container-registry.bicep

-137
This file was deleted.

{{cookiecutter.__src_folder_name}}/infra/core/monitor/applicationinsights.bicep

-31
This file was deleted.

{{cookiecutter.__src_folder_name}}/infra/core/monitor/loganalytics.bicep

-22
This file was deleted.

0 commit comments

Comments
 (0)