timohirt / terraform-provider-hetznerdns

Terraform provider for Hetzner DNS
Mozilla Public License 2.0
109 stars 21 forks source link

Environment variable is not recognized #3

Closed timbrd closed 4 years ago

timbrd commented 4 years ago

Hi,

I'm trying to set some dns records, which works well when being asked for my API Token by terraform, but I always get a 401 error when using the HETZNER_DNS_API_TOKEN environment variable.

module.worker.hetznerdns_record.dns-a[2]: Creating...
module.worker.hetznerdns_record.dns-a[0]: Creating...

Error: Error creating DNS record api.os: Error creating Record. HTTP status 401 unhandled

  on dns.tf line 91, in resource "hetznerdns_record" "dns_a_api":
  91: resource "hetznerdns_record" "dns_a_api" {

Error: Error creating DNS record api-int.os: Error creating Record. HTTP status 401 unhandled

  on dns.tf line 101, in resource "hetznerdns_record" "dns_a_api_int":
 101: resource "hetznerdns_record" "dns_a_api_int" {

Error: Error creating DNS record apps.os: Error creating Record. HTTP status 401 unhandled

  on dns.tf line 111, in resource "hetznerdns_record" "dns_a_apps":
 111: resource "hetznerdns_record" "dns_a_apps" {

Any idea why the error occurs? How am I supposed to debug the problem?

Thanks, Tim

timohirt commented 4 years ago

Hey @timbrd! Thanks for reporting.

I think that HTTP 401 means there is something wrong with the API token. Probably a copy and paste error? I could only reproduce by using an invalid token (removed the last char of the API token).

However, I agree the error message is not useful. Will change this in the next version.

timohirt commented 4 years ago

I added a handler for 401 unauthorized errors. Now, you can see the message from the API why your request was rejected. I hope this helps.

Error: Error getting zone state. Error getting zone example.com: API return 401 Unauthorized with message: 'Invalid authentication credentials'. Double check your API key is still valid

  on .terraform/modules/server/main.tf line 7, in data "hetznerdns_zone" "dns_zone":
   7: data "hetznerdns_zone" "dns_zone" {
timohirt commented 4 years ago

See release https://github.com/timohirt/terraform-provider-hetznerdns/releases/tag/v1.0.2