mcpField
T
terraform-azurerm-set-diff-analyzer

terraform-azurerm-set-diff-analyzer

github.com/github云与 DevOps40.5k8.9k 次安装今天更新
代码仓库

关于 terraform-azurerm-set-diff-analyzer

用于分析 Terraform AzureRM 计划差异的技能,可识别 Set 类型属性导致的误报,并将其与实际资源变更区分开。适合审查计划输出或在 CI/CD 中过滤此类差异。

主要功能

  1. 01读取 Terraform 计划 JSON
  2. 02识别 Set 属性误报差异
  3. 03区分真实资源变更
  4. 04支持 CI/CD 差异过滤

适用场景

  1. 01审查 Application Gateway 计划
  2. 02排查 Load Balancer 或 NSG 差异
  3. 03在 CI/CD 中过滤误报

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/github/awesome-copilot --skill terraform-azurerm-set-diff-analyzer

安装后在 Claude Code 中输入/terraform-azurerm-set-diff-analyzer确认已加载。

包含的文件

除 SKILL.md 外,安装时一起下载的参考资料和脚本。

references/
azurerm_set_attributes.json
azurerm_set_attributes.md
scripts/
.gitignore
analyze_plan.py
README.md

详细介绍

Terraform AzureRM Set Diff 分析器

一项用于识别 Terraform plan 中由 AzureRM Provider 的 Set 类型属性导致的“误报 diff”,并将其与实际变更区分开的技能。

使用场景

  • terraform plan 显示大量变更,但你只添加/删除了一个元素
  • Application Gateway、Load Balancer、NSG 等显示“所有元素均已变更”
  • 你希望在 CI/CD 中自动过滤误报 diff

背景

Terraform 的 Set 类型按位置而非按键进行比较,因此添加或删除元素时,所有元素都会显示为“已变更”。这是 Terraform 的通用问题,但在大量使用 Set 类型属性的 AzureRM 资源(如 Application Gateway、Load Balancer 和 NSG)中尤为明显。

这些“误报 diff”实际上不会影响资源,但会让审查 terraform plan 输出变得困难。

前提条件

  • Python 3.8+

如果 Python 不可用,请通过你的包管理器安装(例如 apt install python3、brew install python3),或从 python.org 安装。

基本用法

# 1. Generate plan JSON output
terraform plan -out=plan.tfplan
terraform show -json plan.tfplan > plan.json

# 2. Analyze
python scripts/analyze_plan.py plan.json

故障排查

  • python: command not found:改用 python3,或安装 Python
  • ModuleNotFoundError:脚本仅使用标准库;请确保 Python 3.8+

详细文档

评论

支持 Markdown