@@ -9,8 +9,6 @@ param location string = resourceGroup().location
9
9
@description ('The tags to apply to all resources' )
10
10
param tags object = {}
11
11
12
- param usePrivateEndpoint bool = false
13
-
14
12
@allowed (['appservice' , 'containerapps' ])
15
13
param deploymentTarget string
16
14
@@ -26,95 +24,191 @@ resource appServicePlan 'Microsoft.Web/serverfarms@2022-03-01' existing = if (de
26
24
name : appServicePlanName
27
25
}
28
26
29
- resource containerAppsEnvironment 'Microsoft.App/managedEnvironments@2023-05-01' existing = if (deploymentTarget == 'containerapps' ) {
30
- name : containerAppsEnvName
27
+ module containerAppsNSG 'br/public:avm/res/network/network-security-group:0.5.1' = if (deploymentTarget == 'containerapps' ) {
28
+ name : 'container-apps-nsg'
29
+ params : {
30
+ name : '${vnetName }-container-apps-nsg'
31
+ location : location
32
+ tags : tags
33
+ securityRules : [
34
+ {
35
+ name : 'AllowHttpsInbound'
36
+ properties : {
37
+ protocol : 'Tcp'
38
+ sourcePortRange : '*'
39
+ sourceAddressPrefix : 'Internet'
40
+ destinationPortRange : '443'
41
+ destinationAddressPrefix : '*'
42
+ access : 'Allow'
43
+ priority : 100
44
+ direction : 'Inbound'
45
+ }
46
+ }
47
+ ]
48
+ }
31
49
}
32
50
33
- // Always need this one
34
- var backendSubnet = {
35
- name : 'backend-subnet'
51
+ module privateEndpointsNSG 'br/public:avm/res/network/network-security-group:0.5.1' = if (deploymentTarget == 'containerapps' ) {
52
+ name : 'private-endpoints-nsg'
53
+ params : {
54
+ name : '${vnetName }-private-endpoints-nsg'
55
+ location : location
56
+ tags : tags
57
+ securityRules : [
58
+ {
59
+ name : 'AllowVnetInBound'
36
60
properties : {
37
- addressPrefix : '10.0.1.0/24'
38
- privateEndpointNetworkPolicies : 'Enabled'
39
- privateLinkServiceNetworkPolicies : 'Enabled'
61
+ protocol : '*'
62
+ sourcePortRange : '*'
63
+ sourceAddressPrefix : 'VirtualNetwork'
64
+ destinationPortRange : '*'
65
+ destinationAddressPrefix : '*'
66
+ access : 'Allow'
67
+ priority : 100
68
+ direction : 'Inbound'
40
69
}
41
70
}
42
-
43
- var appServiceSubnet = {
44
- name : 'app-int-subnet'
45
- properties : {
46
- addressPrefix : '10.0.3.0/24'
47
- privateEndpointNetworkPolicies : 'Enabled'
48
- privateLinkServiceNetworkPolicies : 'Enabled'
49
- delegations : [
50
- {
51
- id : appServicePlan .id
52
- name : appServicePlan .name
53
- properties : {
54
- serviceName : 'Microsoft.Web/serverFarms'
55
- }
56
- }
57
- ]
71
+ {
72
+ name : 'AllowAzureLoadBalancerInbound'
73
+ properties : {
74
+ protocol : '*'
75
+ sourcePortRange : '*'
76
+ sourceAddressPrefix : 'AzureLoadBalancer'
77
+ destinationPortRange : '*'
78
+ destinationAddressPrefix : '*'
79
+ access : 'Allow'
80
+ priority : 110
81
+ direction : 'Inbound'
82
+ }
58
83
}
59
- }
60
-
61
- var containerAppsSubnet = {
62
- name : 'app-int-subnet'
63
- properties : {
64
- addressPrefix : '10.0.4.0/23'
65
- privateEndpointNetworkPolicies : 'Enabled'
66
- privateLinkServiceNetworkPolicies : 'Enabled'
67
- delegations : [
68
- {
69
- id : containerAppsEnvironment .id
70
- name : containerAppsEnvironment .name
71
- properties : {
72
- serviceName : 'Microsoft.App/environments'
73
- }
74
- }
75
- ]
84
+ {
85
+ name : 'DenyInternetInbound'
86
+ properties : {
87
+ protocol : '*'
88
+ sourcePortRange : '*'
89
+ sourceAddressPrefix : 'Internet'
90
+ destinationPortRange : '*'
91
+ destinationAddressPrefix : '*'
92
+ access : 'Deny'
93
+ priority : 4096
94
+ direction : 'Inbound'
95
+ }
76
96
}
77
- }
78
-
79
- var gatewaySubnet = {
80
- name : 'GatewaySubnet' // Required name for Gateway subnet
81
- properties : {
82
- addressPrefix : '10.0.255.0/27' // Using a /27 subnet size which is minimal required size for gateway subnet
83
- }
97
+ {
98
+ name : 'AllowVnetOutbound'
99
+ properties : {
100
+ protocol : '*'
101
+ sourcePortRange : '*'
102
+ sourceAddressPrefix : '*'
103
+ destinationPortRange : '*'
104
+ destinationAddressPrefix : 'VirtualNetwork'
105
+ access : 'Allow'
106
+ priority : 100
107
+ direction : 'Outbound'
108
+ }
109
+ }
110
+ {
111
+ name : 'AllowAzureCloudOutbound'
112
+ properties : {
113
+ protocol : 'Tcp'
114
+ sourcePortRange : '*'
115
+ sourceAddressPrefix : '*'
116
+ destinationPortRange : '443'
117
+ destinationAddressPrefix : 'AzureCloud'
118
+ access : 'Allow'
119
+ priority : 110
120
+ direction : 'Outbound'
121
+ }
122
+ }
123
+ {
124
+ name : 'AllowDnsOutbound'
125
+ properties : {
126
+ protocol : '*'
127
+ sourcePortRange : '*'
128
+ sourceAddressPrefix : '*'
129
+ destinationPortRange : '53'
130
+ destinationAddressPrefix : '*'
131
+ access : 'Allow'
132
+ priority : 120
133
+ direction : 'Outbound'
134
+ }
135
+ }
136
+ {
137
+ name : 'DenyInternetOutbound'
138
+ properties : {
139
+ protocol : '*'
140
+ sourcePortRange : '*'
141
+ sourceAddressPrefix : '*'
142
+ destinationPortRange : '*'
143
+ destinationAddressPrefix : 'Internet'
144
+ access : 'Deny'
145
+ priority : 4096
146
+ direction : 'Outbound'
147
+ }
148
+ }
149
+ ]
84
150
}
151
+ }
85
152
86
- var privateDnsResolverSubnet = {
87
- name : 'dns-resolver-subnet' // Dedicated subnet for Azure Private DNS Resolver
88
- properties : {
89
- addressPrefix : '10.0.11.0/28' // Original value kept as requested
90
- delegations : [
91
- {
92
- name : 'Microsoft.Network.dnsResolvers'
93
- properties : {
94
- serviceName : 'Microsoft.Network/dnsResolvers'
95
- }
153
+ var appServiceSubnet = {
154
+ name : 'app-int-subnet'
155
+ properties : {
156
+ addressPrefix : '10.0.3.0/24'
157
+ privateEndpointNetworkPolicies : 'Enabled'
158
+ privateLinkServiceNetworkPolicies : 'Enabled'
159
+ delegations : [
160
+ {
161
+ id : appServicePlan .id
162
+ name : appServicePlan .name
163
+ properties : {
164
+ serviceName : 'Microsoft.Web/serverFarms'
96
165
}
97
- ]
98
- }
166
+ }
167
+ ]
99
168
}
169
+ }
100
170
101
- var subnets = union (
102
- [backendSubnet , deploymentTarget == 'appservice' ? appServiceSubnet : containerAppsSubnet ],
103
- deployVpnGateway ? [gatewaySubnet , privateDnsResolverSubnet ] : [])
104
-
105
- module vnet './core/networking/vnet.bicep' = if (usePrivateEndpoint ) {
171
+ module vnet 'br/public:avm/res/network/virtual-network:0.6.1' = {
106
172
name : 'vnet'
107
173
params : {
108
174
name : vnetName
109
175
location : location
110
176
tags : tags
111
- subnets : subnets
177
+ addressPrefixes : [
178
+ '10.0.0.0/16'
179
+ ]
180
+ subnets : [
181
+ {
182
+ name : 'backend-subnet'
183
+ addressPrefix : '10.0.1.0/24'
184
+ privateEndpointNetworkPolicies : 'Enabled'
185
+ privateLinkServiceNetworkPolicies : 'Enabled'
186
+ networkSecurityGroupResourceId : privateEndpointsNSG .outputs .resourceId
187
+ }
188
+ {
189
+ name : 'GatewaySubnet' // Required name for Gateway subnet
190
+ addressPrefix : '10.0.255.0/27' // Using a /27 subnet size which is minimal required size for gateway subnet
191
+ }
192
+ {
193
+ name : 'dns-resolver-subnet' // Dedicated subnet for Azure Private DNS Resolver
194
+ addressPrefix : '10.0.11.0/28' // Original value kept as requested
195
+ delegation : 'Microsoft.Network/dnsResolvers'
196
+ }
197
+ {
198
+ name : 'app-int-subnet'
199
+ addressPrefix : '10.0.4.0/23'
200
+ //privateEndpointNetworkPolicies: 'Enabled'
201
+ //privateLinkServiceNetworkPolicies: 'Enabled'
202
+ networkSecurityGroupResourceId : containerAppsNSG .outputs .resourceId
203
+ delegation : 'Microsoft.App/environments'
204
+ }
205
+ ]
112
206
}
113
207
}
114
208
115
- output appSubnetId string = usePrivateEndpoint ? vnet . outputs . vnetSubnets [ 1 ]. id : ''
116
- output appSubnetName string = usePrivateEndpoint ? vnet .outputs .vnetSubnets [ 1 ]. name : ''
117
- output backendSubnetId string = usePrivateEndpoint ? vnet .outputs .vnetSubnets [ 0 ]. id : ''
118
- output privateDnsResolverSubnetId string = deployVpnGateway ? vnet .outputs .vnetSubnets [3 ]. id : ''
119
- output vnetName string = usePrivateEndpoint ? vnet .outputs .name : ''
120
- output vnetId string = usePrivateEndpoint ? vnet .outputs .id : ''
209
+
210
+ output backendSubnetId string = vnet .outputs .subnetResourceIds [ 0 ]
211
+ output privateDnsResolverSubnetId string = deployVpnGateway ? vnet .outputs .subnetResourceIds [ 2 ] : ''
212
+ output appSubnetId string = vnet .outputs .subnetResourceIds [3 ]
213
+ output vnetName string = vnet .outputs .name
214
+ output vnetId string = vnet .outputs .resourceId
0 commit comments