terraform-azurerm-set-diff-analyzer
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseTerraform AzureRM Set Diff Analyzer
Terraform AzureRM Set Diff 分析工具
A skill to identify "false-positive diffs" in Terraform plans caused by AzureRM Provider's Set-type attributes and distinguish them from actual changes.
一款用于识别由AzureRM Provider的Set类型属性导致的Terraform计划中“假阳性差异”,并将其与实际变更区分开的工具。
When to Use
使用场景
- shows many changes, but you only added/removed a single element
terraform plan - Application Gateway, Load Balancer, NSG, etc. show "all elements changed"
- You want to automatically filter false-positive diffs in CI/CD
- 显示大量变更,但你实际上只添加/删除了单个元素
terraform plan - 应用程序网关、负载均衡器、NSG等资源显示“所有元素已变更”
- 你希望在CI/CD中自动过滤假阳性差异
Background
背景信息
Terraform's Set type compares by position rather than by key, so when adding or removing elements, all elements appear as "changed". This is a general Terraform issue, but it's particularly noticeable with AzureRM resources that heavily use Set-type attributes like Application Gateway, Load Balancer, and NSG.
These "false-positive diffs" don't actually affect the resources, but they make reviewing terraform plan output difficult.
Terraform的Set类型是按位置而非键进行比较的,因此当添加或删除元素时,所有元素都会显示为“已变更”。这是Terraform的一个普遍问题,但在大量使用Set类型属性的AzureRM资源(如应用程序网关、负载均衡器和NSG)中尤为明显。
这些“假阳性差异”实际上不会对资源产生影响,但会增加审核terraform plan输出的难度。
Prerequisites
前置条件
- Python 3.8+
If Python is unavailable, install via your package manager (e.g., , ) or from python.org.
apt install python3brew install python3- Python 3.8+
Basic Usage
基础使用方法
bash
undefinedbash
undefined1. Generate plan JSON output
1. Generate plan JSON output
terraform plan -out=plan.tfplan
terraform show -json plan.tfplan > plan.json
terraform plan -out=plan.tfplan
terraform show -json plan.tfplan > plan.json
2. Analyze
2. Analyze
python scripts/analyze_plan.py plan.json
undefinedpython scripts/analyze_plan.py plan.json
undefinedTroubleshooting
故障排除
- : Use
python: command not foundinstead, or install Pythonpython3 - : Script uses only standard library; ensure Python 3.8+
ModuleNotFoundError
- :使用
python: command not found替代,或安装Pythonpython3 - :脚本仅使用标准库,请确保使用Python 3.8+版本
ModuleNotFoundError
Detailed Documentation
详细文档
- scripts/README.md - All options, output formats, exit codes, CI/CD examples
- references/azurerm_set_attributes.md - Supported resources and attributes
- scripts/README.md - 包含所有选项、输出格式、退出码、CI/CD示例
- references/azurerm_set_attributes.md - 支持的资源和属性