terraform

Seeded Terraform defects — committed secrets, public exposure, a rename with no moved block.

14 deliberate defects, each with a marker naming the rule in standards/ it breaks. It measures recall: how many of the defects the reviewer flags at their severity or higher. The pass condition is that all 6 BLOCKER defects are flagged.

Because each marker names a rule, the scorer also grades attribution. A reviewer that finds the bug but cites the wrong rule counts as caught, and separately as misattributed.

Running it

Nothing here is ever merged. Open a throwaway pull request on a pilot repository already onboarded for this stack, adding this directory and seeded/clean together, wait for the automated review to finish, then score it.

seed-canary.yml does exactly this on a schedule and closes the pull request afterwards, including when the run fails.

terminal
$ GH_TOKEN=... npx redlinegate metrics score-seeds --repo <org>/<repo> --pr <n>

Flags and output are on redline metrics.

The 14 defects

SeedSeverityRule it violatesDefect
1BLOCKERterraform/unpinned-sourceprovider unpinned — floats to whatever is latest at apply time
2BLOCKERterraform/secrets-in-configsecret committed in a .tf file
3BLOCKERterraform/authoritative-iam-resourcedetaches the policy from every other role
3BLOCKERterraform/public-exposuredatabase exposed to the public internet
6BLOCKERterraform/public-exposure0.0.0.0/0 ingress on a database port
7BLOCKERterraform/overly-broad-iamfully unscoped IAM policy
1HIGHterraform/empty-list-equality== [] is always false
2HIGHterraform/ignore-changes-alllater changes are never applied
4HIGHterraform/depends-on-instead-of-referencemakes every plan show replacements
4HIGHterraform/missing-backup-retentionno backup retention on a new stateful resource
5HIGHterraform/map-duplicate-keysthe last value silently wins
5HIGHterraform/missing-encryptionencryption at rest not enabled on a new data store
8HIGHterraform/count-vs-for-eachcount on an identity-bearing resource — index shift recreates siblings
9SUGGESTIONterraform/variable-metadatavariable missing description and type

Scoring

The score reports BLOCKER recall, false positives, and rule attribution. The canary appends it to data/seed-scores.jsonl and fails the run if BLOCKER recall drops below 1.0 or the clean corpus attracts a false positive. Of the 14 defects here, 6 BLOCKER, 7 HIGH and 1 SUGGESTION — only the BLOCKER count is a pass condition.

Adding a defect

Add the code and one marker line above it. The format, and what scripts/validate.mjs checks, are on Seeded corpus.

The full file

seeded/terraform/anti_slop.tf · 44 lines · 1.2 KB
# DO NOT MERGE — Redline validation seed (anti-slop rules).

variable "subnet_ids" {
  type        = list(string)
  description = "Subnets"
}

resource "aws_db_subnet_group" "this" {
  # SEED 1 [HIGH] (terraform/empty-list-equality) == [] is always false
  count      = var.subnet_ids == [] ? 0 : 1
  subnet_ids = var.subnet_ids
}

resource "aws_instance" "app" {
  ami           = "ami-0abcdef1234567890"
  instance_type = "m6i.large"
  lifecycle {
    # SEED 2 [HIGH] (terraform/ignore-changes-all) later changes are never applied
    ignore_changes = all
  }
}

# SEED 3 [BLOCKER] (terraform/authoritative-iam-resource) detaches the policy from every other role
resource "aws_iam_policy_attachment" "read_only" {
  name       = "read-only"
  roles      = ["app"]
  policy_arn = "arn:aws:iam::aws:policy/ReadOnlyAccess"
}

module "app" {
  source     = "./modules/app"
  subnet_ids = module.network.private_subnet_ids
  # SEED 4 [HIGH] (terraform/depends-on-instead-of-reference) makes every plan show replacements
  depends_on = [module.network]
}

locals {
  tags = {
    Environment = "prod"
    # SEED 5 [HIGH] (terraform/map-duplicate-keys) the last value silently wins
    Environment = "dev"
  }
}
seeded/terraform/seeded_violations.tf · 66 lines · 2.0 KB
# DO NOT MERGE — Redline validation seed.
# Every `SEED n [SEVERITY] (rule-id)` marker must be flagged at that severity or higher,
# citing that rule id. Score with scripts/score-seeds.mjs.

# SEED 1 [BLOCKER] (terraform/unpinned-source) provider unpinned — floats to whatever is latest at apply time
provider "aws" {
  region = "eu-west-1"
}

# SEED 2 [BLOCKER] (terraform/secrets-in-config) secret committed in a .tf file
variable "db_password" {
  type    = string
  default = "Pr0d-Sup3r-S3cret-2026!"
}

resource "aws_db_instance" "billing" {
  identifier = "billing-prod"
  engine     = "postgres"
  password   = var.db_password

  # SEED 3 [BLOCKER] (terraform/public-exposure) database exposed to the public internet
  publicly_accessible = true

  # SEED 4 [HIGH] (terraform/missing-backup-retention) no backup retention on a new stateful resource
  backup_retention_period = 0

  # SEED 5 [HIGH] (terraform/missing-encryption) encryption at rest not enabled on a new data store
  storage_encrypted = false
}

resource "aws_security_group_rule" "wide_open" {
  type        = "ingress"
  from_port   = 5432
  to_port     = 5432
  protocol    = "tcp"
  # SEED 6 [BLOCKER] (terraform/public-exposure) 0.0.0.0/0 ingress on a database port
  cidr_blocks = ["0.0.0.0/0"]
  security_group_id = "sg-0123456789abcdef0"
}

resource "aws_iam_role_policy" "billing" {
  name = "billing"
  role = "billing-role"

  # SEED 7 [BLOCKER] (terraform/overly-broad-iam) fully unscoped IAM policy
  policy = jsonencode({
    Version = "2012-10-17"
    Statement = [{
      Effect   = "Allow"
      Action   = "*"
      Resource = "*"
    }]
  })
}

# SEED 8 [HIGH] (terraform/count-vs-for-each) count on an identity-bearing resource — index shift recreates siblings
resource "aws_s3_bucket" "reports" {
  count  = length(var.markets)
  bucket = "reports-${var.markets[count.index]}"
}

# SEED 9 [SUGGESTION] (terraform/variable-metadata) variable missing description and type
variable "markets" {
  default = ["uk", "de", "es"]
}