Hamburger Cross Icon
Terraform Collector - Lunar Collector

Terraform Collector

Collector Beta SecurityOrchestration

Parse Terraform HCL files to extract configuration data. Writes file validity and full parsed HCL JSON for downstream policy analysis of providers, modules, backends, resources, and infrastructure security posture.

Add terraform to your lunar-config.yml:
uses: github://earthly/lunar-lib/collectors/terraform@v1.0.5

What This Integration Collects

This integration includes 2 collectors that gather metadata from your systems.

Collector code

terraform

Parses all Terraform (.tf) files in the repository using hcl2json and collects:

  • File validity and parse errors (.iac.files[])
  • Normalized modules with resources and analysis (.iac.modules[])
  • Full parsed HCL JSON for terraform-specific policy (.iac.native.terraform.files[])
  • Source tool metadata (.iac.source)
terraform iac infrastructure hcl aws providers modules backend
Book a demo
Collector ci-before-command

cicd

Records every terraform command executed in CI pipelines along with the Terraform CLI version. Writes command strings and version info to .iac.native.terraform.cicd for audit trails and build reproducibility.

terraform ci terraform version ci commands iac tracking deployment tracking
Book a demo

How Collectors Fit into Lunar

Lunar watches your code and CI/CD systems to collect SDLC data from config files, test results, IaC, deployment configurations, security scans, and more.

Collectors are the automatic data-gathering layer. They extract structured metadata from your repositories and pipelines, feeding it into Lunar's centralized database where guardrails evaluate it to enforce your engineering standards.

Learn How Lunar Works
1
Collectors Gather Data This Integration
Triggered by code changes or CI pipelines, collectors extract metadata from config files, tool outputs, test results, and scans
2
{ } Centralized as JSON
All data merged into each component's unified metadata document
3
Guardrails Enforce Standards
Real-time feedback in PRs and AI workflows

Example Collected Data

This collector writes structured metadata to the Component JSON. Here's an example of the data it produces:

{ } component.json Component JSON
{
  "iac": {
    "source": {"tool": "hcl2json", "version": "0.6.8"},
    "files": [
      {"path": "deploy/terraform/main.tf", "valid": true},
      {"path": "deploy/terraform/variables.tf", "valid": true}
    ],
    "modules": [
      {
        "path": "deploy/terraform",
        "resources": [
          {"type": "aws_db_instance", "name": "main", "category": "datastore", "has_prevent_destroy": true},
          {"type": "aws_s3_bucket", "name": "logs", "category": "datastore", "has_prevent_destroy": false},
          {"type": "aws_lb", "name": "api", "category": "network", "has_prevent_destroy": false, "internet_facing": true},
          {"type": "aws_instance", "name": "web", "category": "compute", "has_prevent_destroy": false},
          {"type": "aws_wafv2_web_acl", "name": "main", "category": "security"},
          {"type": "aws_wafv2_web_acl_association", "name": "api", "category": "security"}
        ],
        "analysis": {
          "internet_accessible": true,
          "has_waf": true
        }
      }
    ],
    "native": {
      "terraform": {
        "files": [
          {
            "path": "deploy/terraform/main.tf",
            "hcl": {
              "terraform": [{"required_providers": [{"aws": {"source": "hashicorp/aws", "version": "~> 5.0"}}]}],
              "resource": {"aws_db_instance": {"main": [{"engine": "postgres"}]}}
            }
          }
        ],
        "cicd": {
          "cmds": [
            {"cmd": "terraform init", "version": "1.9.8"},
            {"cmd": "terraform plan -out=tfplan", "version": "1.9.8"},
            {"cmd": "terraform apply -auto-approve tfplan", "version": "1.9.8"}
          ],
          "source": {"tool": "terraform", "integration": "ci"}
        }
      }
    }
  }
}

Documentation

View on GitHub

Terraform Collector

Parses Terraform HCL files and collects IaC configuration data for policy analysis.

Overview

This collector finds all .tf files in a repository and parses them using hcl2json. It writes file validity status and the full parsed HCL JSON, enabling downstream policies to analyze providers, modules, backend configuration, resource inventory, and infrastructure security posture.

Collected Data

This collector writes to the following Component JSON paths:

Path Type Description
.iac.source object Tool metadata (tool, version)
.iac.files[] array File validity: {path, valid, error?}
.iac.modules[] array Normalized modules: {path, resources[], analysis}
.iac.native.terraform.files[] array Full parsed HCL per file: {path, hcl}
.iac.native.terraform.cicd object CI command tracking: {cmds[], source}

Collectors

This integration provides the following collectors (use include to select a subset):

Collector Description
terraform Parses .tf files, writes validity and full HCL JSON
cicd Records every terraform command run in CI with the CLI version

Installation

Add to your lunar-config.yml:

collectors:
  - uses: github://earthly/lunar-lib/collectors/terraform@main
    on: ["domain:your-domain"]  # Or use tags like [infra, terraform]

Open Source

This collector is open source and available on GitHub. Contribute improvements, report issues, or fork it for your own use.

View Repository

Common Use Cases

Explore guardrails that use data from Terraform Collector.

+
Valid + Terraform Collector Validates that all IaC configuration files are syntactically correct. Invalid...
+
Waf Protection + Terraform Collector Requires WAF protection for internet-facing services. Checks each IaC module for...
+
Datastore Destroy Protection + Terraform Collector Ensures stateful resources (databases, storage buckets, caches) have lifecycle {...
+
Resource Destroy Protection + Terraform Collector Ensures stateless infrastructure resources (EC2 instances, load...
+
Provider Versions Pinned + Terraform Collector Requires Terraform providers to specify version constraints in...
+
Module Versions Pinned + Terraform Collector Requires Terraform modules to use pinned versions or commit SHAs. Unpinned...
+
Remote Backend + Terraform Collector Requires Terraform to use a remote backend for state management. Local state...
+
Min Provider Versions + Terraform Collector Enforces minimum version requirements for Terraform providers. Ensures providers...
+
Aws Alb Waf Enabled + Terraform Collector Requires every internet-facing Application Load Balancer to have an AWS WAF web...
+
Aws Cloudtrail Multi Region + Terraform Collector Requires a multi-region CloudTrail trail that delivers events to...
+
Aws Security Group No Public Postgres + Terraform Collector Requires that no security group allows unrestricted ingress (0.0.0.0/0 or ::/0)...
+
Aws Security Group No Public Ssh + Terraform Collector Requires that no security group allows unrestricted ingress (0.0.0.0/0 or ::/0)...
+
Aws Eks Control Plane Logging + Terraform Collector Requires EKS clusters to enable control-plane logging to CloudWatch for...
+
Aws Elb Access Logging + Terraform Collector Requires Elastic Load Balancers to have access logging enabled so...
+
Aws Ebs Snapshot Encryption + Terraform Collector Requires EBS snapshots to be encrypted at rest. Snapshots inherit data...
+
Aws Ebs Volume Encryption + Terraform Collector Requires EBS volumes (standalone and instance block devices) to be encrypted at...
+
Aws Elb Https Only + Terraform Collector Requires load balancers to enforce encrypted transport. HTTP listeners...
+
Aws Guardduty Enabled + Terraform Collector Requires Amazon GuardDuty to be enabled so the account has continuous threat...
+
Aws Rds Cloudwatch Logging + Terraform Collector Requires RDS instances and clusters to export database logs to CloudWatch, so...
+
Aws S3 Block Public Access + Terraform Collector Requires every S3 bucket to have public access fully blocked through a public...
+
Aws S3 Access Logging + Terraform Collector Requires S3 buckets to have server access logging enabled, recording...
+
Aws Vpc Flow Logs + Terraform Collector Requires every VPC to have flow logs enabled, capturing accepted and rejected...
+
Aws Security Group No Public Admin Ports + Terraform Collector Requires that no security group allows unrestricted ingress (0.0.0.0/0 or ::/0)...
+
Aws Rds Encryption At Rest + Terraform Collector Requires RDS instances and clusters to set storage_encrypted = true so database...
+
Aws Rds Not Publicly Accessible + Terraform Collector Requires RDS instances to keep publicly_accessible = false so databases are not...
+
Aws Rds Snapshot Encryption + Terraform Collector Requires RDS snapshots to be encrypted at rest. Snapshots inherit encryption...
+
Aws S3 Encryption At Rest + Terraform Collector Requires every S3 bucket to declare a server-side encryption configuration,...
+
Aws S3 No Static Website + Terraform Collector Forbids S3 buckets from hosting a public static website, which would...
+
Aws S3 No Public Acl + Terraform Collector Forbids S3 buckets from granting public access through canned...
+
Aws Iam Password Min Length + Terraform Collector Requires an IAM account password policy that enforces a minimum password length...
+
Aws Iam No Direct User Policies + Terraform Collector Forbids attaching IAM policies (inline or managed) directly to users. Policies...
+
Aws Acm Cert Dns Validation + Terraform Collector Requires ACM certificates to use DNS validation so issuance and renewal are...
+
Aws Eks Private Endpoint + Terraform Collector Requires EKS clusters to enable private API-server endpoint access, so...
+
Aws Dynamodb Encryption + Terraform Collector Requires DynamoDB tables to declare server-side encryption explicitly. DynamoDB...
+
Aws Lambda Not Public + Terraform Collector Forbids Lambda functions from being publicly invokable through a principal "*"...
+
Aws Cloudtrail Log File Validation + Terraform Collector Requires CloudTrail trails to enable log-file integrity validation so tampering...
+
Aws Cloudtrail Kms Encryption + Terraform Collector Requires CloudTrail trails to encrypt delivered logs with a KMS customer-managed...

Ready to Automate Your Standards?

See how Lunar can turn your AGENTS.md, engineering wiki, compliance docs, or postmortem action items into automated guardrails with our 200+ built-in guardrails.

Works with any process
check AI agent rules & prompt files
check Post-mortem action items
check Security & compliance policies
check Testing & quality requirements
Automate Now
Paste your AGENTS.md or manual process doc and get guardrails in minutes
Book a Demo