Coder Social home page Coder Social logo

Comments (2)

apparentlymart avatar apparentlymart commented on June 25, 2024

Hi @tcgbrett,

I think you are describing a behavior of HCL, not a behavior of cty. HCL's string syntax uses ${ to represent the start of a template interpolation, and so HCL must escape it as $${ to ensure that the resulting string will be interpreted literally, rather than being interpreted as a template.

If your intention was to generate query = thing.thing.id then I think you may want body.SetAttributeTraversal instead. If that doesn't get you what you want then I suggest asking in Terraform's community forum, which is a reasonable place to ask general questions about Terraform.

from go-cty.

tcgbrett avatar tcgbrett commented on June 25, 2024

Hey @apparentlymart,

Thank you for the response! Hmm, my goal was to actually not escape it, as I don't want the resulting string to be interpreted literally. I am using CTY to generate HCL for me so I don't have to write dozens of HCL files by hand. My goal is that the CTY will spit out some HCL that has template interpolation baked into it.

To give the exact example, I'm building a bunch of New Relic dashboards. I want CTY to be able to produce HCL interpolation. Here's what I keep getting stuck with tho:

nrql {
  query = "FROM Metric SELECT clamp_max(sum(newrelic.sli.good) / sum(newrelic.sli.valid) * 100, 100) as 'SLO compliance' WHERE entity.guid = $${newrelic_service_level.asdf---test---order-management_apm.id}"
}

And here is the go code

baseSLOQuery := fmt.Sprintf("FROM Metric SELECT clamp_max(sum(newrelic.sli.good) / sum(newrelic.sli.valid) * 100, 100) as 'SLO compliance' WHERE entity.guid = ${newrelic_service_level.%s.id}", neatSLOName)
nrqlBody.SetAttributeValue("query", cty.StringVal(baseSLOQuery))

Do you have any suggestions?
Thanks again for reading and commenting :)

from go-cty.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.