cullenmcdermott / terraform-provider-porkbun

Mozilla Public License 2.0
36 stars 8 forks source link

DNS Record Creation is hanging #32

Closed mcat-ee closed 1 year ago

mcat-ee commented 1 year ago

Thanks for developing this provider plugin!

The issue

When I attempt to generate an NS record using the provider, it appears to perpetually hang (alt-tabbing to my terminal, the current attempt to create 4 records is up to Still creating... [8m50s elapsed]

Use case

I'm creating a hosted zone in AWS for a subdomain on an externally-hosted DNS provider, and then attempting to create NS records in Porkbun.

Example Terraform config

terraform {
  required_providers {
    porkbun = {
      source = "cullenmcdermott/porkbun"
      version = "0.2.0"
    }
  }
}

provider "porkbun" {
  api_key = var.porkbun_api_key
  secret_key = var.porkbun_secret_key
}

locals {
  top_level_domain = "example.info" #Replaced with placeholder
  subdomain = "testing" # Replaced with placeholder
  domain_name = "testing.example.info"
}

resource "porkbun_dns_record" "ns_records" {
  domain = local.top_level_domain
  name        = local.subdomain
  type        = "NS"
  content       = "ns-1566.awsdns-03.co.uk"
  notes = "Test case!"
}

variable "porkbun_api_key" {
  description = "The API key for your Porkbun account"
}

variable "porkbun_secret_key" {
  description = "The SECRET key for your Porkbun account"
}

This results in the following plan:

Terraform will perform the following actions:

  # porkbun_dns_record.ns_records will be created
  + resource "porkbun_dns_record" "ns_records" {
      + content = "ns-1566.awsdns-03.co.uk"
      + domain  = "example.info"
      + id      = (known after apply)
      + name    = "testing"
      + notes   = "Test case!"
      + type    = "NS"
    }

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

Expected Result

The NS record is created in <30 seconds

Actual Result

When the plan is applyed, the logs are as follows:

porkbun_dns_record.ns_records: Creating...
porkbun_dns_record.ns_records: Still creating... [10s elapsed]
porkbun_dns_record.ns_records: Still creating... [20s elapsed]
porkbun_dns_record.ns_records: Still creating... [30s elapsed]
porkbun_dns_record.ns_records: Still creating... [40s elapsed]
porkbun_dns_record.ns_records: Still creating... [50s elapsed]
porkbun_dns_record.ns_records: Still creating... [1m0s elapsed]
[snip]
porkbun_dns_record.ns_records: Still creating... [4m30s elapsed]
porkbun_dns_record.ns_records: Still creating... [4m40s elapsed]

Interestingly, using the ctrl+c interrupt at this point raises the message Please wait for Terraform to exit or data loss may occur. Gracefully shutting down.. but the Still creating... logs continue to be printed.

mcat-ee commented 1 year ago

I modified the example to create an A record as follows:

resource "porkbun_dns_record" "ns_records" {
  domain = local.top_level_domain
  name        = local.subdomain
  type        = "A"
  content       = "127.0.0.1"
  notes = "Test case!"
}

This results in the following plan:

  # porkbun_dns_record.ns_records will be created
  + resource "porkbun_dns_record" "ns_records" {
      + content = "127.0.0.1"
      + domain  = "example.info"
      + id      = (known after apply)
      + name    = "testing"
      + notes   = "Test case!"
      + type    = "A"
    }

It appears to have the same result:

porkbun_dns_record.ns_records: Creating...
porkbun_dns_record.ns_records: Still creating... [10s elapsed]
porkbun_dns_record.ns_records: Still creating... [20s elapsed]
porkbun_dns_record.ns_records: Still creating... [30s elapsed]
porkbun_dns_record.ns_records: Still creating... [40s elapsed]
porkbun_dns_record.ns_records: Still creating... [50s elapsed]
mcat-ee commented 1 year ago

These are the DEBUG logs when the interrupt is triggered - it looks like the Provider plugin might be encountering an unhandled EOF from Porkbun?

porkbun_dns_record.ns_records: Still creating... [9m0s elapsed]
^C
Interrupt received.
Please wait for Terraform to exit or data loss may occur.
Gracefully shutting down...

Stopping operation...
2023-03-22T12:05:38.424+1030 [WARN]  terraform: Stop called, initiating interrupt sequence
2023-03-22T12:05:38.424+1030 [WARN]  terraform: run context exists, stopping
2023-03-22T12:05:38.424+1030 [INFO]  terraform: waiting for graceful stop to complete
^C
Two interrupts received. Exiting immediately. Note that data loss may have occurred.

2023-03-22T12:05:42.258+1030 [WARN]  running operation was forcefully canceled
╷
│ Error: operation canceled
│ 
│ 
╵
2023-03-22T12:05:42.262+1030 [ERROR] plugin6.(*GRPCProvider).ApplyResourceChange: error="rpc error: code = Unavailable desc = error reading from server: EOF"
2023-03-22T12:05:42.262+1030 [DEBUG] provider.stdio: received EOF, stopping recv loop: err="rpc error: code = Unavailable desc = error reading from server: EOF"
2023-03-22T12:05:42.264+1030 [DEBUG] provider: plugin process exited: path=.terraform/providers/registry.terraform.io/cullenmcdermott/porkbun/0.2.0/darwin_arm64/terraform-provider-porkbun_v0.2.0 pid=20671
2023-03-22T12:05:42.264+1030 [DEBUG] provider: plugin exited
cullenmcdermott commented 1 year ago

Thanks for the report and the details. I have been busy with some other stuff so I haven't had a chance to look into this yet but I will try to soon!

woile commented 1 year ago

I'm facing a similar issue, has any of you find a way to solve it? Thanks by this library btw, I was not aware I could control the DNS with terraform 🚀

parabolala commented 1 year ago

I have also encountered similar behavior and in my case it was caused by the domain name not "Enabled for API access".

I have also submitted a PR to fix error handling by surfacing the error immediately instead of hanging forever. If enabling the domain for API access doesn't help you, you can preview the fix by following the terraform provider development overrides to point your terraform at the binary built from the PR branch.

cullenmcdermott commented 1 year ago

v0.2.1 is available on the registry (thank you @parabolala). If this doesn't fix the original issue then please reach back out on this or a new issue with TF_LOG=debug set and logs attached and I'll take look (and not forget about it this time 😄 )