pygments icon indicating copy to clipboard operation
pygments copied to clipboard

HashiCorp Configuration Language (HCL) Support

Open karras opened this issue 5 years ago • 16 comments

The HashiCorp Configuration Language (HCL) is becoming very popular these days and also very handy to have in other projects such as MediaWiki, which make use of pygments.

karras avatar Jan 09 '20 17:01 karras

Specification: https://github.com/hashicorp/hcl

@hairmare ^

karras avatar Jan 09 '20 17:01 karras

pygments does support HCL but you have to label it as terraform which isn't 100% accurate, but seems to work pretty well for me.

appleshampooid avatar Jun 12 '20 16:06 appleshampooid

Good catch, totally missed that one. Thanks!

karras avatar Jun 14 '20 17:06 karras

Can you please have a look at #1756? Feedback is welcome. Thanks!

lgiordani avatar Mar 24 '21 17:03 lgiordani

@lgiordani I have a block that looks like this, which is failing when using pygments 2.9.0 with WARNING: Could not lex literal_block as "terraform". Highlighting skipped. Strange thing is this syntax is valid with both HCL 1 and HCL 2, and it was working fine with pygments 2.8.1.

```terraform
provider "aws" {}

module "test-lx-instance" {
  source = "git::https://github.com/plus3it/terraform-aws-watchmaker//modules/lx-instance/"

  Name      = "tf-watchmaker-lx-autoscale"
  AmiId     = "__AMIID__"
  AmiDistro = "__AMIDISTRO__"
}

lorengordon avatar Jun 16 '21 14:06 lorengordon

@lorengordon I'll have a look as soon as possible, thanks for the test case

lgiordani avatar Jun 16 '21 14:06 lgiordani

Can someone confirm this fixed by #1756? I see an error on the first } but that seems unrelated?

Anteru avatar Jun 20 '21 10:06 Anteru

I am using terragrunt that also uses HCL for configuration. The changes from #1756 do not fix that. Should I open another issue for this (even though it's using HCL)?

An example for terragrunt's configuration is below:

terraform {
  source =
    "github.com:foo/infrastructure-modules.git//app?ref=v0.0.1"
}
inputs = {
  instance_count = 10
  instance_type  = "m4.large"
}

Jeinhaus avatar Jul 05 '21 07:07 Jeinhaus

Given #1756 doesn't fix your issue, but is already merged, I'd suggest to open a new one. For my understanding: Is terragrunt using a dialect of HCL or is that a problem for "plain" HCL?

Anteru avatar Jul 18 '21 08:07 Anteru

@Anteru The linked PR #1756 is included in the 2.9.0 release and does not appear to fix this issue. I can't test what it does work for, but it does not work for basic Terraform syntax that is the same in both HCL2 and HCL1, as I mentioned above.

lorengordon avatar Jul 18 '21 14:07 lorengordon

Hi all, my work on #1756 was checked against a large Terraform code base (~100k lines), but I didn't implement the HCL specification following it rule by rule, so I'm not surprised that isn't covered. I think it's simpler to open a new issue with the failing use case and steps to reproduce so that whoever has time to look into it can easily create the test environment.

lgiordani avatar Jul 19 '21 08:07 lgiordani

@lgiordani Just closing the loop, there's a patch for the problem I was noticing in #1987 ...

lorengordon avatar Dec 21 '21 14:12 lorengordon

Thank you @lorengordon!

lgiordani avatar Dec 21 '21 15:12 lgiordani

There's a chance support for the syntax regression I mentioned was fixed in #2097. Just waiting on the next release to test it.

lorengordon avatar Apr 11 '22 13:04 lorengordon

Can confirm #2097 fixed the issue for us, in the 2.12.0 release.

lorengordon avatar Apr 25 '22 14:04 lorengordon

Thank you @lorengordon!

lgiordani avatar Apr 25 '22 14:04 lgiordani