SuperAPI AI 工具集

terraform-module-library

部署与运维

查看项目

更新于 10-15 21:11

技能介绍

用途:创建跨 AWS、Azure、GCP 的可复用、经过测试的 Terraform 模块,用于标准化云资源供给、实现基础设施即代码最佳实践、建立组织级 Terraform 规范。不适用于与 Terraform 模块库无关的任务或超出该范围的领域。

主要能力:提供标准模块目录结构(main.tf、variables.tf、outputs.tf、versions.tf、README.md、examples/、tests/),按云厂商组织模块(aws 下含 vpc、eks、rds、s3;azure 下含 vnet、aks、storage;gcp 下含 vpc、gke、cloud-sql)。给出 AWS VPC 模块示例,包含 aws_vpc、aws_subnet、aws_internet_gateway 资源,变量校验(如 CIDR 正则校验)、输出(vpc_id、private_subnet_ids、vpc_cidr_block)以及模块组合调用示例。

最佳实践:模块使用语义化版本;为所有变量编写描述;在 examples/ 提供示例;使用 validation 块校验输入;输出关键属性以支持模块组合;在 versions.tf 固定 provider 版本;用 locals 处理计算值;用 count/for_each 实现条件资源;用 Terratest 测试模块;统一为资源打标签。

使用方式:按标准模块模式组织文件,通过 module 块引用模块并传入变量,如 source、name、cidr_block、availability_zones、private_subnet_cidrs、tags 等;模块间可通过输出组合,例如将 VPC 的 vpc_id 与 private_subnet_ids 传给 RDS 模块。测试使用 Terratest,示例中通过 terraform.InitAndApply 与 terraform.Output 验证输出非空,并用 defer terraform.Destroy 清理。

参考文件:assets/vpc-module/、assets/rds-module/ 提供完整示例;references/aws-modules.md、references/azure-modules.md、references/gcp-modules.md 提供各云模块模式。相关技能包括 multi-cloud-architecture 与 cost-optimization。

限制:资料未提供具体安装命令、收费或价格信息;示例代码仅作模式参考,实际使用需结合具体环境调整。