-
Notifications
You must be signed in to change notification settings - Fork 220
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
Extracting id from URI using id_attribute #205
Comments
Hi, @blairnangle - good question. I think your inclination is correct: interpolation of the variables is happening in an unexpected order. The provider is doing its own interpolation because of how flexible the location of the URI must be. The downside to this is that the interpolation happens at the very last second just before the request is submitted. I do think some sort of native terraform solution would be a nice silver bullet. I'm not aware of something that says, "get the value of attribute |
Hey @DRuggeri, thank you for the reply! Yeah, I guess the issue kind of comes down to the HATEOAS-inspired implementation of the Calendly API where the client is always expected to be passing around URIs. However, I have also tried setting the resource "restapi_object" "event_created_or_canceled" {
provider = restapi
path = ""
create_method = "POST"
data = templatefile("${path.module}/templates/webhook.json", {
backend_url = var.backend_url
}
)
read_path = "{id}"
} Assuming that Perhaps |
I am having a similar issue right now. On creating an object the API returns the item without an ID in the fields but there is a url for the object that contains the ID with a "_meta" dict. I could set I think I can see how this could be done with a modification to the provider with restapi/api_object.go whenever the ID is read it could be parsed as a URL, either with some clever logic that works if it looks like a URL or with an additional field that tells it that the id attribute is in URL form. I think I could probably make that change. |
@blairnangle I've created a PR that might fix the issue you were having. #222 |
For context, I am working with the Calendly Webhook API.
I can create a webhook fine the first time, but subsequent retries result in a "webhook subscription already exists"-type error originating from Calendly's API, rather than a "remote state is as expected, resource already exists"-type message from Terraform.
This is because the successful response from Calendly is of the form:
So I can use the
id_attribute
field to extract the id ashttps://api.calendly.com/webhook_subscriptions/AAAAAAAAAAAAAAAA
withresource/uri
. But this means that my id is a URI, notAAAAAAAAAAAAAAAA
which the provider needs to use to interact correctly with Calendly's read and update APIs (theGET
andPUT
Calendly APIs expect the calls of the formhttps://api.calendly.com/webhook_subscriptions/AAAAAAAAAAAAAAAA
.Is there a known way to use
id_attribute
with some native Terraform functions to extract and set an id from a response where the value of the target field is a URI (or any other string that requires some work)?My first attempt was to try overriding
read_path
on therestapi_object
:But this just results:
I guess the provider string interpolation is happening in the wrong order with respect to the native Terraform code.
Just wondering if this is a solved problem or a limitation of the provider. Thanks in advance!
The text was updated successfully, but these errors were encountered: