Closed hongkongkiwi closed 3 months ago
@hongkongkiwi This is intentional as once the initial create request succeeded, the resource is recorded in most platforms. But since the polling failed, it makes terraform
mark this resource as "tainted". A tainted resource will be replaced in the next apply, which saves the user's effort to import than delete the resource manually to make the existance check happy.
I may have the wrong approach here, but the problem I'm having is because the item exists in state but is tainted, then terraform tries to delete it upon the next run because it thinks it exists but needs to be recreated which produces a 404.
Normally, a delete command should return a 204 code which indicates success (that's what my delete_poll value is set to).
╷
│ Error: Delete: Polling failure
│
│ Unexpected status "404". Full response: {
│ "code": "NotFound",
│ "message": "The specified entity cannot be found."
│ }
╵
This error makes sense because the object was never created (as create_poll clearly shows).
I could use 404 as a success value for delete_poll to fix this issue? That could work around this (especially with #109 to allow 204 & 404 as success codes).
I guess I had an expectation that failed creates shouldn't even end up in the state, so that upon next run it would try to create again rather than try to delete a non-existent object.
I guess your right the Microsoft API is a bit weird in that it gives a 200 response for an error and you only know it by checking the body, I guess this is an anomaly and not a usual case.
I guess I can work work around it with using delete_poll and success code as 404.
@hongkongkiwi
I may have the wrong approach here, but the problem I'm having is because the item exists in state but is tainted, then terraform tries to delete it upon the next run because it thinks it exists but needs to be recreated which produces a 404.
If you are not suppressing refresh in your apply, then the refresh will do a read first, in which case 404 will cause the provider mark the resource as deleted, and won't do an explicit delete then.
I guess I can work work around it with using delete_poll and success code as 404.
Unfortunately, this isn't something I want to adopt as the poll is a predictable operation, whose successful result also anticipates to be a certain one, instead of multiple.
If you are not suppressing refresh in your apply, then the refresh will do a read first, in which case 404 will cause the provider mark the resource as deleted, and won't do an explicit delete then.
Makes sense. So my workaround for this (for anybody else who finds it) is to do the following, it seems to work well :)
poll_delete = {
status_locator = "code"
status = {
success = "404"
pending = ["204"]
}
}
I've noticed that the state shows that an item was created even if the create_poll fails.
I think it's because the create command actually returns 200, so maybe it's flagged as passed and it's saved into the created state in terraform.
Subsequent runs will actually try to update it since it thinks that the creation was successful (even though the create poll was clearly failed.
Here's my terraform logs:
Here's the log output: