terraform-azurerm-set-diff-analyzer

terraform-azurerm-set-diff-analyzer

熱門

分析 Terraform plan 的 JSON 輸出(針對 AzureRM Provider),區分誤判的差異(Set 類型屬性的順序變更)與實際資源變更。在檢視 Terraform plan 輸出時使用,適用於 Application Gateway、Load Balancer、Firewall、Front Door、NSG 及其他因 Set 類型屬性導致假性差異的 Azure 資源。

3.7萬星標
4569分支
更新於 2026/7/14
SKILL.md
readonlyread-only
name
terraform-azurerm-set-diff-analyzer
description

分析 Terraform plan 的 JSON 輸出(針對 AzureRM Provider),區分誤判的差異(Set 類型屬性的順序變更)與實際資源變更。在檢視 Terraform plan 輸出時使用,適用於 Application Gateway、Load Balancer、Firewall、Front Door、NSG 及其他因 Set 類型屬性導致假性差異的 Azure 資源。

Terraform AzureRM Set Diff Analyzer

此技能用於識別 Terraform plan 中因 AzureRM Provider 的 Set 類型屬性而產生的「誤判差異」,並區分實際變更。

使用時機

  • terraform plan 顯示大量變更,但你只新增/移除了一個元素
  • Application Gateway、Load Balancer、NSG 等顯示「所有元素都已變更」
  • 你想要在 CI/CD 中自動過濾誤判差異

背景

Terraform 的 Set 類型是依位置而非鍵值進行比較,因此新增或移除元素時,所有元素都會顯示為「已變更」。這是 Terraform 的普遍問題,但在大量使用 Set 類型屬性的 AzureRM 資源(如 Application Gateway、Load Balancer、NSG)中特別明顯。

這些「誤判差異」實際上不會影響資源,但會讓檢視 terraform plan 輸出變得困難。

前置需求

  • Python 3.8+

如果 Python 不可用,請透過套件管理器安裝(例如 apt install python3brew install python3)或從 python.org 下載。

基本用法

# 1. 產生 plan JSON 輸出
terraform plan -out=plan.tfplan
terraform show -json plan.tfplan > plan.json

# 2. 分析
python scripts/analyze_plan.py plan.json

疑難排解

  • python: command not found:請改用 python3,或安裝 Python
  • ModuleNotFoundError:腳本僅使用標準函式庫;請確保 Python 3.8+

詳細文件