ryanwholey / terraform-provider-pihole

A Terraform provider for managing Pi-hole resources
https://registry.terraform.io/providers/ryanwholey/pihole/latest/docs
Mozilla Public License 2.0
68 stars 8 forks source link

invalid character 'E' looking for beginning of value #22

Closed TheQueenIsDead closed 2 years ago

TheQueenIsDead commented 2 years ago

Hi there, thanks for creating this module, just the thing I was looking for!

Unfortunately I've encountered the following issue when trying to provision a DNS record. Any help appreciated!

Error


Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
  + create

Terraform will perform the following actions:

  # pihole_dns_record.record will be created
  + resource "pihole_dns_record" "record" {
      + domain = "example.local"
      + id     = (known after apply)
      + ip     = "192.168.0.69"
    }

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

Do you want to perform these actions?
  Terraform will perform the actions described above.
  Only 'yes' will be accepted to approve.

  Enter a value: yes

pihole_dns_record.record: Creating...
╷
│ Error: invalid character 'E' looking for beginning of value
│
│   with pihole_dns_record.record,
│   on main.tf line 10, in resource "pihole_dns_record" "record":
│   10: resource "pihole_dns_record" "record" {
│
╵

Config

My setup looks a little bit like this, running Terraform in WSL

$ terraform version
Terraform v1.1.4
on linux_amd64
+ provider registry.terraform.io/ryanwholey/pihole v0.0.7
resource "pihole_dns_record" "record" {
  domain = "example.local"
  ip     = "192.168.0.69"
}
variable pihole_api_token {
  type = string
  description = "The API token for authenticating with the PiHole API"
}
terraform {
  required_providers {
    pihole = {
      source  = "ryanwholey/pihole"
      version = "0.0.7"
    }
  }
}

provider "pihole" {
  # Configuration options
  url      = "http://pihole.local"
  password = var.pihole_api_token
}
TheQueenIsDead commented 2 years ago

Right, fixed it! This is where I sheepishly admit that I was using an API token retrieved from Settings > API / Web Interface instead of the admin password.

Apologies for the potential waste of time! However, I might have expected the plan and plan-in-apply stage to have failed given it likely did not authenticate properly with the server. Might be worth adding in later down the track? No worries if not, feel free to close the issue.

Thanks again!

ryanwholey commented 2 years ago

Thank you for the issue! I can certainly take a look at this and see what can be done here.

ryanwholey commented 2 years ago

@TheQueenIsDead I was able to reproduce your issue and added some validation on the client initialization with some better error messaging. One of the benefits from erroring in the client init is that Terraform's error tracing now points to the provider and not the resource in the error output! Neat. Anyway, thanks again for submitting! This fix has been released in v0.0.8.

TheQueenIsDead commented 2 years ago

Champion, I appreciate that!

As mentioned, it's completely on me, but I do appreciate the time being taken to allow for easier debugging for the next person that makes my mistake ;-)

Thanks again for the neat provider :+1: