question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Number attributes not synthed as references

See original GitHub issue

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave “+1” or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

cdktf & Language Versions

com.hashicorp:cdktf:0.9.0 “aws@~> 3.0” OpenJDK Runtime Environment (build 1.8.0_312-b10)

Affected Resource(s)

https://www.terraform.io/docs/providers/aws/r/memorydb_cluster https://www.terraform.io/docs/providers/aws/r/db_instance

Debug Output

Expected Behavior

db.port should synthesize to Terraform reference instead of number:

"value": "${aws_memorydb_cluster.cluster_9AC9C0F1.cluster_endpoint.0.port}"

This workaround can achieve the above:

db.getStringAttribute("port")

Actual Behavior

db.port synthesizes to:

"value": "-8.109562212591454E298"

Steps to Reproduce

I assume this happens for any provider when trying to synth number types.

Important Factoids

This seems to be a regression as I found #679 that was supposedly fixed in 0.6.0.

References

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:2
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
DanielMSchmidtcommented, Sep 16, 2022

Hey folks, sorry for taking so long, but I have found the problem.

During synth your program transforms the number to a sting with Gson. After that CDKTF runs through all the numbers it knows of and translates them to terraform expressions if applicable. But your number is not a number anymore, it’s a string now so we dont catch it. To solve this issue right now you can use Fn.jsonencode(testingResource) and it works.

The bigger question here is, can we make your current example work. I think we possibly can try to find things that look like numbers in all strings and see if they are known to us. For that we would need to check if a tokenized number can collide with another tokenized number if serialized to string. If we are sure this can not happen we can then search through every string for something that looks like a serialized number and replace this with the TF expression needed. The serialization format could vary between languages though, JS uses e+ instead of E like Java for example. It could also be a custom serialization engine being used. So I guess it’s hard to get right all the time, but getting it right most of the time and never getting it wrong would be sufficient I think

0reactions
marceloaguiarrcommented, Sep 15, 2022

Hello. I have created this repo to show the error happening. Hope that makes things more clear.

All you have to do is clone, then run the test class. It should print the synthesized string with the error. As you said, this really looks like a rounding error when the serialisation of the java class into json happens.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Attributes and Aliasing - Datadog Docs
This provides guidance towards the naming convention, and discourages users from building assets (such as saved views or dashboards) based on non-standard ...
Read more >
Binary Attribute - an overview | ScienceDirect Topics
The total number of attributes is p, where p = q + r + s + t. Table 2.3. ... For asymmetric binary...
Read more >
Fine-Grained Attribute Analysis for Person Re-Identification
To our best knowledge, we are among the first attempts to explicitly dissect person re-ID from the aspect of attribute on synthetic dataset....
Read more >
XML Information Set (Second Edition) - W3C
This list contains element, processing instruction, unexpanded entity reference, character, and comment information items, one for each element, ...
Read more >
Chapter 4. The class File Format - Oracle Help Center
The value of the attributes_count item gives the number of attributes (§4.7) in the attributes ... A reference to this is not passed...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found