Skip to content

GCSS-1127: add YAML schema validation before terraform plan#47

Merged
dev-milos merged 7 commits into
mainfrom
feature/gcss-1127-validate-yaml-before-tf-plan
Jun 11, 2026
Merged

GCSS-1127: add YAML schema validation before terraform plan#47
dev-milos merged 7 commits into
mainfrom
feature/gcss-1127-validate-yaml-before-tf-plan

Conversation

@dev-milos

@dev-milos dev-milos commented Jun 8, 2026

Copy link
Copy Markdown
Collaborator

Validate repos/*.yaml against schema before terraform plan

Closes G-Research/gr-oss#1127

Problem

Malformed repo config only surfaced deep inside terraform plan output — noisy and slow to diagnose.

Approach

Adds a validate job that runs before terraform-plan on every PR and validates all repo config files against the repository JSON schema, failing fast with a clear, file-scoped error.

Validation runs through the Go importer CLI (importer validate) rather than a standalone script. The schema is generated in-memory from the same Go structs that the schema command and Terraform already use, so there is a single source of truth and no checked-in snapshot to drift.

Acceptance criteria

  • PR with schema-violating YAML fails fast before plan runs
  • PR with valid YAML passes and proceeds to plan as today
  • github-configuration/.schemas/repository-config.schema.json, when added later, transparently overrides the built-in schema — no further wiring
  • Failure output cites the offending file + JSON path

Testing

  • Unit tests cover: valid, schema violation, missing required field, malformed YAML, .yml extension, empty dir, org-override precedence, and symlink-escape guard.
  • go build / go vet / go test ./... green; importer schema output byte-identical (refactor introduced no schema change).

Notes

  • The org override replaces the built-in schema (per the ticket). It's read from the PR head commit, so a PR could supply a permissive override — acceptable since this is a pre-plan lint, but flagging for awareness.
  • Rollout ordering: the validate job runs the action from the terraformer ref the config repo consumes, so this must be merged before config-repo PRs can use it.

dev-milos added 3 commits June 8, 2026 19:50
Validates repos/*.yaml files against a JSON schema before terraform plan
runs on PRs. Fails fast with a clear error if validation fails, preventing
wasted CI time on malformed configs.
Replaces the Python-based YAML schema validation with a Go implementation integrated into `github-repo-importer`. Streamlines workflow by leveraging the importer's built-in schema generator and validator. Updates CI to ensure the schema is current before validation.
Updates the validation logic to include both `.yaml` and `.yml` extensions. Refactors file globbing into a reusable function and adds a test case to ensure `.yml` files are validated correctly.
@dev-milos dev-milos requested a review from pavlovic-ivan June 9, 2026 13:18
@dev-milos dev-milos marked this pull request as ready for review June 9, 2026 13:18
@dev-milos dev-milos changed the title feat: add YAML schema validation before terraform plan GCSS-1127: add YAML schema validation before terraform plan Jun 9, 2026
@dev-milos dev-milos marked this pull request as draft June 10, 2026 10:26
Enhances schema resolution logic to include a fallback schema option (`--fallback-schema`) when no org-level override is present. Updates command flags, adjusts resolution priority, and extends test cases to verify fallback behavior.
@dev-milos dev-milos marked this pull request as ready for review June 10, 2026 11:43
Introduces `fallback-schema-path` input to the validation action and `base_schema_path` to the workflow, allowing customization of schema resolution. Uses fallback schema when no override is provided, defaulting to the bundled schema.
@pavlovic-ivan

Copy link
Copy Markdown
Contributor

Loo,

@pavlovic-ivan pavlovic-ivan left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good. Thanks, and well done 🎉

@dev-milos dev-milos merged commit f6cd348 into main Jun 11, 2026
1 check passed
@dev-milos dev-milos deleted the feature/gcss-1127-validate-yaml-before-tf-plan branch June 11, 2026 11:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants