# tenable/terrascan architecture

> Architecture diagram of the GitHub repository tenable/terrascan, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-02). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/tenable/terrascan
- Repository: https://github.com/tenable/terrascan

## Overview

Terrascan is an IaC security and compliance scanner, usable from the CLI or as an API server. Its main workflow accepts IaC, loads and evaluates policies, optionally enriches results with image vulnerabilities, and presents findings in supported output formats. It also supports policy initialization, admission control, and webhook notifications. The graph reflects the sampled CLI, runtime, policy, and webhook code plus documented provider and format coverage; several server routes and provider implementations were not sampled, so those links are omitted or marked unverified.

Main entry points: [`pkg/runtime/executor.go`](https://github.com/tenable/terrascan/blob/master/pkg/runtime/executor.go) (Scan orchestration), [`pkg/cli/run.go`](https://github.com/tenable/terrascan/blob/master/pkg/cli/run.go) (CLI commands), [`pkg/k8s/admission-webhook/validating-webhook.go`](https://github.com/tenable/terrascan/blob/master/pkg/k8s/admission-webhook/validating-webhook.go) (Admission scan), [`pkg/iac-providers`](https://github.com/tenable/terrascan/tree/master/pkg/iac-providers) (IaC provider parsers)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Entry points"]
  node_main["Executable<br/>[main.go]"]
  node_cli["CLI commands<br/>[run.go]"]
  node_servercmd["Server command<br/>[server.go]"]
  node_http["HTTP API"]
  node_admission["Admission scan"]
  node_initialize["Policy initialization<br/>[run.go]"]
end

subgraph group_inputs["IaC inputs"]
  node_iac["IaC provider parsers"]
  node_tfload["Terraform loading<br/>[load-dir.go]"]
  node_mapper["Cloud resource mapping"]
  node_downloader["Remote modules<br/>[module-download.go]"]
end

subgraph group_analysis["Scan analysis"]
  node_runtime["Scan orchestration<br/>[executor.go]"]
  node_policy["Policy evaluation<br/>[engine.go]"]
  node_filters["Scan filters<br/>[filter-specs.go]"]
end

subgraph group_results["Results and integrations"]
  node_results[("Finding store<br/>[store.go]")]
  node_vuln["Image vulnerabilities"]
  node_writer["Result formats"]
  node_notify["Webhook notifications<br/>[webhook.go]"]
  node_webhooklog[("Admission scan log")]
end

node_user(("CLI user"))
node_kube(("Kubernetes API"))

node_user -->|"runs"| node_main
node_main -->|"starts"| node_cli
node_cli -->|"orchestrates scan"| node_runtime
node_cli -->|"formats results"| node_writer
node_cli -.->|"runs server"| node_servercmd
node_servercmd -->|"starts API"| node_http
node_http -->|"dispatches admission"| node_admission
node_kube -->|"sends review"| node_http
node_admission -->|"executes scan"| node_runtime
node_admission -->|"logs scan"| node_webhooklog
node_cli -.->|"initializes policies"| node_initialize
node_runtime -->|"creates providers"| node_iac
node_runtime -->|"evaluates policies"| node_policy
node_runtime -->|"applies filters"| node_filters
node_runtime -->|"stores findings"| node_results
node_runtime -->|"fetches vulnerabilities"| node_vuln
node_runtime -->|"sends notifications"| node_notify
node_tfload -->|"downloads modules"| node_downloader
node_iac -.->|"maps resources"| node_mapper
node_iac -.->|"loads Terraform"| node_tfload

click node_main "https://github.com/tenable/terrascan/blob/master/cmd/terrascan/main.go"
click node_cli "https://github.com/tenable/terrascan/blob/master/pkg/cli/run.go"
click node_servercmd "https://github.com/tenable/terrascan/blob/master/pkg/cli/server.go"
click node_http "https://github.com/tenable/terrascan/tree/master/pkg/http-server"
click node_admission "https://github.com/tenable/terrascan/blob/master/pkg/k8s/admission-webhook/validating-webhook.go"
click node_initialize "https://github.com/tenable/terrascan/blob/master/pkg/initialize/run.go"
click node_iac "https://github.com/tenable/terrascan/tree/master/pkg/iac-providers"
click node_tfload "https://github.com/tenable/terrascan/blob/master/pkg/iac-providers/terraform/commons/load-dir.go"
click node_mapper "https://github.com/tenable/terrascan/tree/master/pkg/mapper/iac-providers"
click node_runtime "https://github.com/tenable/terrascan/blob/master/pkg/runtime/executor.go"
click node_policy "https://github.com/tenable/terrascan/blob/master/pkg/policy/opa/engine.go"
click node_filters "https://github.com/tenable/terrascan/blob/master/pkg/filters/filter-specs.go"
click node_results "https://github.com/tenable/terrascan/blob/master/pkg/results/store.go"
click node_vuln "https://github.com/tenable/terrascan/tree/master/pkg/vulnerability"
click node_writer "https://github.com/tenable/terrascan/tree/master/pkg/writer"
click node_notify "https://github.com/tenable/terrascan/blob/master/pkg/notifications/webhook/webhook.go"
click node_webhooklog "https://github.com/tenable/terrascan/blob/master/pkg/k8s/dblogs/webhook-scan-logger.go"
click node_downloader "https://github.com/tenable/terrascan/blob/master/pkg/downloader/module-download.go"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_main,node_cli,node_servercmd,node_http,node_admission,node_initialize,node_user toneBlue
class node_iac,node_tfload,node_mapper,node_downloader toneAmber
class node_runtime,node_policy,node_filters,node_kube toneMint
class node_results,node_vuln,node_writer,node_notify,node_webhooklog toneRose
```

## Components

### Entry points

- [Executable](https://github.com/tenable/terrascan/blob/master/cmd/terrascan/main.go): `cmd/terrascan/main.go`
- [CLI commands](https://github.com/tenable/terrascan/blob/master/pkg/cli/run.go): `pkg/cli/run.go`
- [Server command](https://github.com/tenable/terrascan/blob/master/pkg/cli/server.go): `pkg/cli/server.go`
- [HTTP API](https://github.com/tenable/terrascan/tree/master/pkg/http-server): `pkg/http-server`
- [Admission scan](https://github.com/tenable/terrascan/blob/master/pkg/k8s/admission-webhook/validating-webhook.go): `pkg/k8s/admission-webhook/validating-webhook.go`
- [Policy initialization](https://github.com/tenable/terrascan/blob/master/pkg/initialize/run.go): `pkg/initialize/run.go`

### IaC inputs

- [IaC provider parsers](https://github.com/tenable/terrascan/tree/master/pkg/iac-providers): `pkg/iac-providers`
- [Terraform loading](https://github.com/tenable/terrascan/blob/master/pkg/iac-providers/terraform/commons/load-dir.go): `pkg/iac-providers/terraform/commons/load-dir.go`
- [Cloud resource mapping](https://github.com/tenable/terrascan/tree/master/pkg/mapper/iac-providers): `pkg/mapper/iac-providers`
- [Remote modules](https://github.com/tenable/terrascan/blob/master/pkg/downloader/module-download.go): `pkg/downloader/module-download.go`

### Scan analysis

- [Scan orchestration](https://github.com/tenable/terrascan/blob/master/pkg/runtime/executor.go): `pkg/runtime/executor.go`
- [Policy evaluation](https://github.com/tenable/terrascan/blob/master/pkg/policy/opa/engine.go): `pkg/policy/opa/engine.go`
- [Scan filters](https://github.com/tenable/terrascan/blob/master/pkg/filters/filter-specs.go): `pkg/filters/filter-specs.go`

### Results and integrations

- [Finding store](https://github.com/tenable/terrascan/blob/master/pkg/results/store.go): `pkg/results/store.go`
- [Image vulnerabilities](https://github.com/tenable/terrascan/tree/master/pkg/vulnerability): `pkg/vulnerability`
- [Result formats](https://github.com/tenable/terrascan/tree/master/pkg/writer): `pkg/writer`
- [Webhook notifications](https://github.com/tenable/terrascan/blob/master/pkg/notifications/webhook/webhook.go): `pkg/notifications/webhook/webhook.go`
- [Admission scan log](https://github.com/tenable/terrascan/blob/master/pkg/k8s/dblogs/webhook-scan-logger.go): `pkg/k8s/dblogs/webhook-scan-logger.go`

### Other components

- **CLI user**
- **Kubernetes API**

## Connections

- CLI user → Executable: runs (evidence: `cmd/terrascan/main.go`)
- Executable → CLI commands: starts (evidence: `cmd/terrascan/main.go`)
- CLI commands → Scan orchestration: orchestrates scan (evidence: `pkg/cli/run.go`)
- CLI commands → Result formats: formats results (evidence: `pkg/cli/run.go`)
- CLI commands → Server command: runs server
- Server command → HTTP API: starts API (evidence: `pkg/cli/server.go`)
- HTTP API → Admission scan: dispatches admission (evidence: `pkg/http-server/webhook-scan.go`)
- Kubernetes API → HTTP API: sends review (evidence: `pkg/http-server/webhook-scan.go`)
- Admission scan → Scan orchestration: executes scan (evidence: `pkg/k8s/admission-webhook/validating-webhook.go`)
- Admission scan → Admission scan log: logs scan (evidence: `pkg/k8s/admission-webhook/validating-webhook.go`)
- CLI commands → Policy initialization: initializes policies
- Scan orchestration → IaC provider parsers: creates providers (evidence: `pkg/runtime/executor.go`)
- Scan orchestration → Policy evaluation: evaluates policies (evidence: `pkg/runtime/executor.go`)
- Scan orchestration → Scan filters: applies filters (evidence: `pkg/runtime/executor.go`)
- Scan orchestration → Finding store: stores findings (evidence: `pkg/runtime/executor.go`)
- Scan orchestration → Image vulnerabilities: fetches vulnerabilities (evidence: `pkg/runtime/executor.go`)
- Scan orchestration → Webhook notifications: sends notifications (evidence: `pkg/runtime/executor.go`)
- Terraform loading → Remote modules: downloads modules (evidence: `pkg/iac-providers/terraform/commons/load-dir.go`)
- IaC provider parsers → Cloud resource mapping: maps resources
- IaC provider parsers → Terraform loading: loads Terraform (evidence: `pkg/iac-providers/terraform/commons/load-dir.go`)
