Mastercard / terraform-provider-restapi

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

Use IDs provided as URLs #222

Open stephenpaulger opened 1 year ago

stephenpaulger commented 1 year ago

See also #205

This PR solves two issues I've experienced.

This change

I have included a unit test for function that extracts the ID from a URL but not for the redirection functionality, if you have advice on how to implement that test I'm happy to try to add one.

DRuggeri commented 7 months ago

Thanks, @stephenpaulger - I like this idea quite a bit! Great PR

I'm curious about the implementation, though. The provider expects an object that gets created to be at a predictable path that can be queried for state (read_path). I don't think this prevents that from working, but I sense a limitation in that the Location header and format may be API-specific to know the proper way to parse it. Would it be reasonable to assume that the Location header points us to something that ought to look exactly like the read_path? If so, we could then parse read_path as something of a "template" to know where in the header's value the ID can be found.

The more I think about it, the more I lean toward the direction that an API should probably provide a 202 and Location to the read_path... but I don't know what I don't know regarding the specific API you're working on :-)

rpersee commented 1 week ago

I'm facing the same issue with an API that also returns the created resource path in the "Location" header. I've rebased this PR to solve the conflicts: https://github.com/rpersee/terraform-provider-restapi/tree/id-as-url @stephenpaulger maybe you could update your PR with this fork? Would these changes be accepted @DRuggeri ?