Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect $ parsing as string element #24

Closed
doctornkz opened this issue Jul 4, 2019 · 6 comments
Closed

Incorrect $ parsing as string element #24

doctornkz opened this issue Jul 4, 2019 · 6 comments

Comments

@doctornkz
Copy link

How repoduce:
Go to https://play.golang.org/
Put that code there:

package main
import (
	"fmt"
	"github.com/hashicorp/hcl2/hclwrite"
	"github.com/zclconf/go-cty/cty"
)
func main() {
	f := hclwrite.NewEmptyFile()
	rootBody := f.Body()
	rootBody.SetAttributeValue("hello", cty.StringVal("${world}"))
	fmt.Printf("%s", f.Bytes())
}

Receive:

hello = "$${world}"

Expected:
hello = "${world}"

I was trying a couple ways to escape that, but it doesn't work.

@doctornkz
Copy link
Author

doctornkz commented Jul 4, 2019

I found the tricky solution. If I use cty.StringVal("$${world}") I am receiving hello = "$$${world}" and doubled $$ compensate each other and it works like one $. But I think it's not good way to fix.

@apparentlymart
Copy link
Collaborator

apparentlymart commented Jul 4, 2019

Hi @doctornkz,

What you are seeing here seems to be an HCL behavior, not a cty behavior. With that said, I believe it's working as intended because it's escaping the ${ sequence in your literal string so that the HCL parser would then see it as a literal ${ rather than the beginning of an interpolation sequence. If you'd like to discuss this more, please open an issue in the HCL repository.

@doctornkz
Copy link
Author

I solved problem with hcl.Traversal() .Now, I can create templated config file. Ugly, but works good for me.

@marcsauter
Copy link

@doctornkz do you have an example of your solution?

@doctornkz
Copy link
Author

@marcsauter take a look here: https://github.com/doctornkz/signalfx2terraform/blob/master/builder/dashboard.go#L79-L84
it gives me possibility generate that example:

  chart {                  
    chart_id = "${signalfx_time_chart.sfx-XXXXXX.id}"
    column   = 0    
    row      = 1
    width    = 6
    height   = 1                                                      
  }

with ${} inside the structure

@marcsauter
Copy link

Thank you so much, that solves out problem.

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

No branches or pull requests

3 participants