magodo / terraform-provider-restful

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

String body is always quoted with double quotes #124

Open ToniA opened 1 day ago

ToniA commented 1 day ago

I'm trying to control Keycloak's new Organization features with raw REST API, as the Terraform module https://github.com/mrparkers/terraform-provider-keycloak does not support it yet.

I have problems with the Organizations identity-providers endpoint. It expects a string as payload, a plaintext alias like b2c in my example below. What happens is that the string body is wrapped into double quotes like "b2c", and I get {"errorMessage":"Identity provider not found with the given alias"} as a response.

resource "restful_resource" "organization_idp" {
  provider = restful

  path  = "/admin/realms/${restful_resource.realm.body.realm}/organizations/${restful_resource.organization.output.id}/identity-providers"
  body = "b2c"
}

I added stn1slv/http-proxy-logger into my docker-compose development enviroment, to log the REST API traffic, and this is what I'm seeing:

http-proxy-logger-1  | 2024/11/06 13:35:16 ---REQUEST 16---
http-proxy-logger-1  | 
http-proxy-logger-1  | POST /admin/realms/demo/organizations/b109e04e-b531-46d9-a1ca-6fd9dbbe4fd4/identity-providers HTTP/1.1
http-proxy-logger-1  | Host: keycloak:8080
http-proxy-logger-1  | User-Agent: go-resty/2.10.0 (https://github.com/go-resty/resty)
http-proxy-logger-1  | Content-Length: 5
http-proxy-logger-1  | Accept: application/json
http-proxy-logger-1  | Accept-Encoding: gzip
http-proxy-logger-1  | Authorization: Bearer ***
http-proxy-logger-1  | Content-Type: application/json
http-proxy-logger-1  | X-Forwarded-For: 172.18.0.1
http-proxy-logger-1  | 
http-proxy-logger-1  | "b2c"
http-proxy-logger-1  | 
http-proxy-logger-1  | 2024/11/06 13:35:16 ---RESPONSE 16---
http-proxy-logger-1  | 
http-proxy-logger-1  | HTTP/1.1 400 Bad Request
http-proxy-logger-1  | Content-Length: 67
http-proxy-logger-1  | Content-Type: application/json
http-proxy-logger-1  | Referrer-Policy: no-referrer
http-proxy-logger-1  | Strict-Transport-Security: max-age=31536000; includeSubDomains
http-proxy-logger-1  | X-Content-Type-Options: nosniff
http-proxy-logger-1  | X-Frame-Options: SAMEORIGIN
http-proxy-logger-1  | X-Xss-Protection: 1; mode=block
http-proxy-logger-1  | 
http-proxy-logger-1  | {"errorMessage":"Identity provider not found with the given alias"}
http-proxy-logger-1  |