-
Notifications
You must be signed in to change notification settings - Fork 220
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
Parsing api_data output #45
Comments
The purpose of api_data was so you could reference one of the items that came back in the response directly. Unfortunately, it has a limitation. It can only provide that for "root" keys. So, if I parsed your example correctly, the response looks like what follows, which means only "loadBalancer" is something that can be referenced in this way. The result of that lookup will be what you are seeing: a golang representation of that key coaxed to a string.
|
I think having a way to deeper reference the data of the API result is a very useful feature, but I'm not sure how to go about doing this right now. I'll keep this issue open with the help wanted flag to see if any proposals come up. |
Hi @DRuggeri - I just saw this provider and it looks awesome! 🎉 Terraform 0.12 now has a locals {
json_raw = "{\"foo\":[{\"bar\":456}]}"
json_parsed = jsondecode(local.json_raw)
}
output "json_test" {
value = local.json_parsed.foo[0].bar
} Alternatively, if |
Now that is something I can get behind! I've been thinking about also making an api_data_string type of attribute as well... |
That seems to work OK. I just added an attribute named
I can access the apiKey attribute like so: output "api_key" {
value = lookup(lookup(jsondecode(restapi_object.default.api_body), "data"), "apiKey")
} Terraform recognises the string looks like a JSON object and nicely formats it. I can send you a PR if you're OK with it. I ended up using nested |
Actually, dot notation works with functions: output "api_key" {
value = jsondecode(restapi_object.default.api_body).data.apiKey
} |
@gazoakley, need your PR :p |
@cvalentin-adeo: PR #54 is waiting for review. |
Good news ;) |
Indeed! Waiting for the approval on the PR #54 |
I've reviewed #54 - and am totally on board! I have just one question about expanding scope to include the datasource, but once we settle a path forward, I'll merge and release soon. This is an awesome feature! |
With #54 having been merged and released, I think we can close this guy out! |
Hi again,
As mentioned on #43, I'm creating some LB's using an API call, and once the API is made I'm trying to use the output on terraform.
Right now, when I use:
This is the output:
When I use:
The output is:
And finally, when I use:
Does not even run correctly, the output is:
Please help!!
The text was updated successfully, but these errors were encountered: