hcledit icon indicating copy to clipboard operation
hcledit copied to clipboard

Inline comment make parser stop

Open bjornrog opened this issue 4 years ago • 2 comments
trafficstars

Hi!

I'm trying to use hcledit to parse module input variables of type object(), with inline comments. Looking like this:

variable "test" {
  type = object({
    foo = string     # The foo variable is used to control the foo'nes
    bar = number     # The number of foos
  })
}

But cat variables.tf | hcledit attribute get "variable.test.type" will only output the first key in the object:

object({
    foo = string

If I remove the two inline comments, the output of hcledit is correct:

object({
    foo = string
    bar = number
  })

We are using these comments to document complex variables and need to have them inline.

bjornrog avatar Jun 17 '21 12:06 bjornrog

@bjornrog Thank you for reporting this! It looks a bug caused by a hack here due to the current limitation of the hcl library.

https://github.com/minamijoyo/hcledit/blob/397e5f46bda35b45501b36b841afd8b9d683a0f4/editor/sink_attribute_get.go#L184-L205

I think it's hard to resolve the root cause, but probably possible adding a new flag to include or exclude an inline comment. Does it make sense as a workaround for you?

minamijoyo avatar Jul 21 '21 09:07 minamijoyo

Additionally the // character string also breaks the parser.

davidjeddy avatar Apr 06 '22 12:04 davidjeddy

Fixed in v0.2.8 🚀

minamijoyo avatar May 11 '23 00:05 minamijoyo