Skip to content
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

restapi_object data is not optional #260

Open
Justin-DynamicD opened this issue Feb 2, 2024 · 2 comments
Open

restapi_object data is not optional #260

Justin-DynamicD opened this issue Feb 2, 2024 · 2 comments

Comments

@Justin-DynamicD
Copy link

Justin-DynamicD commented Feb 2, 2024

right now data is a required string for the restapi_object, which causes issues with some providers.

Notably CircleCI uses a curl POST with no data to create a new project, with configurations added by a separate call.

(https://circleci.com/docs/api/v2/index.html#operation/createProject)
vs.
(https://circleci.com/docs/api/v2/index.html#operation/patchProjectSettings)

To clarify, a get will still return a valid object with ID, it's just that initial POST needs to be empty :(

I can easily use update_path to make changes, but I cannot omit a default data variable during the initial create, nor even make them two different resources as the resource requires a data value.

@mdepedrof
Copy link

mdepedrof commented Oct 22, 2024

I have the same situation. I have an api that reads and deletes works without receive data. It only works set the id on the path.
this is an example

curl --location 'https://xxxxxxxx.com/api/v2/firewall/alias?id=21' \
--header 'x-api-key: xxxxxxxx' \

But when use terraform always send a data and then my API needs a few parameters on payload that I cant send.

2024-10-22T14:25:51.013+0200 [INFO]  provider.terraform-provider-restapi_v1.20.0: 2024/10/22 14:25:51 api_client.go: method='GET', path='/api/v2/firewall/alias?id=18', full uri (derived)='https://xxxxxxx.com/api/v2/firewall/alias?id=18', data='': timestamp="2024-10-22T14:25:51.013+0200"

note the data=''. It seams that the provider always send the data. I think if this parameter is null or empty or we not provide on tf file, the request should not sent the data.

Error: unexpected response code '400': {"code":400,"status":"bad request","response_id":"MODEL_REQUIRES_ID","message":"Field `id` is required.","data":[]}

Maybe the option that sugest Justin-DynamicD in this comment, Adding a few parameters can be a valid solution:

create_include_data   = false
destroy_include_data  = false
read_include_data     = false

@mdepedrof
Copy link

I have solved this error by removing the Content-Type: application/json header. As far as I researched if this header is present, the request always has a json data. If none is provided the json that is sent is {}. In my case, when I removed the header, the request was sent without data and the API worked correctly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants