Agent Skills
› cosmicstack-labs/mercury-agent-skills
› terraform-iac
terraform-iac
GitHub提供Terraform基础设施即代码管理指南,涵盖状态管理、模块化设计、远程后端配置及多环境策略。指导使用S3/DynamoDB锁定状态,规范模块接口与最佳实践,并推荐目录隔离或Terragrunt等方案实现生产环境的安全自动化部署。
Trigger Scenarios
需要管理Terraform状态
询问IaC模块设计规范
配置远程后端如S3
规划多环境部署策略
Install
npx skills add cosmicstack-labs/mercury-agent-skills --skill terraform-iac -g -y
SKILL.md
Frontmatter
{
"name": "terraform-iac",
"metadata": {
"tags": [
"terraform",
"iac",
"infrastructure",
"cloud",
"devops"
],
"author": "cosmicstack-labs",
"version": "1.0.0",
"category": "devops"
},
"description": "State management, modules, workspaces, remote backends, and multi-environment strategies"
}
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 statecommands) - 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
# 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
terraform {
backend "s3" {
bucket = "my-terraform-state"
key = "production/terraform.tfstate"
region = "us-east-1"
dynamodb_table = "terraform-locks"
encrypt = true
}
}
Multi-Environment Strategy
- Workspaces: Simple, state separation only
- Directory structure: Full isolation, can diff configs
- Terragrunt: DRY config, repeatable structure
- Always: Plan in CI, approve, then apply
- No manual applies in production
Version History
- 38e2523 Current 2026-07-05 19:39


