-
Notifications
You must be signed in to change notification settings - Fork 9.6k
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
lookup fails on a JSON input #16154
Comments
Use the official example (because its url is alive).
When run with debug option, I see the error. (But it doesn't display in normal mode)
So the body output is a string only. That's why it doesn't work with your codes. Because You need to convert the string to map first. |
Seems you need to write a new built-in Functions terraform/config/interpolate_funcs.go Refer codes : https://www.socketloop.com/tutorials/golang-how-to-convert-json-string-to-map-and-slice https://stackoverflow.com/questions/11066946/partly-json-unmarshal-into-a-map-in-go |
Hi @ofer-velich! As @ozbillwang said, the problem here is that the At present Terraform does not have a JSON decoder, because the type system for the configuration language can't represent the interface for such a function (it's a function that takes a string and returns any type based on the input). The good news is that we're currently working on improving the configuration language to support such things, and once done planning to introduce a new function # NOT YET IMPLEMENTED and may change before release
data "http" "json_data" {
url = "http://example.com/jsondata"
# Optional request headers
request_headers {
"Accept" = "application/json"
}
}
output "json_data_key" {
value = "${jsondecode(data.http.json_data.body)["mykey"]}"
} This work is underway, but it's a big project so we're going to be releasing these new features gradually over a few separate releases to reduce risk. We'll have more to share on this soon. |
Hi all, I was going to verify a variant of the original configuration here in Terraform v0.12.0-alpha1, but sadly a build of the locals {
placeholder_json = <<EOT
{"country_iso":"US"}
EOT
}
output "detected_country" {
value = jsondecode(local.placeholder_json)["country_iso"]
}
While I used a local value string here instead of a data source, this There's some more discussion about this new Since this feature is already merged in master and verified in the alpha release, I'm going to close this. This feature will also be included in the forthcoming v0.12.0 final release. Thanks for sharing this use-case, and thanks for your patience while we laid the groundwork to make this possible. |
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further. |
Hi there,
Thank you for opening an issue. Please note that we try to keep the Terraform issue tracker reserved for bug reports and feature requests. For general usage questions, please see: https://www.terraform.io/community.html.
If your issue relates to a specific Terraform provider, please open it in the provider's own repository. The index of providers is at https://github.com/terraform-providers .
Terraform Version
Terraform v0.10.6
Terraform Configuration Files
module A
main.tf
Debug Output
Expected Behavior
Lookup should not fails ...
The
http://myservice/jsondata
returns a valid json stringIf i look on the plan output with out running the lookup on the returned json data i can see:
I would expect that the json would get decoded to a map object and i will be able to run lookup function on it
The text was updated successfully, but these errors were encountered: