2021-06-24 13:55:55 +03:00
|
|
|
param resourceName string
|
|
|
|
param location string
|
2021-07-24 20:36:38 +03:00
|
|
|
param appGwSubnetId string
|
2021-08-17 18:44:10 +03:00
|
|
|
param privateIpApplicationGateway string
|
2021-07-23 22:10:37 +03:00
|
|
|
param availabilityZones array
|
|
|
|
param userAssignedIdentity string
|
|
|
|
param workspaceId string
|
|
|
|
param appGWcount int
|
|
|
|
param appGWmaxCount int
|
2021-07-09 09:27:00 +03:00
|
|
|
|
2021-07-14 15:21:09 +03:00
|
|
|
var appgwName = 'agw-${resourceName}'
|
|
|
|
var appgwResourceId = resourceId('Microsoft.Network/applicationGateways', '${appgwName}')
|
|
|
|
|
2021-06-24 13:55:55 +03:00
|
|
|
resource appgwpip 'Microsoft.Network/publicIPAddresses@2020-07-01' = {
|
|
|
|
name: 'pip-agw-${resourceName}'
|
|
|
|
location: location
|
|
|
|
sku: {
|
|
|
|
name: 'Standard'
|
|
|
|
}
|
|
|
|
properties: {
|
|
|
|
publicIPAllocationMethod: 'Static'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-09 09:27:00 +03:00
|
|
|
var frontendPublicIpConfig = {
|
|
|
|
properties: {
|
|
|
|
publicIPAddress: {
|
2023-03-16 13:37:07 +03:00
|
|
|
id: appgwpip.id
|
2021-07-09 09:27:00 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
name: 'appGatewayFrontendIP'
|
|
|
|
}
|
|
|
|
|
|
|
|
var frontendPrivateIpConfig = {
|
|
|
|
properties: {
|
|
|
|
privateIPAllocationMethod: 'Static'
|
2021-08-17 18:44:10 +03:00
|
|
|
privateIPAddress: privateIpApplicationGateway
|
2021-07-23 22:10:37 +03:00
|
|
|
subnet: {
|
2021-07-24 20:36:38 +03:00
|
|
|
id: appGwSubnetId
|
2021-07-09 09:27:00 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
name: 'appGatewayPrivateIP'
|
|
|
|
}
|
|
|
|
|
2021-07-23 22:10:37 +03:00
|
|
|
var tier = 'WAF_v2'
|
|
|
|
var appGWsku = union({
|
|
|
|
name: tier
|
|
|
|
tier: tier
|
|
|
|
}, appGWmaxCount == 0 ? {
|
|
|
|
capacity: appGWcount
|
|
|
|
} : {})
|
|
|
|
|
|
|
|
// ugh, need to create a variable with the app gateway properies, because of the conditional key 'autoscaleConfiguration'
|
|
|
|
var appgwProperties = union({
|
|
|
|
sku: appGWsku
|
|
|
|
gatewayIPConfigurations: [
|
|
|
|
{
|
|
|
|
name: 'besubnet'
|
|
|
|
properties: {
|
|
|
|
subnet: {
|
2021-07-24 20:36:38 +03:00
|
|
|
id: appGwSubnetId
|
2021-06-24 13:55:55 +03:00
|
|
|
}
|
|
|
|
}
|
2021-07-23 22:10:37 +03:00
|
|
|
}
|
|
|
|
]
|
2021-08-17 18:44:10 +03:00
|
|
|
frontendIPConfigurations: empty(privateIpApplicationGateway) ? array(frontendPublicIpConfig) : concat(array(frontendPublicIpConfig), array(frontendPrivateIpConfig))
|
2021-07-23 22:10:37 +03:00
|
|
|
frontendPorts: [
|
|
|
|
{
|
|
|
|
name: 'appGatewayFrontendPort'
|
|
|
|
properties: {
|
|
|
|
port: 80
|
2021-06-24 13:55:55 +03:00
|
|
|
}
|
2021-07-23 22:10:37 +03:00
|
|
|
}
|
|
|
|
]
|
|
|
|
backendAddressPools: [
|
|
|
|
{
|
|
|
|
name: 'defaultaddresspool'
|
|
|
|
}
|
|
|
|
]
|
|
|
|
backendHttpSettingsCollection: [
|
|
|
|
{
|
|
|
|
name: 'defaulthttpsetting'
|
|
|
|
properties: {
|
|
|
|
port: 80
|
|
|
|
protocol: 'Http'
|
|
|
|
cookieBasedAffinity: 'Disabled'
|
|
|
|
requestTimeout: 30
|
|
|
|
pickHostNameFromBackendAddress: true
|
2021-06-24 13:55:55 +03:00
|
|
|
}
|
2021-07-23 22:10:37 +03:00
|
|
|
}
|
|
|
|
]
|
|
|
|
httpListeners: [
|
|
|
|
{
|
|
|
|
name: 'hlisten'
|
|
|
|
properties: {
|
|
|
|
frontendIPConfiguration: {
|
|
|
|
id: '${appgwResourceId}/frontendIPConfigurations/appGatewayFrontendIP'
|
2021-06-24 13:55:55 +03:00
|
|
|
}
|
2021-07-23 22:10:37 +03:00
|
|
|
frontendPort: {
|
|
|
|
id: '${appgwResourceId}/frontendPorts/appGatewayFrontendPort'
|
2021-06-24 13:55:55 +03:00
|
|
|
}
|
2021-07-23 22:10:37 +03:00
|
|
|
protocol: 'Http'
|
2021-06-24 13:55:55 +03:00
|
|
|
}
|
2021-07-23 22:10:37 +03:00
|
|
|
}
|
|
|
|
]
|
|
|
|
requestRoutingRules: [
|
|
|
|
{
|
|
|
|
name: 'appGwRoutingRuleName'
|
|
|
|
properties: {
|
|
|
|
ruleType: 'Basic'
|
|
|
|
httpListener: {
|
|
|
|
id: '${appgwResourceId}/httpListeners/hlisten'
|
|
|
|
}
|
|
|
|
backendAddressPool: {
|
|
|
|
id: '${appgwResourceId}/backendAddressPools/defaultaddresspool'
|
|
|
|
}
|
|
|
|
backendHttpSettings: {
|
|
|
|
id: '${appgwResourceId}/backendHttpSettingsCollection/defaulthttpsetting'
|
2021-06-24 13:55:55 +03:00
|
|
|
}
|
|
|
|
}
|
2021-07-23 22:10:37 +03:00
|
|
|
}
|
|
|
|
]
|
|
|
|
}, appGWmaxCount > 0 ? {
|
|
|
|
autoscaleConfiguration: {
|
|
|
|
minCapacity: appGWcount
|
|
|
|
maxCapacity: appGWmaxCount
|
|
|
|
}
|
|
|
|
} : {})
|
|
|
|
|
|
|
|
var appGwZones = !empty(availabilityZones) ? availabilityZones : []
|
|
|
|
|
2021-12-07 14:07:06 +03:00
|
|
|
// 'identity' is always set until this is fixed:
|
2021-07-23 22:10:37 +03:00
|
|
|
// https://github.com/Azure/bicep/issues/387#issuecomment-885671296
|
|
|
|
resource appgw 'Microsoft.Network/applicationGateways@2020-07-01' = if (!empty(userAssignedIdentity)) {
|
|
|
|
name: appgwName
|
|
|
|
location: location
|
|
|
|
zones: appGwZones
|
2021-07-27 22:22:17 +03:00
|
|
|
identity: !empty(userAssignedIdentity) ? {
|
2021-07-23 22:10:37 +03:00
|
|
|
type: 'UserAssigned'
|
|
|
|
userAssignedIdentities: {
|
|
|
|
'${userAssignedIdentity}': {}
|
|
|
|
}
|
2021-07-27 22:22:17 +03:00
|
|
|
} : {}
|
2021-07-23 22:10:37 +03:00
|
|
|
properties: appgwProperties
|
|
|
|
}
|
2021-08-17 18:44:10 +03:00
|
|
|
|
|
|
|
param agicPrincipleId string
|
2022-11-17 17:33:44 +03:00
|
|
|
var contributor = subscriptionResourceId('Microsoft.Authorization/roleDefinitions', 'b24988ac-6180-42a0-ab88-20f7382dd24c')
|
2021-08-17 18:44:10 +03:00
|
|
|
// https://docs.microsoft.com/en-us/azure/role-based-access-control/role-assignments-template#new-service-principal
|
|
|
|
resource appGwAGICContrib 'Microsoft.Authorization/roleAssignments@2020-04-01-preview' = {
|
|
|
|
scope: appgw
|
|
|
|
name: guid(resourceGroup().id, appgwName, 'appgwcont')
|
|
|
|
properties: {
|
|
|
|
roleDefinitionId: contributor
|
|
|
|
principalType: 'ServicePrincipal'
|
|
|
|
principalId: agicPrincipleId
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-17 17:33:44 +03:00
|
|
|
var reader = subscriptionResourceId('Microsoft.Authorization/roleDefinitions', 'acdd72a7-3385-48ef-bd42-f606fba81ae7')
|
2021-08-17 18:44:10 +03:00
|
|
|
resource appGwAGICRGReader 'Microsoft.Authorization/roleAssignments@2020-04-01-preview' = {
|
|
|
|
scope: resourceGroup()
|
|
|
|
name: guid(resourceGroup().id, appgwName, 'rgread')
|
|
|
|
properties: {
|
|
|
|
roleDefinitionId: reader
|
|
|
|
principalType: 'ServicePrincipal'
|
|
|
|
principalId: agicPrincipleId
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-24 20:36:38 +03:00
|
|
|
output appgwId string = appgw.id
|
|
|
|
output ApplicationGatewayName string = appgw.name
|
2021-07-23 22:10:37 +03:00
|
|
|
|
|
|
|
// ------------------------------------------------------------------ AppGW Diagnostics
|
|
|
|
var diagProperties = {
|
|
|
|
workspaceId: workspaceId
|
|
|
|
logs: [
|
|
|
|
{
|
|
|
|
category: 'ApplicationGatewayAccessLog'
|
|
|
|
enabled: true
|
|
|
|
}
|
|
|
|
{
|
|
|
|
category: 'ApplicationGatewayPerformanceLog'
|
|
|
|
enabled: true
|
|
|
|
}
|
|
|
|
{
|
|
|
|
category: 'ApplicationGatewayFirewallLog'
|
|
|
|
enabled: true
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
2023-05-23 18:44:42 +03:00
|
|
|
resource appgw_Diag 'Microsoft.Insights/diagnosticSettings@2021-05-01-preview' = if (!empty(workspaceId)) {
|
2021-07-23 22:10:37 +03:00
|
|
|
scope: appgw
|
|
|
|
name: 'appgwDiag'
|
|
|
|
properties: diagProperties
|
2021-06-24 13:55:55 +03:00
|
|
|
}
|