Project Structure
- `main.go` — analyze command: plan parsing, scoring, AI narrative, formatting, `--fail-on` gate, CI posting, Slack notifications
cmd/terraspin/ CLI entry points (main, serve, diff)
internal/
ai/ LLM providers (Claude, OpenAI, Ollama) + preprocessing
analyzer/ Risk scorer + blast radius dependency graph
config/ .terraspin.yml loading + rule evaluation
diff/ Environment diff comparison
formatter/ Output formatting (text, JSON, markdown)
integrations/ GitHub PR comments, GitLab MR notes, Slack webhooks, MCP server
parser/ Terraform plan JSON → PlanAST
testdata/ Terraform plan fixtures for testing
Entry points (cmd/terraspin/)
main.go— analyze command: plan parsing, scoring, AI narrative, formatting,--fail-ongate, CI posting, Slack notificationsserve.go— MCP server (stdio and SSE transports)diff.go— two-plan drift comparison with AI narrative
Internal packages
parser
types.go—PlanAST,ResourceChange,ChangeAction(create/update/delete/replace/no-op/read)parse.go— JSON unmarshal + structural validation
ai
claude.go— Anthropic Claude API clientproviders.go— OpenAI + Ollama clients,QueryLLM()router,Narrativetype, prompt builder, rule-based fallbackpreprocess.go— sensitive value redaction
analyzer
risk.go—ScorePlan(): base scores × resource multipliers, tier mapping,ApplyCustomRules()for escalation from config rulesblast.go—ParseDependencyRefs(),AnalyzeBlastRadius(): dependency graph and cascading impact
config
config.go—Configstruct,Load(),DefaultConfig(), validationrules.go—EvaluateRules(), glob + attribute matching
formatter
formatter.go—FormatText(),FormatJSON(),FormatMarkdown(): all three output formats
integrations
github.go— GitHub PR comment client (post + update with tag)gitlab.go— GitLab MR note clientslack.go— Slack webhook notificationshttp.go— Shared HTTP helpers (retry, auth headers)mcp/server.go— MCP tool registration and server setup
diff
types.go—DiffResult,ResourceDiff,DiffStatusdiff.go—Compare(): two-plan side-by-side analysis
Test fixtures (testdata/)
plan.json— typical plan with creates, updates, deletesplan_empty.json— no changesplan_with_modules.json— module-based resourcesplan_with_sensitive.json— sensitive value redaction scenarios
Config files
| File | Purpose |
|---|---|
go.mod | Go module (1.24). Deps: mcp-go, yaml.v3 |
shell.nix | Nix dev shell with full tooling |
.env.example | Environment variable template |
.gitignore | Go build artifacts, .env |