Mastercard / terraform-provider-restapi

A terraform provider to manage objects in a RESTful API
Other
785 stars 215 forks source link

"POST" not working as destroy method #233

Closed acteru closed 8 months ago

acteru commented 11 months ago

Hi,

Currently trying to trigger Ansible-Tower(AAP) Job templates via this module, the creation part works great, but the objects are not destroyed.

Context for the API-call: https://docs.ansible.com/ansible-tower/3.2.6/html/towerapi/launch_jobtemplate.html

The idea is to trigger the job with certain parameters send via json_data (in this case via extra_vars) to trigger the job via terraform apply. In the data field, there is an “add” and “remove” parameter to tell tower what to do when launching the job.

The structure of Ansible-Tower forces me to send this to destroy:

destroy_method = "POST"
destroy_path = "/api/v2/job_templates/2688/launch"
destroy_data = "{ \"extra_vars\": {\"task\": \"remove\"}}"

My expectation here was that, the task is simply triggers again when “destroy” runs with the different json_data field, but I only get: “No changes. No object need to be destroyed”.

So I am not sure if it is not intended from this provider to allow "POST" to destroy or if I am doing it wrong? Regarding the “ID” the response is the “running job id” but I can't use this ID anymore because the new call will spawn another job to remove the resource, so the guess was to overwrite "destroy_path" but it did not seam to matter.

So I hope you, have some inside or ideas to get around this issue?

kladiv commented 8 months ago

Hi @acteru, did you tested with path below? (according to Tower API reference)

  destroy_path = "/api/v2/job_templates/2688/launch/"

trailing slash: forward slash (“/”) placed at the end of a URL

I used restapi provider for some tests on Ansible AWX and i always override restapi paths using trailing slash

acteru commented 8 months ago

Hi @kladiv, Thanks for your response, not sure if I tested the path like this back in August — I already moved on and found another solution.