-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAppServiceAndAppGW.ps1
More file actions
101 lines (94 loc) · 3.52 KB
/
AppServiceAndAppGW.ps1
File metadata and controls
101 lines (94 loc) · 3.52 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
98
99
100
101
#建立資源群組
$resourceGroup = "AppGW"
$location = "Japan East"
New-AzResourceGroup -Name $resourceGroup -Location $location
#建立網路安全性群組
$networkSecurityGroup = New-AzNetworkSecurityGroup -Name "AppGW-NSG" -ResourceGroupName $resourceGroup -Location $location
#建立虛擬網路
$agSubnetConfig = New-AzVirtualNetworkSubnetConfig `
-Name myAGSubnet `
-AddressPrefix 10.0.1.0/24
$backendSubnetConfig = New-AzVirtualNetworkSubnetConfig `
-Name myBackendSubnet `
-AddressPrefix 10.0.2.0/24 `
-NetworkSecurityGroup $networkSecurityGroup
New-AzVirtualNetwork `
-ResourceGroupName $resourceGroup `
-Location $location `
-Name myVNet `
-AddressPrefix 10.0.0.0/16 `
-Subnet $agSubnetConfig,$backendSubnetConfig
New-AzPublicIpAddress `
-ResourceGroupName $resourceGroup `
-Location $location `
-Name myAGPublicIPAddress `
-AllocationMethod Static `
-Sku Standard
#建立應用程式匣道設定
$vnet = Get-AzVirtualNetwork -ResourceGroupName $resourceGroup -Name myVNet
$subnet = Get-AzVirtualNetworkSubnetConfig -VirtualNetwork $vnet -Name myAGSubnet
$pip = Get-AzPublicIPAddress -ResourceGroupName $resourceGroup -Name myAGPublicIPAddress
$gipconfig = New-AzApplicationGatewayIPConfiguration `
-Name myAGIPConfig `
-Subnet $subnet
$fipconfig = New-AzApplicationGatewayFrontendIPConfig `
-Name myAGFrontendIPConfig `
-PublicIPAddress $pip
$frontendport = New-AzApplicationGatewayFrontendPort `
-Name myFrontendPort `
-Port 80
#建立應用程式匣道後端集區
$backendPool = New-AzApplicationGatewayBackendAddressPool `
-Name myAGBackendPool
$poolSettings = New-AzApplicationGatewayBackendHttpSetting `
-Name myPoolSettings `
-Port 80 `
-Protocol Http `
-CookieBasedAffinity Enabled `
-RequestTimeout 30 `
-PickHostNameFromBackendAddress
#建立Listener和規則
$defaultlistener = New-AzApplicationGatewayHttpListener `
-Name myAGListener `
-Protocol Http `
-FrontendIPConfiguration $fipconfig `
-FrontendPort $frontendport
$frontendRule = New-AzApplicationGatewayRequestRoutingRule `
-Name rule1 `
-RuleType Basic `
-HttpListener $defaultlistener `
-BackendAddressPool $backendPool `
-priority "1" `
-BackendHttpSettings $poolSettings
#建立應用程式
$sku = New-AzApplicationGatewaySku `
-Name WAF_v2 `
-Tier WAF_v2 `
-Capacity 2
New-AzApplicationGateway `
-Name AppGW `
-ResourceGroupName $resourceGroup `
-Location $location `
-BackendAddressPools $backendPool `
-BackendHttpSettingsCollection $poolSettings `
-FrontendIpConfigurations $fipconfig `
-GatewayIpConfigurations $gipconfig `
-FrontendPorts $frontendport `
-HttpListeners $defaultlistener `
-RequestRoutingRules $frontendRule `
-Sku $sku
#建立應用程式服務
# Replace the following URL with a public GitHub repo URL
$gitrepo="https://github.com/Azure-Samples/app-service-web-dotnet-get-started.git"
$webappname="mywebapp$(Get-Random)"
# Create an App Service plan in Free tier.
New-AzAppServicePlan -Name $webappname -Location $location -ResourceGroupName $resourceGroup -Tier Standard
# Create a web app.
New-AzWebApp -Name $webappname -Location $location -AppServicePlan $webappname -ResourceGroupName $resourceGroup
# Configure GitHub deployment from your GitHub repo and deploy once.
$PropertiesObject = @{
repoUrl = "$gitrepo";
branch = "master";
isManualIntegration = "true";
}
Set-AzResource -Properties $PropertiesObject -ResourceGroupName $resourceGroup -ResourceType Microsoft.Web/sites/sourcecontrols -ResourceName $webappname/web -ApiVersion 2015-08-01 -Force