Skip to content

Conversation

@emcniece
Copy link

@emcniece emcniece commented Nov 27, 2025

Related Issue

Fixes #538

Description

Adds the ability to change the rendered code format for anything handled by the {{ tffile }} method, like example files. Includes test coverage and documentation.

Can be used in several ways:

  • tfplugindocs generate --syntax hcl - change all tffile syntax code block across the whole site
  • {{ tffile . "hcl" }} - change syntax for specific template sections
  • {{ tffile . .Format }} - change syntax based on page header definitions

Example outputs

With tfplugindocs generate --provider-dir . --provider-name myProvider: (default behavior)

```terraform
# Copyright (c) 2021 Hashicorp, Inc.
# SPDX-License-Identifier: MPL-2.0

data "myprovider_thingy" "example" {
  id = "43fe6a70-ca3f-4e8a-bf16-786866170aa0"
}
```

With tfplugindocs generate --provider-dir . --provider-name myProvider --syntax hcl: (new behavior)

```hcl
# Copyright (c) 2021 Hashicorp, Inc.
# SPDX-License-Identifier: MPL-2.0

data "myprovider_thingy" "example" {
  id = "43fe6a70-ca3f-4e8a-bf16-786866170aa0"
}
```

Why

Implemented because I am stuck with a syntax highlighter in a documentation generator that is outside of my control, and I need to use hcl syntax 😁

Rollback Plan

  • If a change needs to be reverted, we will roll out an update to the code within 7 days.

Changes to Security Controls

Are there any changes to security controls (access controls, encryption, logging) in this pull request? If so, explain.

No security control changes.

@emcniece emcniece requested a review from a team as a code owner November 27, 2025 21:18
@hashicorp-cla-app
Copy link

hashicorp-cla-app bot commented Nov 27, 2025

CLA assistant check
All committers have signed the CLA.

@hashicorp-cla-app
Copy link

CLA assistant check

Thank you for your submission! We require that all contributors sign our Contributor License Agreement ("CLA") before we can accept the contribution. Read and sign the agreement

Learn more about why HashiCorp requires a CLA and what the CLA includes

Have you signed the CLA already but the status is still pending? Recheck it.

@emcniece
Copy link
Author

emcniece commented Dec 4, 2025

I've signed the CLA several times, not sure why it won't resolve :\

@SBGoods
Copy link
Contributor

SBGoods commented Dec 8, 2025

Hi @emcniece 👋🏾,
Thank you for the contribution! I am a bit reluctant to accept this PR as terraform-plugin-docs is meant to generate reasonable defaults for the Terraform public registry. The registry aliases terraform and tf for hcl code blocks, so adding an option to change terraform to hcl doesn't add a lot of value for most users.

Also it is possible to achieve what you want here by using a custom template with by replacing the tffile lines in the default template with {{codefile "hcl" filepath }}

@emcniece
Copy link
Author

emcniece commented Dec 8, 2025

Makes sense, thanks for the info. I wouldn't mind seeing some documentation about that {{ codefile }} usage mentioned in this project in case someone else runs into the same issue 😁

@emcniece emcniece closed this Dec 8, 2025
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.

Change terraform to hcl syntax highlighting?

2 participants