infobloxopen/infoblox-client

Working API that won't accept empty JSON body on PUT

Closed this issue · 1 comments

I am trying to implement some Terraform-like behavior in a resource exposed by the Infoblox API. In this case, I want to change an attribute of an object to mark it as reserved, then null those properties when the resource is no longer needed. This is because the object I'm working with persistently exists and can't/shouldn't be deleted.

So I followed the example in terraform-provider-restapi/examples/update_field_with_put_request.tf. I use an external script with a restapi datasource to get the next available object from my API's pool. Then I use the restapi resource to redirect the create action from POST to PUT. The create and change methods work great:

locals {
  tenant_private_extattrs = {
    extattrs = {
      "Tenant ID" = {
        value = "sh_${var.tenant_name}"
      }
    }
  }
}
resource "restapi_object" "tenant_private_vlan" {
  path           = "/${data.external.next_private_vlan.result._ref}?_return_as_object=1"
  object_id      = data.external.next_private_vlan.result._ref
  create_method  = "PUT"
  destroy_method = "PUT"
  data           = jsonencode(local.tenant_private_extattrs)
}

When it comes time to destroy though, the upstream API complains because the provider tries to send an empty json body and gives the following error message:

╷
│ Error: unexpected response code '400': { "Error": "AdmConProtoError: PUT requires indata, none given",
│   "code": "Client.Ibap.Proto",
│   "text": "PUT requires indata, none given"
│ }
│
│
╵

Ideally I'd prefer the resource destruction to set the parameters back to empty, but I'd also just be okay with something non-empty being sent to the server to satisfy the API and using a destroy-time provisioner to set the attributes back to empty.

Filed against the wrong repo, apologies.