Comments (1)
Hi @tcgbrett,
Sorry I missed this before.
The escaping you are concerned about is being done by nrqlBody.SetAttributeValue
(in HCL), not by cty.StringVal
.
Here's the SetAttributeValue
function's implementation: https://github.com/hashicorp/hcl/blob/63067e819cb6e8044d34b0a32d198a4941f34e42/hclwrite/ast_body.go#L168-L179
It calls NewExpressionLiteral
: https://github.com/hashicorp/hcl/blob/63067e819cb6e8044d34b0a32d198a4941f34e42/hclwrite/ast_expression.go#L63-L68
...which calls TokensForValue
which then, after a few other calls I'm skipping over, escapes the given string: https://github.com/hashicorp/hcl/blob/63067e819cb6e8044d34b0a32d198a4941f34e42/hclwrite/generate.go#L220
That escapeQuotedStringLit
function is the one doing the escaping: https://github.com/hashicorp/hcl/blob/63067e819cb6e8044d34b0a32d198a4941f34e42/hclwrite/generate.go#L367-L373
It does that because SetAttributeValue
is for setting the attribute to a constant value, not for setting it to an arbitrary expression. hclwrite
currently lacks a function for setting an attribute to be a string template, because it lacks any model of string templates beyond the minimum required to generate literal strings. The closest you can get with the current API is to use SetAttributeRaw
, but that requires you to hand-write the individual tokens that the template expression is built from.
hclwrite
's model of expressions was originally built around what Terraform needed for some of its work and so it's lacking various features for constructing arbitrary expressions. It should be possible in principle to add an API for building string template expressions, and other kinds of expressions, but that's a topic for HashiCorp's HCL repository, rather than this codebase.
I also can't promise that the Terraform team at HashiCorp (who are the primarily maintainers of HCL) will be able to prioritize this, both because in this repository I'm wearing my cty
maintainer hat (this is a personal project that HashiCorp projects depend on, rather than a HashiCorp project) and because even when I'm wearing my Terraform team hat I'm not the one who decides the team's development priorities. Opening an issue in the HCL repository to discuss your use-case would probably be the best next step, though.
from go-cty.
Related Issues (20)
- 1.11.0 causes errors with //go:generate packer-sdc mapstructure-to-hcl2 HOT 1
- hashicorp/packer-plugin-sdk incompatible with zclconf/go-cty v1.11.0 HOT 4
- TestFormatDate fails with upcoming Go 1.20 release HOT 5
- Add support for decoding into structs with a custom tag HOT 1
- Nested go struct to cty value fails HOT 1
- Proposal: JSON serialization of `cty.Path` HOT 3
- cty/json: configure (non-)HTML-escaping serialization HOT 3
- stdlib: SetProductFunc doesn't seem to handle refinements quite right HOT 2
- How to convert cty.Value of unknown type into `interface{}` HOT 2
- cty.StringVal always doubles $ in `${}` output HOT 2
- Parse string into cty type HOT 1
- adding jsonencode() block into a generated terraform file using golang cty HOT 2
- Encoding values with custom function (terraform provider) HOT 1
- Marshal() generate invalid JSON HOT 2
- panic with `AsString()` on result of json encoding of to_number conversion of null value HOT 4
- Some valid `Path` values cannot be applied to their source `Value` HOT 2
- Add a deepmerge function HOT 1
- `ObjectVal` or `MapVal `without `NormalizeString` HOT 6
- Some method to avoid the lexicographical order when parsing tokens HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from go-cty.