Skip to content

Commit 1217274

Browse files
author
sivakami
committed
create NSG.
1 parent 7c3a051 commit 1217274

File tree

1 file changed

+49
-2
lines changed

1 file changed

+49
-2
lines changed

.pipelines/swiftv2-long-running/scripts/create_nsg.sh

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,58 @@ set -e
33

44
SUBSCRIPTION_ID=$1
55
RG=$2
6+
LOCATION=${3:-centraluseuap}
67

78
VNET_A1="cx_vnet_a1"
89
S1_PREFIX="10.10.1.0/24"
910
S2_PREFIX="10.10.2.0/24"
1011
NSG_NAME="${VNET_A1}-nsg"
1112

12-
az network nsg create -g "$RG" -n "$NSG_NAME" --output none
13-
az network nsg rule create -g "$RG"
13+
echo "==> Creating Network Security Group: $NSG_NAME"
14+
az network nsg create -g "$RG" -n "$NSG_NAME" -l "$LOCATION" --output none
15+
16+
echo "==> Adding NSG rules"
17+
18+
# Allow SSH from any
19+
az network nsg rule create \
20+
-g "$RG" \
21+
--nsg-name "$NSG_NAME" \
22+
-n allow-ssh \
23+
--priority 100 \
24+
--source-address-prefixes "*" \
25+
--destination-port-ranges 22 \
26+
--direction Inbound \
27+
--access Allow \
28+
--protocol Tcp \
29+
--description "Allow SSH access" \
30+
--output none
31+
32+
# Allow internal VNet traffic
33+
az network nsg rule create \
34+
-g "$RG" \
35+
--nsg-name "$NSG_NAME" \
36+
-n allow-vnet \
37+
--priority 200 \
38+
--source-address-prefixes VirtualNetwork \
39+
--destination-address-prefixes VirtualNetwork \
40+
--direction Inbound \
41+
--access Allow \
42+
--protocol "*" \
43+
--description "Allow VNet internal traffic" \
44+
--output none
45+
46+
# Allow AKS API traffic
47+
az network nsg rule create \
48+
-g "$RG" \
49+
--nsg-name "$NSG_NAME" \
50+
-n allow-aks-controlplane \
51+
--priority 300 \
52+
--source-address-prefixes AzureCloud \
53+
--destination-port-ranges 443 \
54+
--direction Inbound \
55+
--access Allow \
56+
--protocol Tcp \
57+
--description "Allow AKS control plane traffic" \
58+
--output none
59+
60+
echo "NSG '$NSG_NAME' created successfully with rules."

0 commit comments

Comments
 (0)