跳到正文
Skillpedia
部署与云(DevOps)40k · #7249

import-infrastructure-as-code

它能做什么

这个工具可以把你现有的 Azure 基础设施转换成 Terraform 代码。它会自动发现你的云资源,并使用标准模块(AVM)把它们重新创建出来,让管理和复制都更方便。

适用场景

  • ✓当你想重新创建一套现有的 Azure 基础设施的时候。
  • ✓当你想把 Azure 资源变成可以做版本管理、反复复用的代码的时候。
  • ✓当你在做基础设施迁移或者备份配置的时候。

技能链接

https://github.com/github/awesome-copilot/blob/main/skills/import-infrastructure-as-code/SKILL.md

复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。

使用方法

最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/github/awesome-copilot/blob/main/skills/import-infrastructure-as-code/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 AI

“请把订阅 “12345678-abcd-1234-abcd-1234567890ab” 里的资源组 “my-app” 转换成 Terraform 代码,并使用 AVM 模块。”

每周 5 个新技能,1 分钟读完。

工作原理

工具会借助 Azure 命令行工具(Azure CLI)读取你现有的资源信息。然后,它会查找与这些资源匹配的标准模块(Azure Verified Modules,即 AVM),并生成对应的 Terraform 代码。

技术内容(原始 SKILL.md)

作者在 GitHub 上的英文原文。

Import Infrastructure as Code (Azure -> Terraform with AVM)

Convert existing Azure infrastructure into maintainable Terraform code using discovery data and Azure Verified Modules.

When to Use This Skill

Use this skill when the user asks to:

  • Import existing Azure resources into Terraform
  • Generate IaC from live Azure environments
  • Handle any Azure resource type supported by AVM (and document justified non-AVM fallbacks)
  • Recreate infrastructure from a subscription or resource group
  • Map dependencies between discovered Azure resources
  • Use AVM modules instead of handwritten azurerm_* resources

Prerequisites

  • Azure CLI installed and authenticated (az login)
  • Access to the target subscription or resource group
  • Terraform CLI installed
  • Network access to Terraform Registry and AVM index sources

Inputs

Parameter Required Default Description
subscription-id No Active CLI context Azure subscription used for subscription-scope discovery and context setting
resource-group-name No None Azure resource group used for resource-group-scope discovery
resource-id No None One or more Azure ARM resource IDs used for specific-resource-scope discovery

At least one of subscription-id, resource-group-name, or resource-id is required.

Step-by-Step Workflows

1) Collect Required Scope (Mandatory)

Request one of these scopes before running discovery commands:

  • Subscription scope: <subscription-id>
  • Resource group scope: <resource-group-name>
  • Specific resources scope: one or more <resource-id> values

Scope handling rules:

  • Treat Azure ARM resource IDs (for example /subscriptions/.../providers/...) as cloud resource identifiers, not local file system paths.
  • Use resource IDs only with Azure CLI --ids arguments (for example az resource show --ids <resource-id>).
  • Never pass resource IDs to file-reading commands (cat, ls, read_file, glob searches) unless the user explicitly says they are local file paths.
  • If the user already provided one valid scope, do not ask for additional scope inputs unless required by a failing command.
  • Do not ask follow-up questions that can be answered from already-provided scope values.

If scope is missing, ask for it explicitly and stop.

2) Authenticate and Set Context

Run only the commands required for the selected scope.

For subscription scope:

az login
az account set --subscription <subscription-id>
az account show --query "{subscriptionId:id, name:name, tenantId:tenantId}" -o json

Expected output: JSON object with subscriptionId, name, and tenantId.

For resource group or specific resource scope, az login is still required but az account set is optional if the active context is already correct.

When using specific resource scope, prefer direct --ids-based commands first and avoid extra discovery prompts for subscription or resource group unless needed for a concrete command.

3) Run Discovery Commands

Discover resources using the selected scopes. Ensure to fetch all necessary information for accurate Terraform generation.

# Subscription scope
az resource list --subscription <subscription-id> -o json

# Resource group scope
az resource list --resource-group <resource-group-name> -o json

# Specific resource scope
az resource show --ids <resource-id-1> <resource-id-2> ... -o json

Expected output: JSON object or array containing Azure resource metadata (id, type, name, location, tags, properties).

4) Resolve Dependencies Before Code Generation

Parse exported JSON and map:

  • Parent-child relationships (for example: NIC -> Subnet -> VNet)
  • Cross-resource references in properties
  • Ordering for Terraform creation

IMPORTANT: Generate the following documentation and save it to a docs folder in the root of the project.

  • exported-resources.json with all discovered resources and their metadata, including dependencies and references.
  • EXPORTED-ARCHITECTURE.MD file with a human-readable architecture overview based on the discovered resources and their relationships.

5) Select Azure Verified Modules (Required)

Use the latest AVM version for each resource type.

Terraform Registry

  • Search for "avm" + resource name
  • Filter by "Partner" tag to find official AVM modules
  • Example: Search "avm storage account" → filter by Partner

Official AVM Index

…

常见问题

什么是“AVM 模块”?

它们是由微软测试过的标准化构建模块,用来通过 Terraform 搭建 Azure 基础设施,能保证配置的一致性和安全性。

我需要先安装 Terraform 吗?

需要。你的电脑上要先安装 Terraform 命令行工具,工具才能生成并使用这些代码。

如果某个 Azure 资源没有对应的 AVM 模块怎么办?

工具会尽量把这种情况记录下来,还可能给出替代方案,或者提示这个资源需要你手动配置。

详情

作者的原始描述

Import existing Azure resources into Terraform using Azure CLI discovery and Azure Verified Modules (AVM). Use when asked to reverse-engineer live Azure infrastructure, generate Infrastructure as Code from existing subscriptions/resource groups/resource IDs, map dependencies, derive exact import addresses from downloaded module source, prevent configuration drift, and produce AVM-based Terraform f

repo: github/awesome-copilot

热度

GitHub 星标
40k
排名
#7249
许可证
MIT
更新时间
2026/10/15

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能