地形
- 作者仓库星标 0
- 作者仓库 skills-registry
- 领域
- 运维部署
- 作者声明的智能体
- 未找到明确声明;不据此推断已兼容或已测试
- 静态检查
- 88 / 100 · 启发式扫描,不代表运行安全
- 运行环境证据
- 未执行;当前没有隔离运行测试证据
- 作者 / 版本 / 许可证
- @tomevault-io · 未声明许可证
- 上下文用量评级
- 低消耗
- 接入复杂程度
- 即装即用
- 是否需要外部接口密钥
- 不需要
- 兼容的系统
- 未声明(默认跨平台)
- 运行环境要求
- 未检出明确要求
- 检测到的文件与系统行为
-
- 只读
- 允许写入 / 修改
- 网络行为
- 仅限本地
- 安装命令数
- 无(仅作为资料)
需要注意: 未声明工具权限范围;实际权限由运行环境决定。
# Terraform / Infrastructure as Code
Manage infrastructure with Terraform.
## Core Concepts
### State Management
- Store state remotely (S3, Terraform Cloud)
- Enable state locking (DynamoDB)
- Never edit state manually (use `terraform state` commands)
- Isolate environments with workspaces or directories
### Structure
```
terraform/
├── modules/
│ ├── networking/
│ ├── compute/
│ └── database/
├── environments/
│ ├── dev/
│ │ ├── main.tf
│ │ ├── variables.tf
│ │ └── terraform.tfvars
│ ├── staging/
│ └── production/
└── backend.tf
```
## Module Design
### Module Interface
```hcl
# modules/compute/main.tf
variable "instance_type" { type = string }
variable "subnet_id" { type = string }
output "instance_id" { value = aws_instance.app.id }
```
### Module Best Practices
- Input validation (type constraints, validation blocks)
- Outputs for all useful values
- Versioned modules (Git tags, registry)
- Documentation (README per module)
- Test with Terratest
## Remote Backend
```hcl
terraform {
backend "s3" {
bucket = "my-terraform-state"
key = "production/terraform.tfstate"
region = "us-east-1"
dynamodb_table = "terraform-locks"
encrypt = true
}
}
```
## Multi-Environment Strategy
1. **Workspaces**: Simple, state separation only
2. **Directory structure**: Full isolation, can diff configs
3. **Terragrunt**: DRY config, repeatable structure
4. **Always**: Plan in CI, approve, then apply
5. **No manual applies** in production
---
> Source: [cosmicstack-labs/mercury-agent-skills](https://github.com/cosmicstack-labs/mercury-agent-skills) — distributed by [TomeVault](https://tomevault.io).
<!-- tomevault:4.0:skill_md:2026-05-22 -->
章节与文件索引
按说明文件中的顺序排列。
状态管理
模块最佳实践
多环境策略
文件/命令 -> terraform state · modules/compute/main.tf · production/terraform.tfstate · cosmicstack-labs/mercury-agent-skills · github.com/cosmicstack-labs/mercury-agent-skills
内容校验值 -> e6ae34083e24
当前原文的自动摘译,尚未人工审校。
状态管理
远程存储状态(S3、Terraform Cloud) 启用状态锁定 (DynamoDB) 切勿手动编辑状态(使用
terraform state命令) 将环境与工作区或目录隔离模块最佳实践
输入验证(类型约束、验证块) 所有有用值的输出 版本化模块(Git 标签、注册表) 文档(每个模块的自述文件) 使用 Terratest 进行测试
多环境策略
工作空间:简单,仅状态分离 目录结构:完全隔离,可以比较配置 Terragrunt:DRY 配置,可重复结构 始终:在 CI 中规划,批准,然后应用 生产中不适用手册