Skip to content

Commit 8cfdaa9

Browse files
authored
Merge pull request #227885 from AbdullahBell/tm-freshness-cli
Traffic Manager Freshness: Quickstart: Create a Traffic Manager profile for a highly available web application using Azure CLI
2 parents 554b6b2 + 2322b1e commit 8cfdaa9

File tree

1 file changed

+30
-47
lines changed

1 file changed

+30
-47
lines changed

articles/traffic-manager/quickstart-create-traffic-manager-profile-cli.md

Lines changed: 30 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ ms.service: traffic-manager
88
ms.topic: quickstart
99
ms.tgt_pltfrm: na
1010
ms.workload: infrastructure-services
11-
ms.date: 04/19/2021
11+
ms.date: 02/18/2023
1212
ms.author: greglin
1313
ms.custom: devx-track-azurecli, mode-api
1414
#Customer intent: As an IT admin, I want to direct user traffic to ensure high availability of web applications.
@@ -45,19 +45,20 @@ The following example creates a resource group named *myResourceGroup* in the *e
4545

4646
Create a Traffic Manager profile using [az network traffic-manager profile create](/cli/azure/network/traffic-manager/profile#az-network-traffic-manager-profile-create) that directs user traffic based on endpoint priority.
4747

48-
In the following example, replace **<profile_name>** with a unique Traffic Manager profile name.
4948

5049
```azurecli-interactive
5150
51+
mytrafficmanagerprofile='mytrafficmanagerprofile'$RANDOM
52+
5253
az network traffic-manager profile create \
53-
--name <profile_name> \
54+
--name $mytrafficmanagerprofile \
5455
--resource-group myResourceGroup \
5556
--routing-method Priority \
56-
--path "/" \
57-
--protocol HTTP \
58-
--unique-dns-name <profile_name> \
57+
--path '/' \
58+
--protocol "HTTP" \
59+
--unique-dns-name $mytrafficmanagerprofile \
5960
--ttl 30 \
60-
--port 80
61+
--port 80
6162
6263
```
6364

@@ -68,18 +69,17 @@ For this quickstart, you'll need two instances of a web application deployed in
6869
### Create web app service plans
6970
Create web app service plans using [az appservice plan create](/cli/azure/appservice/plan#az-appservice-plan-create) for the two instances of the web application that you will deploy in two different Azure regions.
7071

71-
In the following example, replace **<appspname_eastus>** and **<appspname_westeurope>** with a unique App Service Plan Name
7272

7373
```azurecli-interactive
7474
7575
az appservice plan create \
76-
--name <appspname_eastus> \
76+
--name myAppServicePlanEastUS \
7777
--resource-group myResourceGroup \
7878
--location eastus \
7979
--sku S1
8080
8181
az appservice plan create \
82-
--name <appspname_westeurope> \
82+
--name myAppServicePlanWestEurope \
8383
--resource-group myResourceGroup \
8484
--location westeurope \
8585
--sku S1
@@ -89,18 +89,19 @@ az appservice plan create \
8989
### Create a web app in the app service plan
9090
Create two instances the web application using [az webapp create](/cli/azure/webapp#az-webapp-create) in the App Service plans in the *East US* and *West Europe* Azure regions.
9191

92-
In the following example, replace **<app1name_eastus>** and **<app2name_westeurope>** with a unique App Name, and replace **<appspname_eastus>** and **<appspname_westeurope>** with the name used to create the App Service plans in the previous section.
93-
9492
```azurecli-interactive
9593
94+
mywebappeastus='myWebAppEastUS'$RANDOM
95+
myWebAppWestEurope='myWebAppWestEurope'$RANDOM
96+
9697
az webapp create \
97-
--name <app1name_eastus> \
98-
--plan <appspname_eastus> \
98+
--name $mywebappeastus \
99+
--plan myAppServicePlanEastUS \
99100
--resource-group myResourceGroup
100101
101102
az webapp create \
102-
--name <app2name_westeurope> \
103-
--plan <appspname_westeurope> \
103+
--name $myWebAppWestEurope \
104+
--plan myAppServicePlanWestEurope \
104105
--resource-group myResourceGroup
105106
106107
```
@@ -113,59 +114,41 @@ Add the two Web Apps as Traffic Manager endpoints using [az network traffic-mana
113114

114115
When the primary endpoint is unavailable, traffic automatically routes to the failover endpoint.
115116

116-
In the following example, replace **<app1name_eastus>** and **<app2name_westeurope>** with the App Names created for each region in the previous section. Then replace **<profile_name>** with the profile name used in the previous section.
117117

118118
**East US endpoint**
119119

120120
```azurecli-interactive
121121
122-
az webapp show \
123-
--name <app1name_eastus> \
124-
--resource-group myResourceGroup \
125-
--query id
126-
127-
```
128-
129-
Make note of ID displayed in output and use in the following command to add the endpoint:
130-
131-
```azurecli-interactive
122+
App1ResourceId=$(az webapp show --name $mywebappeastus --resource-group myResourceGroup --query id --output tsv)
132123
133124
az network traffic-manager endpoint create \
134-
--name <app1name_eastus> \
125+
--name $mywebappeastus \
135126
--resource-group myResourceGroup \
136-
--profile-name <profile_name> \
127+
--profile-name $mytrafficmanagerprofile \
137128
--type azureEndpoints \
138-
--target-resource-id <ID from az webapp show> \
129+
--target-resource-id $App1ResourceId \
139130
--priority 1 \
140131
--endpoint-status Enabled
132+
141133
```
142134

143135
**West Europe endpoint**
144136

145137
```azurecli-interactive
146138
147-
az webapp show \
148-
--name <app2name_westeurope> \
149-
--resource-group myResourceGroup \
150-
--query id
151-
152-
```
153-
154-
Make note of ID displayed in output and use in the following command to add the endpoint:
155-
156-
```azurecli-interactive
139+
App2ResourceId=$(az webapp show --name $myWebAppWestEurope --resource-group myResourceGroup --query id --output tsv)
157140
158141
az network traffic-manager endpoint create \
159-
--name <app2name_westeurope> \
142+
--name $myWebAppWestEurope \
160143
--resource-group myResourceGroup \
161-
--profile-name <profile_name> \
144+
--profile-name $mytrafficmanagerprofile \
162145
--type azureEndpoints \
163-
--target-resource-id <ID from az webapp show> \
146+
--target-resource-id $App2ResourceId \
164147
--priority 2 \
165148
--endpoint-status Enabled
166-
167149
```
168150

151+
169152
## Test your Traffic Manager profile
170153

171154
In this section, you'll check the domain name of your Traffic Manager profile. You'll also configure the primary endpoint to be unavailable. Finally, you get to see that the web app is still available. It's because Traffic Manager sends the traffic to the failover endpoint.
@@ -179,7 +162,7 @@ Determine the DNS name of the Traffic Manager profile using [az network traffic-
179162
```azurecli-interactive
180163
181164
az network traffic-manager profile show \
182-
--name <profile_name> \
165+
--name $mytrafficmanagerprofile \
183166
--resource-group myResourceGroup \
184167
--query dnsConfig.fqdn
185168
@@ -197,9 +180,9 @@ Copy the **RelativeDnsName** value. The DNS name of your Traffic Manager profile
197180
```azurecli-interactive
198181
199182
az network traffic-manager endpoint update \
200-
--name <app1name_eastus> \
183+
--name $mywebappeastus \
201184
--resource-group myResourceGroup \
202-
--profile-name <profile_name> \
185+
--profile-name $mytrafficmanagerprofile \
203186
--type azureEndpoints \
204187
--endpoint-status Disabled
205188

0 commit comments

Comments
 (0)