tf-module-generator: 自动化 Terraform 模块生成 - Openclaw Skills

作者:互联网

2026-04-14

AI教程

什么是 tf-module-generator?

tf-module-generator 是一款先进的自动化工具,旨在弥合手动云配置与基础设施即代码 (IaC) 之间的鸿沟。通过分析主流云供应商的现有资源,它能够智能地合成模块化的 Terraform 代码,并包含变量定义和输出。这确保了您的基础设施按照行业最佳实践进行记录、可复现且标准化。

作为 Openclaw Skills 生态系统的重要组成部分,此工具简化了将遗留环境迁移到托管代码库的过程。它消除了资源映射的手动劳动,让 DevOps 团队能够专注于高层架构,而由该工具处理样板代码生成和语法验证。

下载入口:https://github.com/openclaw/skills/tree/main/skills/martinforsulu/neo-tf-module-generator

安装与下载

1. ClawHub CLI

从源直接安装技能的最快方式。

npx clawhub@latest install neo-tf-module-generator

2. 手动安装

将技能文件夹复制到以下位置之一

全局模式 ~/.openclaw/skills/ 工作区 /skills/

优先级:工作区 > 本地 > 内置

3. 提示词安装

将此提示词复制到 OpenClaw 即可自动安装。

请帮我使用 Clawhub 安装 neo-tf-module-generator。如果尚未安装 Clawhub,请先安装(npm i -g clawhub)。

tf-module-generator 应用场景

  • 将手动创建的 AWS、Azure 或 GCP 资源迁移到 Terraform 管理中
  • 通过从现有生产环境生成模块来标准化基础设施模式
  • 加速为 VPC、数据库和计算集群创建可重用的 IaC 模板
  • 通过生成的 Terraform 代码和示例用法文件实现资源文档自动化
  • 在 Openclaw Skills 工作流中简化多云管理
tf-module-generator 工作原理
  1. 该工具通过 CLI 或代理命令触发,指定目标云供应商和资源范围。
  2. 它利用本地云供应商凭据来扫描和发现活动的基础设施组件。
  3. 引擎根据预定义的架构模板和供应商逻辑映射发现的资源。
  4. 生成优化的 Terraform 代码,包括 variables.tf、outputs.tf 和 main.tf 文件。
  5. 集成的验证器进行语法检查和最佳实践审核,确保代码已就绪可部署。

tf-module-generator 配置指南

要开始使用,请确保您的系统中配置了 Node.js 18+ 和相关的云 CLI。此工具直接与 Openclaw Skills 集成,以增强自动化。

# 克隆仓库并安装依赖
npm install

# 确保您的云 CLI 已通过身份验证(例如 AWS)
aws configure

# 为特定供应商运行生成器
node scripts/main.js --provider aws --resource-type vpc

tf-module-generator 数据架构与分类体系

该工具通过专注于资源映射和代码合成的结构化目录来组织其操作:

组件 功能
scripts/ AWS、Azure 和 GCP 扫描器以及 Terraform 生成器的逻辑
references/ 基于 JSON 的资源架构映射和模块模板
assets/ 示例用例、测试文件和 Terraform 版本约束
package.json 项目元数据和 Node.js 依赖项管理
name: tf-module-generator
description: Automatically generates Terraform modules from existing cloud infrastructure resources with intelligent resource detection and best-practice code formatting.

tf-module-generator Skill Documentation

1. Skill Name

tf-module-generator

2. Description

Automatically generates Terraform modules from existing cloud infrastructure resources across AWS, Azure, and GCP. The skill discovers live cloud resources, creates optimized Terraform code with proper variable definitions and outputs, and validates the generated modules against Terraform best practices.

3. Core Capabilities

  • Scan and analyze existing cloud infrastructure resources across AWS, Azure, and GCP
  • Generate optimized Terraform module code with proper variable definitions and outputs
  • Support multiple resource types (compute, storage, networking, databases, etc.)
  • Generate documentation and example usage for each generated module
  • Validate generated Terraform syntax and best practices
  • Provide CLI interface with customizable output options and error handling
  • Integrate seamlessly with OpenClaw agent workflows for automated infrastructure management

4. Out of Scope

  • Infrastructure provisioning (only generates code from existing resources)
  • Cost optimization recommendations
  • Security policy enforcement
  • Multi-environment management (dev/staging/prod)
  • State management or backend configuration
  • Testing the generated modules beyond syntax validation
  • Support for non-cloud infrastructure (on-prem, hybrid environments)

5. Trigger Scenarios

  • "Generate Terraform module from my existing AWS EC2 instances"
  • "Convert my Azure resources to Terraform modules"
  • "Create Terraform code from my GCP cloud resources"
  • "Generate module for my current VPC configuration"
  • "Automate Terraform module creation for our cloud infrastructure"
  • "Generate Terraform from existing [service] resources"
  • "Create reusable Terraform modules from our deployed resources"

6. Requirements

  • Cloud provider credentials configured (AWS CLI, Azure CLI, or GCP CLI)
  • Node.js 18+ runtime
  • Access to terraform binary for validation (optional but recommended)
  • OpenCl agent with sessions_spawn capability

7. Key Files

  • SKILL.md: This documentation
  • scripts/main.js: CLI entry point and command parsing
  • scripts/aws-scanner.js: AWS resource discovery and analysis
  • scripts/azure-scanner.js: Azure resource discovery and analysis
  • scripts/gcp-scanner.js: GCP resource discovery and analysis
  • scripts/terraform-generator.js: Terraform module code generation logic
  • scripts/validator.js: Generated code syntax and best practice validation
  • scripts/config.js: Configuration management and provider settings
  • references/providers.json: Cloud provider resource schema mappings
  • references/templates/: Directory containing module templates for different resource types
  • assets/examples/: Sample usage examples and test cases
  • assets/terraform-version: Supported Terraform version constraints
  • package.json: npm package metadata and dependencies
  • README.md: Quick start guide

8. Acceptance Criteria

  • CLI successfully scans and identifies resources from at least 3 cloud providers
  • Generated Terraform modules pass syntax validation with terraform validate
  • All generated code follows Terraform best practices conventions
  • Skill integrates correctly with OpenClaw session_spawn for agent usage
  • Error handling provides clear, actionable feedback for common failure cases
  • Documentation includes usage examples for both CLI and agent integration
  • Code passes all automated tests including security checks
  • Generated modules include appropriate variables, outputs, and documentation
  • Skill triggers correctly for all defined trigger scenarios
  • Performance benchmarks meet targets for typical infrastructure sizes (<1k resources)