forked from Azure/aks-engine
/
applicationgateway.go
132 lines (125 loc) · 5.35 KB
/
applicationgateway.go
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
package engine
import (
"github.com/Azure/aks-engine/pkg/api"
"github.com/Azure/azure-sdk-for-go/services/network/mgmt/2018-08-01/network"
"github.com/Azure/go-autorest/autorest/to"
)
func createApplicationGateway(prop *api.Properties) ApplicationGatewayARM {
applicationGateway := ApplicationGatewayARM{
ARMResource: ARMResource{
APIVersion: "[variables('apiVersionNetwork')]",
DependsOn: []string{
"[concat('Microsoft.Network/publicIPAddresses/', variables('appGwPublicIPAddressName'))]",
"[concat('Microsoft.Network/virtualNetworks/', variables('virtualNetworkName'))]",
},
},
ApplicationGateway: network.ApplicationGateway{
Location: to.StringPtr("[variables('location')]"),
Name: to.StringPtr("[variables('appGwName')]"),
ApplicationGatewayPropertiesFormat: &network.ApplicationGatewayPropertiesFormat{
Sku: &network.ApplicationGatewaySku{
Name: network.ApplicationGatewaySkuName("[parameters('appGwSku')]"),
Tier: network.ApplicationGatewayTier("[parameters('appGwSku')]"),
Capacity: to.Int32Ptr(2),
},
GatewayIPConfigurations: &[]network.ApplicationGatewayIPConfiguration{
{
Name: to.StringPtr("gatewayIP"),
ApplicationGatewayIPConfigurationPropertiesFormat: &network.ApplicationGatewayIPConfigurationPropertiesFormat{
Subnet: &network.SubResource{
ID: to.StringPtr("[concat(variables('vnetID'),'/subnets/',variables('appGwSubnetName'))]"),
},
},
},
},
FrontendIPConfigurations: &[]network.ApplicationGatewayFrontendIPConfiguration{
{
Name: to.StringPtr("frontendIP"),
ApplicationGatewayFrontendIPConfigurationPropertiesFormat: &network.ApplicationGatewayFrontendIPConfigurationPropertiesFormat{
PublicIPAddress: &network.SubResource{
ID: to.StringPtr("[resourceId('Microsoft.Network/publicIpAddresses',variables('appGwPublicIPAddressName'))]"),
},
},
},
},
FrontendPorts: &[]network.ApplicationGatewayFrontendPort{
{
Name: to.StringPtr("httpPort"),
ApplicationGatewayFrontendPortPropertiesFormat: &network.ApplicationGatewayFrontendPortPropertiesFormat{
Port: to.Int32Ptr(80),
},
},
},
BackendAddressPools: &[]network.ApplicationGatewayBackendAddressPool{
{
Name: to.StringPtr("pool"),
ApplicationGatewayBackendAddressPoolPropertiesFormat: &network.ApplicationGatewayBackendAddressPoolPropertiesFormat{
BackendAddresses: &[]network.ApplicationGatewayBackendAddress{},
},
},
},
HTTPListeners: &[]network.ApplicationGatewayHTTPListener{
{
Name: to.StringPtr("httpListener"),
ApplicationGatewayHTTPListenerPropertiesFormat: &network.ApplicationGatewayHTTPListenerPropertiesFormat{
Protocol: network.HTTP,
FrontendPort: &network.SubResource{
ID: to.StringPtr("[concat(variables('appGwId'), '/frontendPorts/httpPort')]"),
},
FrontendIPConfiguration: &network.SubResource{
ID: to.StringPtr("[concat(variables('appGwId'), '/frontendIPConfigurations/frontendIP')]"),
},
},
},
},
BackendHTTPSettingsCollection: &[]network.ApplicationGatewayBackendHTTPSettings{
{
Name: to.StringPtr("setting"),
ApplicationGatewayBackendHTTPSettingsPropertiesFormat: &network.ApplicationGatewayBackendHTTPSettingsPropertiesFormat{
Port: to.Int32Ptr(80),
Protocol: network.HTTP,
},
},
},
RequestRoutingRules: &[]network.ApplicationGatewayRequestRoutingRule{
{
Name: to.StringPtr("rule"),
ApplicationGatewayRequestRoutingRulePropertiesFormat: &network.ApplicationGatewayRequestRoutingRulePropertiesFormat{
HTTPListener: &network.SubResource{
ID: to.StringPtr("[concat(variables('appGwId'), '/httpListeners/httpListener')]"),
},
BackendAddressPool: &network.SubResource{
ID: to.StringPtr("[concat(variables('appGwId'), '/backendAddressPools/pool')]"),
},
BackendHTTPSettings: &network.SubResource{
ID: to.StringPtr("[concat(variables('appGwId'), '/backendHttpSettingsCollection/setting')]"),
},
},
},
},
},
Type: to.StringPtr("Microsoft.Network/applicationGateways"),
},
}
if prop.OrchestratorProfile.KubernetesConfig.GetAddonByName(AppGwIngressAddonName).Config["appgw-sku"] == "WAF_v2" {
applicationGateway.ApplicationGateway.ApplicationGatewayPropertiesFormat.WebApplicationFirewallConfiguration = &network.ApplicationGatewayWebApplicationFirewallConfiguration{
Enabled: to.BoolPtr(true),
FirewallMode: network.Detection,
}
}
privateIP := prop.OrchestratorProfile.KubernetesConfig.GetAddonByName(AppGwIngressAddonName).Config["appgw-private-ip"]
if privateIP != "" {
frontendIPConfigurations := append(
*applicationGateway.ApplicationGateway.ApplicationGatewayPropertiesFormat.FrontendIPConfigurations,
network.ApplicationGatewayFrontendIPConfiguration{
Name: to.StringPtr("privateIp"),
ApplicationGatewayFrontendIPConfigurationPropertiesFormat: &network.ApplicationGatewayFrontendIPConfigurationPropertiesFormat{
PrivateIPAddress: to.StringPtr(privateIP),
},
})
applicationGateway.ApplicationGateway.ApplicationGatewayPropertiesFormat.FrontendIPConfigurations = &frontendIPConfigurations
}
return applicationGateway
}