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

Add support for std.trace() #13

Open
david-raine opened this issue Dec 16, 2024 · 3 comments
Open

Add support for std.trace() #13

david-raine opened this issue Dec 16, 2024 · 3 comments

Comments

@david-raine
Copy link

It can be very difficult to debug errors in jsonnet code when called from a terraform module and the std.trace() function in jsonnet does not appear to be surfaced to the terraform space. Could this be added?

@alxrem
Copy link
Owner

alxrem commented Dec 16, 2024

Hello.

Try version 2.4.0. For example:

terraform {
  required_providers {
    jsonnet = {
      source  = "alxrem/jsonnet"
      version = "~> 2.4"
    }
  }
}

data "jsonnet_file" "default" {
  content = <<EOF
  {
    a: std.trace("str", "rest"),
  }
  EOF
}

output "json" {
  value = data.jsonnet_file.default.rendered
}

output "trace" {
  value = data.jsonnet_file.default.trace
}
> terraform apply -auto-approve 
data.jsonnet_file.default: Reading...
data.jsonnet_file.default: Read complete after 0s [id=05502b56511b3669cd6a57e43ab217cbb982dbc2c6dd5ac32b5d937a641eccef]

No changes. Your infrastructure matches the configuration.

Terraform has compared your real infrastructure against your configuration and found no differences, so no changes are needed.

Apply complete! Resources: 0 added, 0 changed, 0 destroyed.

Outputs:

json = <<EOT
{
   "a": "rest"
}

EOT
trace = <<EOT
TRACE: data:2 str

EOT

@david-raine
Copy link
Author

Thanks Alexey! Is it possible to surface trace() function output under error condition, when the message "Failed to render test from jsonnet template" occurs?

@alxrem
Copy link
Owner

alxrem commented Dec 17, 2024

Yes. Try 2.4.1.

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

2 participants