Enhancement: scan Terraform / OpenTofu JSON configs (`.tf.json`, `.tofu.json`)

Aperta
#719 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
55/100
Tipo di issue
Funzionalità
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
typescript
Ambito
backend, cli

Direzione di ricerca

Start with isTerraformManifest and extractTerraformRequirements in src/core-open/scanners/terraform-scanner.ts, then read parseHclBlocks in src/core-open/scanners/hcl-blocks.ts and the precedence tests in test/terraform-scanner.test.ts. Add coverage for JSON manifest detection, declarations, HCL and JSON conflicts, OpenTofu shadowing, and invalid JSON; use the existing module source classifier. Done means the acceptance cases pass and the selected precedence and invalid JSON behavior are documented in DOCS.md.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

enhancement help wanted
  • Difficulty: medium
  • Area: Terraform scanner
Problem

isTerraformManifest in src/core-open/scanners/terraform-scanner.ts (around lines 383–384) only accepts .tf and .tofu. test/terraform-scanner.test.ts (around line 154) pins isTerraformManifest('main.tf.json') to false. Terraform’s official JSON syntax (*.tf.json) and OpenTofu’s *.tofu.json are therefore never parsed.

extractTerraformRequirements walks HCL via parseHclBlocks (src/core-open/scanners/hcl-blocks.ts). JSON configs need a different walk of the same shapes: terraform.required_version, terraform.required_providers, provider blocks, and module blocks with source / version.

A directory that contains only versions.tf.json is not even a project. A mixed directory silently omits providers and modules declared only in the JSON files.

Expected behaviour

Treat .tf.json and .tofu.json as Terraform manifests. Apply the same OpenTofu shadowing rule already documented for .tofu vs .tf (a same-stem .tofu.json replaces .tf.json / .tf as appropriate — pin the exact precedence in the test and a short DOCS.md note). Parse JSON objects for required_version, required_providers (including the legacy version-only shorthand), standalone provider version pins, and registry module sources. Reuse classifyTerraformModuleSource so git / local / S3 sources stay non-registry. Invalid JSON fails that file in an actionable way or is skipped without a stack trace; pin one behaviour and document it. HCL files stay on the existing parser.

Acceptance
  • isTerraformManifest('versions.tf.json') and isTerraformManifest('versions.tofu.json') are true; readme.md is still false.
  • A project with only versions.tf.json declaring a provider and a registry module reports them (offline scan is enough for declaration).
  • A same-directory HCL + JSON combination does not double-count the same provider source; pin how a conflict is resolved.
  • Existing .tf / .tofu tests keep passing, including the OpenTofu stem-shadowing cases in test/terraform-scanner.test.ts.

Lingua principale
TypeScript
Stelle
4
Fork
3
Merge medio
1g 22h
PR unite (30g)
76

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di vibgrate/cli

Tutte le issue di vibgrate/cli

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.