Skip to content
Testaroo
hcl1.2 KB

HCL2 Policy Document

A generic HCL2 policy document with three severity-graded rules, condition blocks using all_of / none_of / one_of, and a dated exemption. Grants nothing to anything; it exists so policy tooling has a realistic document to read.

Preview, first 45 lineshcl
# Generic HCL2 policy document. Describes allow/deny rules for a fictional control plane;
# it grants nothing, because nothing reads it.
policy "deploy-guardrails" {
  description = "Guardrails applied to every deployment in the example estate."
  enforcement = "hard-mandatory"

  rule "require-resource-limits" {
    description = "Every container must declare CPU and memory limits."
    severity    = "high"
    applies_to  = ["Deployment", "StatefulSet", "CronJob"]

    condition {
      all_of = [
        "spec.template.spec.containers[*].resources.limits.cpu",
        "spec.template.spec.containers[*].resources.limits.memory",
      ]
    }
  }

  rule "forbid-latest-tag" {
    description = "Image references must be pinned to an explicit tag."
    severity    = "medium"

    condition {
      none_of = ["*:latest"]
      field   = "spec.template.spec.containers[*].image"
    }
  }

  rule "restrict-namespaces" {
    severity = "low"

    condition {
      one_of = ["example-apps", "example-gitops", "example-tools"]
      field  = "metadata.namespace"
    }
  }

  exemption "bootstrap" {
    reason     = "Cluster bootstrap runs before the policy controller is available."
    expires_on = "2026-12-31"
    namespaces = ["kube-system"]
  }
}

Specifications

Grammar
HCL2
Rules
3
Exemptions
1
Enforcement
hard-mandatory
Severities
high, medium, low

Testing contract

Expected to pass
Scenario
Read a policy document's rules, severities, and exemptions from HCL2
Expected result
Three rules resolve with distinct severities and one exemption is found carrying an expiry date and a namespace list

What is a .hcl file?

HCL (HashiCorp Configuration Language) is the block-structured configuration language behind Terraform, Packer, Nomad, Consul, and Vault. A document is a sequence of attributes (`name = expression`) and blocks (a type, zero or more string labels, and a braced body), with support for heredocs, function calls, conditionals, and for-expressions. It is designed to be both hand-written and machine-generated, and has a documented JSON-equivalent syntax.

How to use this file

Use an example .hcl file to test HCL parsers, configuration linters, and JSON-syntax converters, exercising nested blocks with multiple labels, heredoc indentation, and comment styles (`#`, `//`, and `/* */`).

How to use this file for testing

“HCL2 Policy Document” is a deterministic Testaroo fixture for Config testing, Config parsing, Syntax highlighting. TOML, INI, YAML, .env, and dotfile configuration samples with nested sections and typed values, for testing config parsers, loaders, and environment tooling.

Documented properties for this file: HCL · 1,262 bytes. Compare results against paired or grouped companions on this page when present (clean↔damaged, searchable↔scanned, or format twins) so scores stay reproducible across runs.

Download the file once, keep the path stable in CI or local scripts, and treat the spec table as the contract: dimensions, seeds, field lists, and roles are intentional. Corrupt or invalid samples are labelled as such, expect parsers to fail loudly rather than silently accept them.

Pipeline and infrastructure fixtures are inert configuration: steps reference fictional images and scripts, and nothing here executes. Run your linter, schema validator, migrator, or policy engine against them, and expect the deprecated-syntax and intentionally invalid variants to be rejected.

Point your config loader at the file and assert it reads the documented sections and typed values, including any deliberately-tricky nesting or comments.

Generated by generation/pipelines.py. Free for any use, no attribution required, license.