Powershell 기반으로, 키고 끔을 통해 비용을 절감시킬 수 있다.

 

1. Application Gateway

$AppGw = Get-AzApplicationGateway -Name Test -ResourceGroupName Appgwtest
Stop-AzApplicationGateway -ApplicationGateway $AppGw

2. Azure Firewall

STOP

# Stop an existing firewall

$azfw = Get-AzFirewall -Name "FW Name" -ResourceGroupName "RG Name"
$azfw.Deallocate()
Set-AzFirewall -AzureFirewall $azfw

START

 

- forced tunneling 설정이 안되어 있을때

# Start the firewall

$azfw = Get-AzFirewall -Name "FW Name" -ResourceGroupName "RG Name"
$vnet = Get-AzVirtualNetwork -ResourceGroupName "RG Name" -Name "VNet Name"
$publicip1 = Get-AzPublicIpAddress -Name "Public IP1 Name" -ResourceGroupName "RG Name"
$publicip2 = Get-AzPublicIpAddress -Name "Public IP2 Name" -ResourceGroupName "RG Name"
$azfw.Allocate($vnet,@($publicip1,$publicip2))

Set-AzFirewall -AzureFirewall $azfw

- forced tunneling 설정이 되어있을 때

# Start the firewall

$azfw = Get-AzFirewall -Name "FW Name" -ResourceGroupName "RG Name"
$vnet = Get-AzVirtualNetwork -ResourceGroupName "RG Name" -Name "VNet Name"
$pip= Get-AzPublicIpAddress -ResourceGroupName "RG Name" -Name "azfwpublicip"
$mgmtPip2 = Get-AzPublicIpAddress -ResourceGroupName "RG Name" -Name "mgmtpip"
$azfw.Allocate($vnet, $pip, $mgmtPip2)
$azfw | Set-AzFirewall

 

- secured virtual hub architecture 일 때

# Start the firewall

$virtualhub = get-azvirtualhub -ResourceGroupName "RG name of vHUB" -name "vHUB name"
$azfw = Get-AzFirewall -Name "FW Name" -ResourceGroupName "Azfw RG Name"
$azfw.Allocate($virtualhub.Id)
$azfw | Set-AzFirewall

'Azure > Azure CLI' 카테고리의 다른 글

[Azure CLI] 1. az vm 대량 생성하는 법  (0) 2022.12.02

bash + Azure CLI 조합

 

csv와 bash의 while문을 활용하여, 여러대의 vm을 배포하는 스크립트이다.

 

 

 

* Azure Compute Gallery의 이미지를 사용한다고 가정

* Vnet은 배포되어있다고 가정

 

vm_ResourceGroup vm_type vm_name vm_subnet vm_sku
test-rg VirtualMachine test-01 test-subnet Standard_B1S
test-rg VirtualMachine test-02 test-subnet Standard_B1S
test-rg VirtualMachine test-03 test-subnet Standard_B1S
test-rg VirtualMachine test-04 test-subnet Standard_B1S
test-rg VirtualMachine test-05 test-subnet Standard_B1S
test-rg VirtualMachine test-06 test-subnet Standard_B1S
test-rg VirtualMachine test-07 test-subnet Standard_B1S
test-rg VirtualMachine test-08 test-subnet Standard_B1S
test-rg VirtualMachine test-09 test-subnet Standard_B1S
#!/bin/bash

subscription = 'koo-prod'
subnet_prefix = '/subscriptions/54e0cba4-d24d-4eb3-86d9-ea8cf67e4693/resourceGroups/prd-seas-gasp-common-rg/providers/Microsoft.Network/virtualNetworks/prd-seas-gasp-vnet/subnets/'

declare -i count
count=1
filename="vm.csv"
{ 
read
while IFS=, read -r vm_ResourceGroup vm_name vm_subnet vm_sku vm_image null;
do

    echo "I got:$vm_ResourceGroup | $vm_name | $vm_subnet | $vm_sku | $vm_image"

    az account set -s $subscription

    ###네트워크 인터페이스의 파라미터 값으로 해당 값을 넣어 nic 생성
    accnet=$(az vm list-skus --location koreacentral --all true --resource-type virtualMachines --size ${vm_sku} --query '[].{acceleratedNetworkingEnabled: capabilities[?name==`AcceleratedNetworkingEnabled`].value | [0]}' -o tsv)
    accnet="$(tr [A-Z] [a-z] <<< "$accnet")"


    #동적 IP 할당
    az network nic create --name ${vm_name}"-VMNic" \
                          --resource-group $vm_ResourceGroup \
                          --subnet ${subnet_prefix}"VM-subnet"
                          #--accelerated-networking ${accnet}
                          #--output none
    


    if [ "$accnet" == "true" ];
    then
    echo "${vm_sku}임으로, nic의 가속화된 네트워킹이 enabled 되었습니다"
    else
    echo "${vm_sku}이므로, nic의 가속화된 네트워킹이 disabled 입니다."
    fi

    privateip=`az network nic ip-config list --resource-group $vm_ResourceGroup --nic-name ${vm_name}"-VMNic" | grep "privateIpAddress" | grep -v Version | cut -d '"' -f 4`
    echo "$privateip 로 nic가 생성되었습니다."
    #필요한 IP만 뽑기위해 grep, cut	

    ###3번 static IP로 설정             
    #정적 IP 설정
    az network nic ip-config update \
                            --name ipconfig1 \
                            --resource-group $vm_ResourceGroup \
                            --nic-name ${vm_name}"-VMNic" \
                            --private-ip-address ${privateip}
	
    echo "$privateip 가 static으로 변경되었습니다."

    az vm create --name $vm_name \
                 --resource-group $vm_ResourceGroup \
                 --image /subscriptions/54e0cba4-d24d-4eb3-86d9-ea8cf67e4693/resourceGroups/test-rg/providers/Microsoft.Compute/galleries/gallerykoo/images/web-test/versions/0.1.3 \
                 --generate-ssh-keys \
                 --nics ${vm_name}"-VMNic" \
                 --os-disk-name ${vm_name}"-OSdisk" \
                 --size $vm_sku \
                 --zone 1 \
                 --no-wait

    echo " $count VMs created, this time $vm_name is deployed, ip is $privateip"
    count+=1
done
} < $filename

'Azure > Azure CLI' 카테고리의 다른 글

[Azure CLI] 2.사용하지 않는 리소스 중단  (1) 2022.12.02

+ Recent posts