# tfmcp v0.1.9 企画書: ローカルTerraform完全特化
## 設計思想
**ローカルTerraform開発体験の徹底強化**
- HCP/Cloud機能は一切含まない
- terraform CLIの全主要コマンドをMCPで操作可能に
- AIアシスタントとのローカル開発に最適化
---
## 新規ツール (10)
### 1. `analyze_plan` - Plan詳細分析
**目的**: `terraform plan -json`を解析し、構造化された分析結果を提供
```rust
pub struct AnalyzePlanInput {
pub include_risk: Option<bool>, // リスク評価 (デフォルト: true)
}
```
**出力**:
- 変更サマリー (add/change/destroy)
- リソース別変更詳細
- リスクスコア・警告・推奨事項
- 依存影響分析
---
### 2. `analyze_state` - State詳細分析
**目的**: `terraform state`を解析し、リソース状況を可視化
```rust
pub struct AnalyzeStateInput {
pub resource_type: Option<String>, // フィルタ
pub detect_drift: Option<bool>, // ドリフト検出
}
```
**出力**:
- リソース統計 (provider別、type別)
- ドリフト検出結果
- 健全性チェック
---
### 3. `terraform_workspace` - ワークスペース管理
**目的**: `terraform workspace`コマンドをMCPで操作
```rust
pub struct WorkspaceInput {
pub action: String, // list, show, new, select, delete
pub name: Option<String>, // ワークスペース名
}
```
---
### 4. `terraform_import` - Import支援
**目的**: 既存リソースのインポートを支援
```rust
pub struct ImportInput {
pub resource_type: String,
pub resource_id: String,
pub name: String,
pub execute: Option<bool>, // false=プレビュー, true=実行
}
```
---
### 5. `terraform_fmt` - コード整形
**目的**: `terraform fmt`をMCPで操作
```rust
pub struct FmtInput {
pub check: Option<bool>, // チェックのみ
pub diff: Option<bool>, // 差分表示
pub file: Option<String>, // 特定ファイル
}
```
---
### 6. `terraform_graph` - 依存グラフ出力
**目的**: `terraform graph`の出力を提供
```rust
pub struct GraphInput {
pub format: Option<String>, // dot, json
pub type_filter: Option<String>, // plan, apply
}
```
**出力**: DOT形式またはJSON形式の依存グラフ
---
### 7. `terraform_output` - Output値取得
**目的**: `terraform output`の値を取得
```rust
pub struct OutputInput {
pub name: Option<String>, // 特定のoutput名 (省略時は全て)
pub json: Option<bool>, // JSON形式
}
```
---
### 8. `terraform_taint` - リソースTaint/Untaint
**目的**: リソースのtaint/untaint操作
```rust
pub struct TaintInput {
pub action: String, // taint, untaint
pub address: String, // リソースアドレス
}
```
**注**: Terraform 1.5+では非推奨、`-replace`オプション推奨の警告を含める
---
### 9. `terraform_refresh` - State Refresh
**目的**: `terraform refresh`相当の操作
```rust
pub struct RefreshInput {
pub target: Option<String>, // 特定リソース
}
```
**実装**: `terraform apply -refresh-only -auto-approve`
---
### 10. `terraform_providers` - Provider情報
**目的**: 使用中のプロバイダー情報を取得
```rust
pub struct ProvidersInput {
pub lock: Option<bool>, // lock情報を含める
}
```
**実装**: `terraform providers` + `.terraform.lock.hcl`解析
---
## 既存ツール拡張 (3)
### `validate_terraform_detailed` 拡張
追加チェック:
- deprecated属性警告
- 命名規則チェック (snake_case推奨)
- ベストプラクティス違反
### `analyze_terraform` 拡張
追加分析:
- モジュールバージョン確認 (outdated検出)
- Backend設定分析
- Terraformバージョン互換性
### `get_security_status` 拡張
追加スキャン:
- Backend設定セキュリティ
- .gitignore確認 (tfstate, tfvars)
- Provider認証方法確認
---
## 最終ツール構成
### 既存 (21ツール)
| カテゴリ | ツール |
|---------|--------|
| Core | list_terraform_resources, get_terraform_plan, apply_terraform, destroy_terraform, init_terraform, validate_terraform, validate_terraform_detailed, get_terraform_state |
| Config | analyze_terraform, set_terraform_directory, get_security_status, analyze_module_health, get_resource_dependency_graph, suggest_module_refactoring |
| Registry | search_terraform_providers, get_provider_info, get_provider_docs, search_terraform_modules, get_module_details, get_latest_module_version, get_latest_provider_version |
### 新規 (10ツール)
| ツール | 説明 | アノテーション |
|--------|------|---------------|
| `analyze_plan` | Plan詳細分析・リスク評価 | readOnly |
| `analyze_state` | State分析・ドリフト検出 | readOnly |
| `terraform_workspace` | ワークスペース管理 | idempotent |
| `terraform_import` | Import支援 | destructive |
| `terraform_fmt` | コード整形 | idempotent |
| `terraform_graph` | 依存グラフ出力 | readOnly |
| `terraform_output` | Output値取得 | readOnly |
| `terraform_taint` | Taint/Untaint | destructive |
| `terraform_refresh` | State Refresh | destructive |
| `terraform_providers` | Provider情報 | readOnly |
### 合計: 31ツール
---
## アーキテクチャ
```
src/terraform/
├── service.rs # 既存 (拡張)
├── analyzer.rs # 既存 (拡張)
├── plan_analyzer.rs # 新規: Plan JSON解析
├── state_analyzer.rs # 新規: State解析
├── workspace.rs # 新規: Workspace操作
├── import_helper.rs # 新規: Import支援
├── fmt.rs # 新規: Fmt操作
├── graph.rs # 新規: Graph出力
├── output.rs # 新規: Output取得
├── taint.rs # 新規: Taint/Untaint
├── refresh.rs # 新規: Refresh操作
└── providers.rs # 新規: Provider情報
```
---
## README.md 更新内容
```markdown
## 🎉 Latest Release
The latest version of tfmcp (v0.1.9) is now available on Crates.io!
### 🆕 What's New in v0.1.9
- **📊 Plan Analysis**: Structured plan analysis with risk scoring and recommendations
- **🔍 State Analysis**: Deep state inspection with drift detection
- **📁 Workspace Management**: Full terraform workspace support
- **📥 Import Helper**: Guided resource import with config generation
- **✨ Code Formatting**: terraform fmt integration
- **🔗 Dependency Graph**: terraform graph visualization
- **📤 Output Management**: terraform output access
- **🏷️ Taint/Untaint**: Resource taint management
- **🔄 State Refresh**: Explicit state refresh
- **📦 Provider Info**: Detailed provider information
## MCP Tools
### Terraform Operations (31 tools)
#### Core Operations
| Tool | Description |
|------|-------------|
| `init_terraform` | Initialize Terraform project |
| `get_terraform_plan` | Execute terraform plan |
| `analyze_plan` | **NEW** Analyze plan with risk scoring |
| `apply_terraform` | Apply configuration |
| `destroy_terraform` | Destroy resources |
| `validate_terraform` | Validate configuration |
| `validate_terraform_detailed` | Detailed validation with guidelines |
| `get_terraform_state` | Get current state |
| `analyze_state` | **NEW** Analyze state with drift detection |
#### Workspace & State
| Tool | Description |
|------|-------------|
| `terraform_workspace` | **NEW** Manage workspaces |
| `terraform_import` | **NEW** Import existing resources |
| `terraform_taint` | **NEW** Taint/untaint resources |
| `terraform_refresh` | **NEW** Refresh state |
#### Code & Output
| Tool | Description |
|------|-------------|
| `terraform_fmt` | **NEW** Format code |
| `terraform_graph` | **NEW** Generate dependency graph |
| `terraform_output` | **NEW** Get output values |
| `terraform_providers` | **NEW** Get provider info |
#### Analysis & Security
| Tool | Description |
|------|-------------|
| `analyze_terraform` | Analyze configuration |
| `analyze_module_health` | Module health metrics |
| `get_resource_dependency_graph` | Resource dependencies |
| `suggest_module_refactoring` | Refactoring suggestions |
| `get_security_status` | Security scan with secret detection |
#### Registry (unchanged)
| Tool | Description |
|------|-------------|
| `search_terraform_providers` | Search providers |
| `get_provider_info` | Provider details |
| `get_provider_docs` | Provider documentation |
| `search_terraform_modules` | Search modules |
| `get_module_details` | Module details |
| `get_latest_module_version` | Latest module version |
| `get_latest_provider_version` | Latest provider version |
```
---
## 見積もり
| 項目 | 数値 |
|------|------|
| 新規ツール | 10 |
| 既存拡張 | 3 |
| 合計ツール | 31 |
| 新規ファイル | 10 |
| 追加行数 | ~2,000行 |
| テスト追加 | ~25テスト |
---
## 実装優先順
1. **Plan/State分析** - analyze_plan, analyze_state
2. **Workspace管理** - terraform_workspace
3. **Import/Fmt** - terraform_import, terraform_fmt
4. **Graph/Output** - terraform_graph, terraform_output
5. **Taint/Refresh** - terraform_taint, terraform_refresh
6. **Provider情報** - terraform_providers
7. **既存拡張** - validate/analyze/security拡張
8. **README更新** - ドキュメント整備
---
## 除外した機能
| 機能 | 理由 |
|------|------|
| HCPワークスペース | クラウド依存 |
| Sentinelポリシー | HCP専用 |
| Private Registry | HCP専用 |
| Run管理 | HCP専用 |
| 変数セット | HCP専用 |