MODULE 03 Identity & Governance 20–25% đề thi ~2.5 giờ

Cấu hình Subscriptions

Azure regions & geographies, đăng ký và quản lý subscription, xem resource usage & limits, Cost Management & Budgets, resource tagging, và chiến lược tối ưu chi phí cloud cho doanh nghiệp.

Lý Thuyết Cốt Lõi

1. Azure Regions, Geographies & Availability Zones

Microsoft Azure vận hành hơn 60 regions trải khắp thế giới. Mỗi region là một tập hợp data center trong cùng một khu vực địa lý, kết nối với nhau qua mạng backbone tốc độ cao và độ trễ cực thấp. Khi triển khai resource, cần chọn region phù hợp về data residency, compliance, latency, và service availability.

Region
  • • Đơn vị địa lý cơ bản — VD: southeastasia (Singapore)
  • • Mỗi region có ít nhất 3 data center cách nhau ≥ vài km
  • • Region pairs: mỗi region ghép với region khác cùng geography để DR
  • • Southeast Asia ↔ East Asia (Hong Kong)
  • • Không phải mọi service đều có ở mọi region
Availability Zones
  • • 3 zone (Zone 1/2/3) trong cùng region, data center vật lý độc lập
  • • Kết nối bằng fiber riêng, độ trễ <2ms
  • • Bảo vệ khỏi failure của 1 data center
  • • Không phải region nào cũng có AZ (southeastasia có AZ)
  • • Zone-redundant resources tự phân tán qua 3 zone
Geography
  • • Nhóm region theo biên giới địa chính trị và compliance
  • • Asia Pacific gồm: Southeast Asia, East Asia, Japan, Korea, Australia, India
  • • Data residency đảm bảo data không rời geography
  • • Sovereign clouds: Azure Government, Azure China 21Vianet
Lưu ý cho doanh nghiệp VN: Azure chưa có region tại Việt Nam (2026). Gần nhất là southeastasia (Singapore) với độ trễ ~30ms. Đây là lựa chọn tốt nhất cho data residency ASEAN, tuân thủ Circular 06/2023/TT-NHNN của Ngân hàng Nhà nước.

2. Azure Subscription — Đăng Ký & Quản Lý

Subscription là đơn vị billing và quyền truy cập Azure. Mỗi resource phải thuộc một subscription. Một Entra ID tenant có thể có nhiều subscription, nhưng một subscription chỉ trust một tenant. Subscription có ID duy nhất (GUID) không thay đổi.

Loại Subscription Đặc điểm Phù hợp với
Pay-As-You-Go Thanh toán theo mức dùng, không cam kết, giá cao nhất Dev/Test, startup, workload không đoán trước được
Azure Free Account $200 credit 30 ngày + 12 tháng free services + always-free tier Học tập, lab, khám phá dịch vụ Azure
Enterprise Agreement (EA) Cam kết tiêu thụ tối thiểu 3 năm, giảm giá lớn, billing tập trung Doanh nghiệp lớn, chi tiêu Azure > $100K/năm
CSP (Cloud Solution Provider) Mua qua đối tác Microsoft, được hỗ trợ và billing qua đối tác SMB, doanh nghiệp VN mua qua distributor nội địa
Dev/Test Giá giảm cho workload non-production, yêu cầu Visual Studio subscription Môi trường dev, test, staging (không dùng production)
Resource Limits (Quotas)
  • • Mỗi subscription có giới hạn số lượng resource theo loại
  • • VD: tối đa 980 Resource Groups / subscription
  • • VD: tối đa 25,000 VMs / region / subscription
  • • Xem tại: Subscription → Usage + quotas
  • • Tăng quota qua: Support request → Quota increase
Chuyển Subscription
  • Transfer billing ownership: chuyển subscription sang account khác
  • Change directory (tenant): gắn subscription vào tenant Entra ID khác
  • Move resources: di chuyển resource giữa các subscription cùng tenant
  • • Một số resource không hỗ trợ move (xem Move support docs)

3. Cost Management + Billing

Azure Cost Management (tích hợp sẵn, không phí thêm) cung cấp khả năng phân tích, theo dõi và kiểm soát chi phí. Kết hợp với Budgets và Alerts để chủ động quản lý ngân sách cloud.

Cost Analysis

Phân tích chi phí theo resource, resource group, service, location, tag. Xem actual vs forecast. Export báo cáo CSV/Excel.

Budgets & Alerts

Đặt ngưỡng ngân sách (tháng/quý/năm), nhận email alert khi vượt 80%/90%/100%. Action groups kích hoạt automation (Logic App, Runbook) khi vượt budget.

Advisor Recommendations

Azure Advisor phát hiện resource tốn kém không dùng: VM underutilized <5% CPU, unattached disk, idle App Gateway. Khuyến nghị right-size hoặc xóa.

Tối ưu chi phí quan trọng nhất: (1) Reserved Instances — tiết kiệm 40–72% so với PAYG khi cam kết 1–3 năm; (2) Azure Spot VMs — tiết kiệm đến 90% cho workload interruptible; (3) Azure Hybrid Benefit — dùng Windows Server / SQL Server license on-prem cho Azure VM.

4. Resource Tagging — Phân Loại & Quản Lý Chi Phí

Tags là cặp key-value metadata gắn vào resource, resource group, hoặc subscription. Không ảnh hưởng đến hoạt động của resource — dùng thuần túy để phân loại, tìm kiếm, và phân bổ chi phí (chargeback/showback).

Quy tắc Tags
  • • Tối đa 50 tags mỗi resource/resource group/subscription
  • • Key tối đa 512 ký tự, Value tối đa 256 ký tự
  • Tags KHÔNG kế thừa từ RG xuống resource con — phải gán riêng hoặc dùng Azure Policy Append/Modify
  • • Tag key không phân biệt hoa-thường nhưng value phân biệt
  • • Một số resource type không hỗ trợ tags (VD: classic resources)
Tags Taxonomy khuyến nghị
Environment Production / Staging / Dev
CostCenter IT-001 / SALES-002
Project ERP-2024 / Portal-v2
CreatedDate 2024-06-22
Chiến lược tối ưu chi phí tổng hợp
Right-sizing

Dùng Azure Advisor để phát hiện VM underutilized. Downsize từ D4s_v3 xuống D2s_v3 nếu CPU <20% trong 30 ngày.

Reserved Instances

Workload chạy 24/7 (production DB, web server): mua Reserved 1-year = -40%, 3-year = -60% so với PAYG.

Auto-shutdown

Dev/Test VM tự tắt lúc 19:00, bật lúc 8:00 = tiết kiệm 54% chi phí (chỉ chạy 13h/ngày).

Bài Tập Thực Hành (Lab)

Lab M03-A: Subscription Info & Quotas Lab M03-B: Resource Tagging Lab M03-C: Budget Alert Lab M03-D: Cost Analysis Query
1

Kiểm tra thông tin Subscription, Regions và Resource Quotas

Azure CLI— Chạy được trên PowerShell, CMD, Bash hoặc Azure Cloud Shell
# Xem thông tin subscription hiện tại
az account show --query '{name:name, id:id, tenantId:tenantId, state:state}' -o json

# Liệt kê tất cả subscriptions có thể truy cập
az account list --query '[].{Name:name, ID:id, State:state, Default:isDefault}' -o table

# Xem tất cả Azure regions (tên + display name)
az account list-locations \
  --query '[].{Name:name, DisplayName:displayName, Region:metadata.regionType}' \
  -o table | grep -v "Logical" | head -30

# Xem regions ở Asia Pacific
az account list-locations \
  --query '[?contains(name, `asia`) || contains(name, `japan`) || contains(name, `korea`) || contains(name, `australia`) || contains(name, `india`)].{Name:name, Display:displayName}' \
  -o table

# Xem resource quotas tại Southeast Asia (VM cores)
az vm list-usage --location southeastasia \
  --query '[?contains(name.value,`cores`) || contains(name.value,`vCPUs`)].{Quota:name.localizedValue, Used:currentValue, Limit:limit}' \
  -o table

# Tạo Resource Group cho module 03
az group create \
  --name rg-az104-m03 \
  --location southeastasia \
  --tags Environment=Lab Module=03 Course=AZ-104 CostCenter=Training Owner=hoatranlab
Verify Portal: Azure Portal → Subscriptions → chọn subscription → Overview → ghi nhận Subscription ID, Tenant ID, Status. Vào Usage + quotas → lọc theo "Compute" → xem mức dùng hiện tại so với limit.
2

Gán Tags cho Resource Group và Resources — Thực hành tagging strategy

Azure CLI— Chạy được trên PowerShell, CMD, Bash hoặc Azure Cloud Shell
# Cập nhật tags trên Resource Group (merge với tags hiện có)
az tag update \
  --resource-id $(az group show --name rg-az104-m03 --query id -o tsv) \
  --operation Merge \
  --tags Environment=Lab Module=03 CostCenter=IT-Training \
         [email protected] Project=AZ104-Course \
         CreatedDate=2026-06-22

# Tạo Storage Account với tags đầy đủ
STORAGE_NAME="staz104m03$(date +%s | tail -c 6)"
az storage account create \
  --name $STORAGE_NAME \
  --resource-group rg-az104-m03 \
  --location southeastasia \
  --sku Standard_LRS \
  --kind StorageV2 \
  --tags Environment=Lab CostCenter=IT-Training \
         [email protected] Project=AZ104-Course \
         DataClassification=Internal

echo "Storage account created: $STORAGE_NAME"

# Xem tất cả tags trên Resource Group
az tag list \
  --resource-id $(az group show --name rg-az104-m03 --query id -o tsv) \
  --query 'properties.tags' -o json

# Tìm tất cả resources có tag Environment=Lab trong subscription
az resource list \
  --tag "Environment=Lab" \
  --query '[].{Name:name, Type:type, RG:resourceGroup, Location:location}' \
  -o table

# Xem tag summary toàn subscription
az resource list --query \
  '[].tags | [?@]' -o json | python3 -c "
import json,sys
from collections import Counter
tags=json.load(sys.stdin)
keys=Counter()
for t in tags:
    if t:
        for k in t.keys(): keys[k]+=1
for k,v in keys.most_common(10): print(f'  {k}: {v} resources')
"
Verify Portal: Azure Portal → rg-az104-m03 → Tags → xác nhận 6 tags. Vào All resources → lọc theo Tag: Environment = Lab → danh sách resource có tag. Vào Cost Management → Cost analysis → Group by: Tag → Environment để xem chi phí phân chia theo môi trường.
3

Tạo Budget Alert với Action Group gửi email thông báo

Bash— Linux/macOS/Cloud Shell, KHÔNG chạy CMD
SUB_ID=$(az account show --query id -o tsv)
RG_ID=$(az group show --name rg-az104-m03 --query id -o tsv)

# Tạo Action Group để nhận email alert
az monitor action-group create \
  --name "ag-az104-cost-alert" \
  --resource-group rg-az104-m03 \
  --short-name "CostAlert" \
  --email-receivers name="Admin" email-address="[email protected]"

AG_ID=$(az monitor action-group show \
  --name "ag-az104-cost-alert" \
  --resource-group rg-az104-m03 \
  --query id -o tsv)

# Tạo Budget tại scope Resource Group với 2 ngưỡng cảnh báo
az consumption budget create \
  --budget-name "budget-az104-m03-monthly" \
  --amount 20 \
  --category Cost \
  --time-grain Monthly \
  --start-date "2026-06-01" \
  --end-date "2026-12-31" \
  --resource-group rg-az104-m03 \
  --notifications \
    Actual_GreaterThan_80_Percent="{\"enabled\":true,\"operator\":\"GreaterThan\",\"threshold\":80,\"contactEmails\":[\"[email protected]\"],\"contactRoles\":[\"Owner\",\"Contributor\"]}" \
  2>/dev/null || echo "Note: Use Portal for budget creation if CLI version is older."

# Phương pháp thay thế: tạo budget qua REST API
TOKEN=$(az account get-access-token --query accessToken -o tsv)
curl -s -X PUT \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d "{
    \"properties\": {
      \"category\": \"Cost\",
      \"amount\": 20,
      \"timeGrain\": \"Monthly\",
      \"timePeriod\": {\"startDate\": \"2026-06-01\", \"endDate\": \"2026-12-31\"},
      \"notifications\": {
        \"Actual_80\": {
          \"enabled\": true, \"operator\": \"GreaterThan\", \"threshold\": 80,
          \"contactEmails\": [\"[email protected]\"], \"thresholdType\": \"Actual\"
        },
        \"Forecasted_100\": {
          \"enabled\": true, \"operator\": \"GreaterThan\", \"threshold\": 100,
          \"contactEmails\": [\"[email protected]\"], \"thresholdType\": \"Forecasted\"
        }
      }
    }
  }" \
  "https://management.azure.com${RG_ID}/providers/Microsoft.Consumption/budgets/budget-az104-m03-monthly?api-version=2023-05-01" \
  | python3 -c "import json,sys; d=json.load(sys.stdin); print('Budget:', d.get('name','created'), '| Amount:', d.get('properties',{}).get('amount','N/A'))"
Verify Portal: Azure Portal → Cost Management + Billing → Budgets → xác nhận budget budget-az104-m03-monthly với amount $20/tháng. Xem 2 alert conditions: 80% actual và 100% forecasted. Click budget → xem biểu đồ actual vs forecast vs budget.
4

Phân tích chi phí và xem Azure Advisor recommendations

Bash— Linux/macOS/Cloud Shell, KHÔNG chạy CMD
SUB_ID=$(az account show --query id -o tsv)
TOKEN=$(az account get-access-token --query accessToken -o tsv)

# Xem chi phí tháng hiện tại theo resource group
curl -s -X POST \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "type": "ActualCost",
    "timeframe": "MonthToDate",
    "dataset": {
      "granularity": "None",
      "grouping": [{"type": "Dimension", "name": "ResourceGroupName"}],
      "aggregation": {"totalCost": {"name": "Cost", "function": "Sum"}}
    }
  }' \
  "https://management.azure.com/subscriptions/$SUB_ID/providers/Microsoft.CostManagement/query?api-version=2023-11-01" \
  | python3 -c "
import json,sys
d=json.load(sys.stdin)
rows=d.get('properties',{}).get('rows',[])
cols=d.get('properties',{}).get('columns',[])
print(f'{'ResourceGroup':<40} {'Cost (USD)':>12}')
print('-'*54)
for r in sorted(rows, key=lambda x: x[0], reverse=True)[:10]:
    print(f'{str(r[1]):<40} {r[0]:>12.4f}')
"

# Xem Azure Advisor cost recommendations
az advisor recommendation list \
  --category Cost \
  --query '[].{Impact:impact, Problem:shortDescription.problem, Solution:shortDescription.solution}' \
  -o table 2>/dev/null | head -20

# Xem resource usage/quotas chi tiết tại southeastasia
az vm list-usage --location southeastasia \
  --query '[?currentValue > `0`].{Resource:name.localizedValue, Used:currentValue, Limit:limit, PctUsed:currentValue}' \
  -o table | head -20
Verify Portal: Cost Management → Cost analysis → Scope: Subscription → Group by: Resource group → xem biểu đồ theo tháng. Vào Azure Advisor → Cost → xem danh sách khuyến nghị tiết kiệm chi phí. Click từng recommendation → xem chi tiết resource và số tiền tiết kiệm ước tính.
5

Cleanup — Dọn dẹp tài nguyên lab

Azure CLI— Chạy được trên PowerShell, CMD, Bash hoặc Azure Cloud Shell
SUB_ID=$(az account show --query id -o tsv)
RG_ID=$(az group show --name rg-az104-m03 --query id -o tsv)

# Xóa Budget trước khi xóa RG (budget scope vào RG)
TOKEN=$(az account get-access-token --query accessToken -o tsv)
curl -s -X DELETE \
  -H "Authorization: Bearer $TOKEN" \
  "https://management.azure.com${RG_ID}/providers/Microsoft.Consumption/budgets/budget-az104-m03-monthly?api-version=2023-11-01" \
  && echo "Budget deleted." || echo "Budget not found or already deleted."

# Xóa Resource Group (kéo theo Action Group, Storage Account và tất cả resource)
az group delete --name rg-az104-m03 --yes --no-wait
echo "Resource group rg-az104-m03 deletion initiated."

# Xác nhận trạng thái xóa sau vài phút
sleep 10
az group show --name rg-az104-m03 --query provisioningState -o tsv 2>/dev/null \
  || echo "rg-az104-m03 đã xóa thành công."
Lưu ý: Budget và Action Group nằm trong RG nên sẽ bị xóa cùng khi xóa RG. Tuy nhiên, budget ở scope subscription (không có --resource-group) cần xóa riêng: az consumption budget delete --budget-name BudgetName. Cost data lịch sử vẫn giữ trong Cost Management sau khi xóa resource.

Kết Quả Đầu Ra

Hiểu Azure Regions & Geographies

Chọn region phù hợp dựa trên latency, compliance, data residency; biết region pairs và Availability Zones

Quản lý Subscription

Phân biệt các loại subscription (PAYG, EA, CSP); xem và request tăng quota; hiểu subscription hierarchy

Resource Tagging hiệu quả

Thiết kế taxonomy tag nhất quán; gán tags qua CLI; tìm resource theo tag; hiểu tags không kế thừa từ RG

Cấu hình Budget & Alerts

Tạo budget monthly với ngưỡng 80%/100%; kết hợp Action Group gửi email; budget ở scope RG và subscription

Phân tích chi phí qua Cost Management

Query cost qua REST API; phân tích actual vs forecast; group by tag/RG/service; export báo cáo

Chiến lược tối ưu chi phí

Áp dụng Reserved Instances, Spot VMs, Azure Hybrid Benefit, right-sizing, auto-shutdown để giảm bill

Ứng Dụng Thực Tế

Tình huống 1: Ngân hàng — Phân bổ chi phí cloud theo chi nhánh và sản phẩm

Ngân hàng có 3 subscription (Production, UAT, Dev), 50 resource groups, cần báo cáo chi phí hàng tháng cho 5 chi nhánh và 3 dòng sản phẩm riêng biệt.

Giải pháp

Tag taxonomy bắt buộc qua Policy: Branch (HN/HCM/DN/CT/HP), Product (Lending/Deposit/Payment), Environment (Prod/UAT/Dev). Cost Management → Export tự động CSV cuối tháng sang Blob Storage.

Triển khai

Azure Policy "Require Branch tag" áp tại Management Group → tất cả 3 subscription kế thừa. Budget $50K/tháng/subscription với alert 70%, 90%, 110%. Power BI kết nối trực tiếp Cost Management API cho dashboard CFO.

Lợi ích

Báo cáo chargeback chính xác đến từng chi nhánh và sản phẩm. CFO có dashboard real-time. Phát hiện product Lending tốn 40% budget nhưng chỉ dùng 15% tài nguyên → right-size tiết kiệm $12K/tháng.

Tình huống 2: Công ty Phần Mềm — Kiểm soát chi phí môi trường Dev/Test

Dev team spin-up nhiều VM và environment thử nghiệm, chi phí dev environment không được kiểm soát tăng từ $2K lên $8K/tháng.

Giải pháp

Subscription Dev/Test riêng (giá giảm 55% vs PAYG). Budget $3K/tháng với alert 80% → email team lead, 100% → trigger Logic App tự động shutdown tất cả VM có tag Environment=Dev. Auto-shutdown 19:00 bật 8:00 weekdays.

Triển khai

Policy "Allowed VM SKUs" cho Dev sub: chỉ cho tạo B2s, B4ms, D2s_v3 (không D32s_v3 đắt tiền). Tag AutoShutdown=Yes bắt buộc cho VM. Azure Automation Runbook scan tag và shutdown định kỳ 19:00.

Lợi ích

Chi phí dev giảm từ $8K xuống $2.8K/tháng (giảm 65%). Dev team không còn vô tình để VM chạy cuối tuần. Budget alert giúp team lead phát hiện sớm nếu có spike bất thường.

Tình huống 3: Hãng Hàng Không VN — Tuân thủ Data Residency & Tối ưu DR

Hệ thống đặt vé cần tuân thủ quy định lưu trữ dữ liệu tại Việt Nam/ASEAN; cần DR plan đảm bảo RPO <1 giờ và RTO <4 giờ cho mùa cao điểm Tết.

Giải pháp

Primary region: southeastasia (Singapore, ~30ms từ HN/HCM). DR region: eastasia (Hong Kong, region pair của Southeast Asia). Policy "Allowed locations" chỉ cho phép 2 region này. EA subscription với Reserved Instances 3-year cho production workload.

Triển khai

Production subscription tại southeastasia, DR subscription tại eastasia. Cost Management export monthly → Azure Blob → Power BI report cho ban lãnh đạo. Tag Criticality=Mission-Critical cho hệ thống booking để ưu tiên DR testing.

Lợi ích

Tuân thủ Circular 13/2018/TT-BGTVT về lưu trữ dữ liệu hàng không. Reserved Instances 3-year tiết kiệm $180K/năm so với PAYG. Tết Nguyên Đán 2025: 0 downtime trong 48h traffic tăng 300%.

Zalo