Add terraform file support for blob viewer in repository
-
Please check this box if this contribution uses AI-generated content (including content generated by GitLab Duo features) as outlined in the GitLab DCO & CLA. As a benefit of being a GitLab Community Contributor, you receive complimentary access to GitLab Duo.
What does this MR do?
This merge request resolves Issue #514908, where .tf (Terraform) files are improperly highlighted or shown without syntax highlighting in the blob viewer due to the absence of Terraform support in Highlight.js.
Why was this needed?
- Highlight.js does not officially support Terraform or HCL.
- Although a
highlightjs-terraformrepository exists, it is not maintained or published to npm. - GitLab currently attempts to highlight
.tffiles using Highlight.js, which leads to rendering issues such as misinterpretation of the.operator in expressions likedata.terraform_remote_state.backend.outputs.value.
What’s in the patch?
.tf files
Why Rouge?
GitLab already uses Rouge on the backend for syntax highlighting and it supports:
Rouge::Lexers::HCL
This change leverages the existing Rouge lexers for proper and consistent highlighting of Terraform files.
How was it tested?
- Added a sample
test.tffile using common Terraform constructs such as provider, data sources, outputs, and chained expressions. - Verified that it renders
.tfsyntax correctly in the blob viewer. - Confirmed blob viewer tests pass with the added Ruby test case.
Screenshot / Visual (if applicable)
MR acceptance checklist
Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.
Related to #514908
Edited by Munish
