Skip to content
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

409 Conflict - Error when creating hetznerdns_records #5

Closed
rowa78 opened this issue Jul 6, 2020 · 5 comments
Closed

409 Conflict - Error when creating hetznerdns_records #5

rowa78 opened this issue Jul 6, 2020 · 5 comments
Assignees
Labels
bug Something isn't working

Comments

@rowa78
Copy link

rowa78 commented Jul 6, 2020

I have a terraform resource which should create a dns-record entry for each server I created before:

resource "hetznerdns_record" "ipv4" {
    count = 2
    zone_id = var.dns_zone_id
    name = hcloud_server.rancher[count.index].name
    value = hcloud_server.rancher[count.index].ipv4_address
    type = "A"
    ttl= 60
}

When applying this resource, the following error occurs:

Terraform will perform the following actions:

  # hetznerdns_record.ipv4[0] will be created
  + resource "hetznerdns_record" "ipv4" {
      + id      = (known after apply)
      + name    = "rancher0"
      + ttl     = 60
      + type    = "A"
      + value   = "78.47.182.191"
      + zone_id = "tE8hyXXXXXXX"
    }

  # hetznerdns_record.ipv4[1] will be created
  + resource "hetznerdns_record" "ipv4" {
      + id      = (known after apply)
      + name    = "rancher1"
      + ttl     = 60
      + type    = "A"
      + value   = "116.203.123.223"
      + zone_id = "tE8hyXXXXXXX"
    }

Plan: 2 to add, 0 to change, 0 to destroy.

Output:

hetznerdns_record.ipv4[0]: Creating...
hetznerdns_record.ipv4[1]: Creating...
hetznerdns_record.ipv4[1]: Creation complete after 1s [id=49c28c994e600ecec10e76493ea44727]

Error: Error creating DNS record rancher0: Error creating record rancher0: API returned HTTP 422 Unprocessable Entity error with message: '**409 Conflict:** '

  on dns.tf line 1, in resource "hetznerdns_record" "ipv4":
   1: resource "hetznerdns_record" "ipv4" { 

The error occurs, but the 2 records are created in Hetzner-dns:

Bildschirmfoto 2020-07-06 um 22 26 18

Do I make a mistake while creating these resources or is there a bug? How can this error be avoided?

Debug-Output at Loglevel DEBUG:

hetznerdns_record.ipv4[1]: Creating...
hetznerdns_record.ipv4[0]: Creating...
2020/07/06 22:33:21 [DEBUG] hetznerdns_record.ipv4[1]: applying the planned Create change
2020/07/06 22:33:21 [DEBUG] hetznerdns_record.ipv4[0]: applying the planned Create change
2020-07-06T22:33:21.762+0200 [DEBUG] plugin.terraform-provider-hetznerdns: 2020/07/06 22:33:21 [DEBUG] Updaing resource record
2020-07-06T22:33:21.762+0200 [DEBUG] plugin.terraform-provider-hetznerdns: 2020/07/06 22:33:21 [DEBUG] HTTP request to API POST https://dns.hetzner.com/api/v1/records
2020-07-06T22:33:21.762+0200 [DEBUG] plugin.terraform-provider-hetznerdns: 2020/07/06 22:33:21 [DEBUG] Updaing resource record
2020-07-06T22:33:21.762+0200 [DEBUG] plugin.terraform-provider-hetznerdns: 2020/07/06 22:33:21 [DEBUG] HTTP request to API POST https://dns.hetzner.com/api/v1/records
2020-07-06T22:33:22.253+0200 [DEBUG] plugin.terraform-provider-hetznerdns: 2020/07/06 22:33:22 [DEBUG] 422 Unprocessable Entity error response body: {"record":{"id":"","type":"","name":"","value":"","zone_id":"","created":"","modified":""},"error":{"message":"409 Conflict: ","code":422}}
2020-07-06T22:33:22.253+0200 [DEBUG] plugin.terraform-provider-hetznerdns: 2020/07/06 22:33:22 [ERROR] Error Creating DNs record rancher1: Error creating record rancher1: API returned HTTP 422 Unprocessable Entity error with message: '409 Conflict: '
2020/07/06 22:33:22 [DEBUG] hetznerdns_record.ipv4[1]: apply errored, but we're indicating that via the Error pointer rather than returning it: Error creating DNS record rancher1: Error creating record rancher1: API returned HTTP 422 Unprocessable Entity error with message: '409 Conflict: '
2020/07/06 22:33:22 [ERROR] <root>: eval: *terraform.EvalApplyPost, err: Error creating DNS record rancher1: Error creating record rancher1: API returned HTTP 422 Unprocessable Entity error with message: '409 Conflict: '
2020/07/06 22:33:22 [ERROR] <root>: eval: *terraform.EvalSequence, err: Error creating DNS record rancher1: Error creating record rancher1: API returned HTTP 422 Unprocessable Entity error with message: '409 Conflict: '
2020-07-06T22:33:22.839+0200 [DEBUG] plugin.terraform-provider-hetznerdns: 2020/07/06 22:33:22 [DEBUG] Reading resource record
2020-07-06T22:33:22.839+0200 [DEBUG] plugin.terraform-provider-hetznerdns: 2020/07/06 22:33:22 [DEBUG] HTTP request to API GET https://dns.hetzner.com/api/v1/records/97b81d00629ef17ab64f1d7542ff8d1d
hetznerdns_record.ipv4[0]: Creation complete after 1s [id=97b81d00629ef17ab64f1d7542ff8d1d]

Error: Error creating DNS record rancher1: Error creating record rancher1: API returned HTTP 422 Unprocessable Entity error with message: '409 Conflict: '

  on dns.tf line 1, in resource "hetznerdns_record" "ipv4":
   1: resource "hetznerdns_record" "ipv4" {


2020-07-06T22:33:22.938+0200 [DEBUG] plugin: plugin process exited: path=/Users/ronny/dev/terraform/rancher/terraform/.terraform/plugins/darwin_amd64/terraform-provider-hetznerdns pid=26105
@timohirt timohirt self-assigned this Jul 10, 2020
@timohirt
Copy link
Owner

Thank you for reporting @atlan78. The information you provided was very helpful :-). I was able to reproduce and can confirm it's a bug. I'll look into it in the next couple of days.

@timohirt timohirt added the bug Something isn't working label Jul 10, 2020
@timohirt
Copy link
Owner

Can be reproduced with the following resources.

data "hetznerdns_zone" "z1" {
    name = "z1.de"
}

resource "hetznerdns_record" "www" {
    zone_id = data.hetznerdns_zone.z1.id
    name = "test0"
    value = "192.168.1.1"
    type = "A"
    ttl= 60
}

resource "hetznerdns_record" "www2" {
    zone_id = data.hetznerdns_zone.z1.id
    name = "test1"
    value = "192.168.1.22"
    type = "A"
    ttl= 60
}

The first record is created, for the second the API returns a 422 Unprocessable Entity. When applied twice, everything works fine.

@rowa78
Copy link
Author

rowa78 commented Jul 14, 2020

Wow, you are fast. I'll test it soon.

@timohirt
Copy link
Owner

Turned out that the Hetzner API doesn't like creating more than one DNS record at a time. To be fair, there is a bulk create API endpoint which could be used to support this, but I decided to synchronize the API calls in code for now. This will slow down CRUD of DNS records. I hope there are not too many in your project.

Release v1.0.4 fixes this issue.

@rowa78
Copy link
Author

rowa78 commented Jul 14, 2020

Works perfectly now. Now i can set all the 'A' and 'AAAA' records for all of my k8s-nodes.

hetznerdns_record.ipv4_k8s["1"]: Creation complete after 2s [id=eb1b8529a32f10e348453dbbe0a6fedb] hetznerdns_record.ipv4_k8s["2"]: Creation complete after 5s [id=3cb598d5eac6cda16786e74c5b5af05d] hetznerdns_record.ipv4_k8s["3"]: Creation complete after 5s [id=f3897153441a951282bbbc7340ba38e6] hetznerdns_record.ipv6_k8s["2"]: Creation complete after 5s [id=7a2d43f3c631cdb103ce89df6169fbf0] hetznerdns_record.ipv6_rancher: Creation complete after 5s [id=5abf8b050147a6aad360ec4d31a9ca7c] hetznerdns_record.ipv6_k8s["1"]: Creation complete after 5s [id=e21223c8fa549a7f0741894ffc423b87] hetznerdns_record.ipv6_k8s["3"]: Creation complete after 5s [id=7c001b158ffca8f4c7ba20f699479e80]

Great Work!

timohirt added a commit that referenced this issue Jul 16, 2020
See Issue #5 for context. Serialized all requests to the API, but only
PUT and POST requests cause the issue.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants