跳到內容

拆除環境

當實驗課程結束後,請銷毀所有 Azure 資源以停止計費。

在包含 Terraform 設定的目錄中執行:

Terminal window
# Review what will be destroyed
terraform plan -destroy
# Destroy all resources
terraform destroy

Terraform 將提示確認。輸入 yes 以繼續。

確認所有資源已被移除:

Terminal window
# Check resource group is gone
az group show --name "$(terraform output -raw resource_group_name)" 2>&1 \
| grep -q "ResourceGroupNotFound" \
&& echo "Resource group deleted" \
|| echo "Resource group still exists"

移除 Terraform 狀態與快取檔案:

Terminal window
rm -rf .terraform .terraform.lock.hcl terraform.tfstate terraform.tfstate.backup

若您在整合過程中修改了 DNS 或 hosts 檔案,請還原這些變更:

Terminal window
# Remove hosts file entry (Linux/macOS)
sudo sed -i '/<CDN_EDGE_PUBLIC_IP>/d' /etc/hosts

若您建立了 DNS A 記錄,請透過您的 DNS 供應商將其刪除。