Skip to main content

attackmap-analyzer-terraform

Terraform / HCL infrastructure-as-code analyzer for AttackMap.

This analyzer is shaped differently from language analyzers — Terraform doesn't have routes in the application sense. Instead, it extracts:

  • Public ingress — security groups (ingress blocks only; open egress is ignored) and inbound firewall rules with 0.0.0.0/0 / ::/0, Lambda Function URLs with no auth, API Gateway methods with authorization = "NONE", S3 buckets with public ACLs (inline or aws_s3_bucket_acl), public bucket policies or disabled public-access blocks → entrypoint_hints
  • Asset inventory — S3 buckets, Azure storage accounts, GCS buckets, KMS keys, Cognito user pools → service_hints
  • Databases — aws_db_instance and aws_rds_cluster (engine-aware: postgres / mysql / oracle / sqlserver / mariadb), aws_dynamodb_table, aws_elasticache_*, aws_documentdb_*, Azure PostgreSQL/MySQL/CosmosDB, GCP Cloud SQL → database_hints
  • Secrets — aws_secretsmanager_secret, aws_ssm_parameter (SecureString), azurerm_key_vault, plus variable blocks marked sensitive = true or with secret-shaped names (*secret*, *token*, *password*, *key*), and secret-shaped string literals in .tfvars (kind="hardcoded") → secret_hints. A secret variable with a literal string default is kind="hardcoded" (the value is never echoed); a bare declaration keeps the default kind.
  • IAM blast radius — Allow statements with Action "*" (0.7), Resource "*" (0.5) or unconditioned Principal "*" (0.7) in aws_iam_*_policy, aws_iam_role trust/inline policies and data "aws_iam_policy_document" → auth_hints
  • Cognito — aws_cognito_user_pool → auth_hints
  • Modules — module "x" { source = ... } → service_hints keyed module:x
  • Misconfigurations → cloud_misconfigs (AttackMap's CloudMisconfig record, which core turns into findings with CWE/OWASP ids). Each record names the resource, carries its for_each/count and, for resources inside a local module, the module.<name> (file:line) blocks that call it:
    • iac_module_unpinned: git module sources without ?ref= or pinned to a branch (main, master, develop, ...), and registry modules without version. A tag (?ref=v1.2.3) or commit SHA is pinned.
    • public_network_access: associate_public_ip_address = true (aws_instance, launch configurations and templates), publicly_accessible = true RDS, and public_network_access_enabled = true on any azurerm_* resource.
    • public_cluster_endpoint: aws_eks_cluster whose API endpoint is public and open to 0.0.0.0/0 (both are the defaults, reported with lower confidence when left implicit).
    • plaintext_listener: aws_lb_listener on HTTP without a redirect default action, unless its load balancer is internal = true.
    • api_no_authorizer: API Gateway v1 methods with authorization = "NONE" and no API key, and v2 HTTP routes with authorization_type = "NONE" or none at all (the default). OPTIONS (CORS preflight) is skipped.
    • unencrypted_storage: storage_encrypted = false on aws_db_instance / aws_rds_cluster, and aws_db_instance without it (defaults to false; replicas, snapshot restores and kms_key_id are skipped).
    • public_data_access: public S3 ACLs and policies, disabled public-access blocks, OpenSearch / Elasticsearch access_policies open to Principal "*", GCS buckets granted to allUsers / allAuthenticatedUsers (IAM, ACLs, predefined_acl = "publicRead"), allow_nested_items_to_be_public = true and public azurerm_storage_containers.
    • public_invoker: Cloud Run / Cloud Functions invoker roles granted to allUsers / allAuthenticatedUsers, and Lambda function URLs with authorization_type = "NONE".
    • kubernetes provider: privileged containers, allow_privilege_escalation = true, host_network / host_pid / host_ipc, host_path volumes (high for the runtime socket, /, /etc, /proc, /var/lib/kubelet, ...), cluster-admin or system:authenticated bindings, roles with * / escalate / bind / impersonate / pods/exec / Secret read, and LoadBalancer / NodePort services without load_balancer_source_ranges.
    • Only literal values are judged: an attribute set from var.x or another reference is skipped.
  • API Gateway v2 routes — aws_apigatewayv2_route with route_key = "POST /charges" → actual Route entries
  • API Gateway v1 routes — aws_api_gateway_method on an aws_api_gateway_resource chain (parent_id / path_part joined back to root_resource_id, across files) → Route entries
  • Lambda function URLs — aws_lambda_function_url → an ANY / Route
  • Route auth (AttackMap#256) — every route carries auth / guards / guard_evidence. authorization / authorization_type = AWS_IAM, COGNITO_USER_POOLS, CUSTOM or JWT (or v1 api_key_required = true) → required. "NONE" written out → anonymous. Omitted or computed (var.x) → unknown.

All emissions populate AttackMap's Signal v2 fields (line numbers + evidence snippets) so downstream insights can cite infra/main.tf:NN.

Install

uv tool install attackmap --with attackmap-analyzer-terraform    # from PyPI
# or: pip install attackmap-analyzer-terraform    (installs attackmap too)
# or from source:
pip install git+https://github.com/mlaify/attackmap-analyzer-terraform.git

The analyzer is auto-discovered by AttackMap via the attackmap.analyzers entry-point group.

Usage with AttackMap

# Auto-discovered when installed:
attackmap analyze /path/to/terraform/repo

# Or invoke explicitly:
attackmap analyze /path/to/terraform/repo --module terraform

Detection

detect() returns true when any .tf, .tf.json, or .tfvars file is present in the tree, ignoring .terraform/ and AttackMap's shared skip list (.git/, node_modules/, vendor/, build/, dist/, out/, target/, ...). Skip directories are matched only inside the repo, so a checkout under e.g. /build/... is still scanned. Files are walked with attackmap.sdk.iter_repo_files, which does not follow symlinks out of the repo.

HCL block parsing

The analyzer parses HCL block bodies via brace-depth counting (with string-literal awareness so "{" inside strings" doesn't throw off the counter). Nested blocks like multiple ingress { } blocks inside a security group are handled correctly. Variable interpolation (${var.foo}, aws_iam_role.app.id) is not resolved — string literals and direct attribute values are what get extracted.

Coverage notes

  • AWS is the most thoroughly covered provider. Azure and GCP have basic coverage (NSG/firewall open ingress, Storage Account / GCS bucket as service hints, PostgreSQL/MySQL/CosmosDB/CloudSQL as databases) — extend per resource type as needed.
  • IAM wildcard detection matches JSON-shaped ("Action": "*", heredoc or .tf.json string) and HCL-shaped (Action = "*" in jsonencode, actions = ["*"] in aws_iam_policy_document) policies. A policy = data.aws_iam_policy_document.x.json reference isn't followed; the data source is reported under its own name.
  • .tf.json files get the same analysis as .tf. .tfvars files are checked for secret-shaped string literals (reported as kind="hardcoded" with the value redacted).
  • API Gateway v1 methods become routes when their resource_id resolves through literal aws_api_gateway_resource blocks to a root_resource_id. Methods on resources from modules or with interpolated path_parts only emit entrypoint hints. OpenAPI body-defined REST APIs aren't parsed.
  • Lambda Function URLs with authorization_type = "NONE" are flagged as open entrypoints. IAM-authorized URLs are emitted with the regular lambda_url: prefix.
  • Database publicly_accessible = true on aws_db_instance produces a separate rds_publicly_accessible: entrypoint hint in addition to the standard database hint.

License

MIT

Metadata

Release files for attackmap-analyzer-terraform 0.2.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for attackmap-analyzer-terraform 0.2.2
File Size Uploaded Provenance Actions
attackmap_analyzer_terraform-0.2.2.tar.gz 51.1 kB With provenance Details for attackmap_analyzer_terraform-0.2.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for attackmap-analyzer-terraform 0.2.2
File Interpreter ABI Platform Actions
attackmap_analyzer_terraform-0.2.2-py3-none-any.whl Python 3 none any Details for attackmap_analyzer_terraform-0.2.2-py3-none-any.whl

Total release size: 83.7 kB

Release files / attackmap_analyzer_terraform-0.2.2.tar.gz

Download URL attackmap_analyzer_terraform-0.2.2.tar.gz
Size 51.1 kB
Tags Source
SHA-256 checksum
How to use checksums
2f2c3ac3b3a6a5071ac3efb16c89646f74d4d46398357c71edd27037cac24c26
BLAKE2b-256 checksum
How to use checksums
bb9a8e934a131ff890a04305aeee669fb2e8177901fa2f9732f8c3a1626cabf6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 14, 2026.

Transparency log

Release files / attackmap_analyzer_terraform-0.2.2-py3-none-any.whl

Download URL attackmap_analyzer_terraform-0.2.2-py3-none-any.whl
Size 32.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d676459fd2aa1effb8085caf91b29477d27a8712cab231576128d1541cddb3b4
BLAKE2b-256 checksum
How to use checksums
fc67dd2c7d2bdd09607de0593955635ac26949294ef180cafbae86d20dd9e5e2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 14, 2026.

Transparency log

Security for attackmap-analyzer-terraform 0.2.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for attackmap_analyzer_terraform-0.2.2.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 14, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.2.2 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page