Event-driven automation tool that bridges Prometheus Alertmanager with Terraform — receives alert webhooks and executes Terraform modules in response.
make build # CGO_ENABLED=0 linux/amd64 binary → ./build/iterator
make test # go test -race with coverage
make lint # golangci-lint
make docker-build # builds container (reads VERSION file for tag)
make ci # mod → inst → gen → spell → test → build → docker-buildEntry point flow: main.go → cli.NewApp() (cobra) → bootstrap.BootstrapIterator() → server.NewServer().Start()
Config pipeline: HCL input (/etc/iterator/config.hcl default, -f flag) → parsed via hashicorp/hcl/v2 in config.LoadConfig() → rendered to YAML (config.RenderConfig()) → read back as config.Config with command definitions.
Request flow (firing alert):
- Alertmanager POST →
handleWebhook()unmarshalstemplate.Data - Per alert:
amFiring()matches commands by labels, checksCanRun()(fingerprint dedup) instrument()runs command, tracks metrics, persists fingerprint data (file or Consul KV)
Request flow (resolved alert):
amResolved()reads fingerprint data, runsterraform destroy(unless sawtooth scheduling)- Cleans up fingerprint storage, closes fingerprint channel
| Package | Purpose |
|---|---|
packages/cli |
Cobra CLI setup, release subcommand |
packages/bootstrap |
Init sequence: storage, terraform, config render, server start |
packages/server |
HTTP handlers, alert dispatch, metrics, fingerprint tracking |
packages/config |
HCL parsing (InitConfig), YAML read (Config), render |
packages/command |
Command execution, label matching, fingerprint generation, signal handling |
packages/chanmap |
Thread-safe map of fingerprint → channel (for signaling running commands) |
packages/countermap |
Thread-safe map of fingerprint → count (for max concurrent enforcement) |
packages/terraform |
Terraform/Terragrunt execution (apply/destroy) |
packages/consul |
Consul KV storage backend for fingerprint data |
packages/lifecycle |
Release/sawtooth scheduling lifecycle management |
packages/logger |
Structured logging with JSON/YAML output |
packages/stats |
Active alert status tracking |
packages/storage |
Data directory initialization |
POST /— Alertmanager webhook receiver (main entry point)POST /release— Trigger terraform destroy for a named alert (sawtooth release)GET /metrics— Prometheus metrics (iterator_process_duration_seconds,iterator_processes_current,iterator_errors_total,iterator_signalled_total,iterator_skipped_total)GET /_health— Health check
- Fingerprint dedup: Each alert+command produces a fingerprint.
countermaptracks active count per fingerprint;chanmapmaps fingerprint to quit channel.Command.Maxlimits concurrent runs per fingerprint. - Terraform scheduling modes:
defaultruns destroy on resolve;sawtoothskips auto-destroy (released manually via/releaseendpoint or CLI). - Terraform drivers: Supports both
terraform(-chdir=) andterragrunt(--terragrunt-working-dir). - Storage backends: File-based (default, writes JSON to
{data_dir}/process/alerts/) or Consul KV. - Alert env vars: Alert data passed to commands as
TF_VAR_ITERATOR_ALERT_*environment variables.
- Go 1.21.4, module
github.com/cloudputation/iterator - Logging via
packages/logger(wraps hclog):log.Info(),log.Error(),log.Fatal(),log.Debug() - Error handling: return errors up the stack;
log.Fatal()for unrecoverable; HTTP 500 for webhook errors - Tests live in
tests/go_tests/(not colocated with packages) - Config default port:
9595 - HCL config blocks:
server {}andtask {}withcondition "label-match" {}sub-blocks