cullenmcdermott / terraform-provider-porkbun

Mozilla Public License 2.0
36 stars 8 forks source link

Error: status: 202 message: #64

Open purpleraven opened 8 months ago

purpleraven commented 8 months ago

Last days I see errors in the log during terraform updates

│ Error: Could not retrieve records for xxx.com.
│ 
│   with porkbun_dns_record.xxx-records["res4"],
│   on porkburn.tf line 8, in resource "porkbun_dns_record" "xxx-records":
│    8: resource "porkbun_dns_record" "xxx-records" {
│ 
│ Error: status: 202 message: 
╵

looks like porkbun have updates api and return 202 instaead of 200

purpleraven commented 8 months ago
2024-03-03T10:03:32.271+0100 [ERROR] provider.terraform-provider-porkbun_v0.2.5: Response contains error diagnostic: @module=sdk.proto diagnostic_severity=ERROR tf_proto_version=6.4 tf_provider_addr=registry.terraform.io/cullenmcdermott/porkbun tf_rpc=ReadResource tf_resource_type=porkbun_dns_record @caller=github.com/hashicorp/terraform-plugin-go@v0.19.0/tfprotov6/internal/diag/diagnostics.go:58 diagnostic_detail="Error: status: 202 message: " diagnostic_summary="Could not retrieve records for xxx.com." tf_req_id=b28faf12-4056-556e-6c01-60a3fdc1f506 timestamp="2024-03-03T10:03:32.271+0100"
2024-03-03T10:03:32.271+0100 [ERROR] vertex "porkbun_dns_record.xxx-images-records[\"yyy\"]" error: Could not retrieve records for xxx.com.
purpleraven commented 8 months ago

@cullenmcdermott @parabolala does the plugin mantained? I think porkbun changed the api and returns 202 code insted of 200. The fix should be simple.

cullenmcdermott commented 8 months ago

Hi, yes it is maintained I have not abandoned this. I have not had time to take a look. If the fix seems simple I'd encourage you to submit a PR and I'd be happy to review it.

purpleraven commented 8 months ago

@cullenmcdermott sorry, I'm not a go developer. I have had a look on the code, and I see a usage of client.

Looks like problem happance periodically for my resources, and it not connected with api update.

thats strange.

Maybe it connected with many threads run? terraform apply -parallelism=20

purpleraven commented 8 months ago

the issue can be closed, I'm not using porkbun dns anymore

dezren39 commented 3 months ago

the issue should not be closed, still an issue for those using porkbun. i think 202 means 'accepted, but still processing' or maybe 'valid request, but i cant change things until pending changes occur'. pending changes might mean for that domain, or total number of changes for the account has hit a rate limit, or both, i'm unsure

i just had this issue and now i'm unsure what, if any, changes happened in porkbun and the tfstate didn't get properly updated since it didn't complete.

i think 202 probably would need a long wait and then check if item completed and if not then retry, i think rest requests go into a queue of sorts. i see a maxRetries with a default of 10, but it appears go-retryablehttp only has automatic retries and exponential backoff if the request fails or http range 500. i guess if 202 has the id, then next is to store the id and loop over 'get' until it arrives? or possibly consider a 202 'good'? unclear to me. if 202 doesn't have the id idk what you would do other than loop over get until you see a new record somehow.

this caused me a bunch of manual work to remove all the existing records manually and try again. i can roll out in stages for my next update, but still pretty worried about this process, i think any time this occurs it doesnt record the id for the 202.

edit: setting -parallelism=1, applying up in batches, and using -refresh=false in conjunction has let me get a bunch of changes in. i think if we added a general wait between api calls, especially once 202's hit in, it might help. i worry i'll eventually be unable to plan with -refresh=true at all at some point without updating the provider.

also wrote some scripts to delete all the records from porkbun, remove tainted resources from state.

neither of these is that well-written and they are specific to my uses, but maybe someone will find them helpful. i use sops and nix but neither is too much needed for these scripts. if you replace out the sops part with your keys it ought to work. delete_all_dns_records retrieves all records for the domains in domains.txt, then deletes all matching types used on the main domain and set of subdomains. it could be smarter, retrieve all records and then pass retrieved records into delete commands. but this worked fine after rerunning it a few times and adding some sleeps.