Mastercard / terraform-provider-restapi

A terraform provider to manage objects in a RESTful API
Other
817 stars 217 forks source link

Compatibility issue with iTop API which expects json_data parameter to be passed #180

Open alexralph opened 2 years ago

alexralph commented 2 years ago

When I use the Mastercard/terraform-provider-restapi and I send json data using the resource I receive an error back from theiTop api: "{"code":3,"message":"Error: Missing parameter 'json_data'"}: timestamp=2022-06-30T10:51:01.012+0100" So it seems that the API I am trying to send the json data to is expecting a json_data parameter. Any idea how to get this provider/resource to send the json data using a json_data parameter is a change needed to support this or can the provider do this in some way?

Here is my code:

terraform {
  required_providers {
    restapi = {
      source               = "Mastercard/restapi"
      version              = "1.17.0"
    }
  }
}

provider "restapi" {
    uri                  = "${var.uri}"
    debug                = true
    write_returns_object = true
    username = "${var.auth_user}"
    password = "${var.auth_passwd}"

    headers = {
        "Content-Type" = "application/json"
    }
    create_method  = "POST"
}

resource "restapi_object" "post_request" {
    path = "/webservices/rest.php?version=1.2"
    data = "{\"operation\": \"core/create\", <remaining valid json removed for clarity>}
}
DRuggeri commented 2 years ago

Hi, @alexralph. That should be easily accomplished by putting the data element in your data like so:

resource "restapi_object" "post_request" {
    path = "/webservices/rest.php?version=1.2"
    data = "{\"json_data\": {\"operation\": \"core/create\", <remaining valid json removed for clarity>}}"
}

Have you tried this kind of approach yet?

alexralph commented 2 years ago

Thanks @DRuggeri - yes I had already tried this - it produces the same error. I assume that the provider is putting the data value into the POST body, but I think that the iTop API is expecting a parameterised url like /uri/path&json_data="{JSON-string}"

DRuggeri commented 2 years ago

Ah - I understand what you mean. Yes, if it is expecting a param in the URL, the provider won't be able to be of much help, unfortunately.

If you're curious about the exact data that goes to/from the API, you can always observe the contents by using debug mode (quick howto is in the readme)