magodo / terraform-provider-restful

Terraform provider to manage RESTful resources
https://registry.terraform.io/providers/magodo/restful
Mozilla Public License 2.0
16 stars 5 forks source link

Restful Operation - Error: Filter `output` during operation - can not unmarshal json response array #97

Closed wilkejo closed 6 months ago

wilkejo commented 6 months ago

Hello again :)

I planned to use/test the restful_operation to set permissions with an API. The response is an array (details see below) and I get the error Error: Filter output during operation

used provider version

source = "magodo/restful" version = "0.13.3"

terraform resource

resource "restful_operation" "user_permissions" {
  method = "PUT"
  path   = "/public/v1/users/${local.user.email}/permissions"
  body   = jsonencode(local.permissions)
  poll = {

    status_locator = "code"
    status = {
      success = "200"
    }
  }
  output_attrs = ["user"]
}

error message:

restful_operation.user_permissions: Creating... ╷ │ Error: Filter output during operation │ │ with restful_operation.user_permissions, │ on main.tf line 95, in resource "restful_operation" "user_permissions": │ 95: resource "restful_operation" "user_permissions" { │ │ unexpected end of JSON input ╵

example API response

[
  {
    "resourceType": "Topic",
    "clusterId": "my-cluster",
    "topicPattern": "finance-*",
    "permissions": [
      "topicCreate",
      "topicDelete"
    ]
  }
]
magodo commented 6 months ago

The oepration resource filter the output based on the response of the PUT. If it returns you an array as shown above, and you are only care about the field, say clusterId (as I don't see a field named user in above response), you can do:

output_attrs = ["#.clusterId"]

This will then filter the output into:

[
  {
    "clusterId": "my-cluster"
  }
]
wilkejo commented 6 months ago

Thank you, I got confused with my requests and responses. Everything is fine, thank you :)