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

Add support for alternate update and delete path with optional support for token in URL #17

Closed LaurentLesle closed 1 year ago

LaurentLesle commented 1 year ago

Some APIs are not fully RESTfull and require the update_path and delete_path to be different from the path.

During the creation of the object the API will include in the response buffer an attribute than can also be used in the update and delete path

The following example describe a proposed implementation.

the path attribute is used to create the resource. the name_path attribut represent the attribute to retrieve the update_path = "v2/vpns/%s.json" will replace the %s by the name_path

resource "restful_resource" "vpns" {
  provider = restful.provider1

  create_method = "POST"
  update_method = "PUT"

  header = {
    Accept       = "application/json"
    Content-Type = "application/json"
  }

  poll_create = {
    status_locator = "code"
    status = {
      success = "200"
      pending = ["404"]
    }
  }

  poll_delete = {
    status_locator = "code"
    status = {
      success = "404"
      pending = ["202", "200"]
    }
  }

  path        = "v2/resources.json"
  update_path = "v2/resources/%s.json"
  delete_path = "v2/resources/%s.json"
  name_path   = "id"

  body = jsonencode(local.body)

}