maxlaverse / terraform-provider-bitwarden

Terraform Bitwarden provider to read, create, or update logins, secure notes, folders, org-collections in your Bitwarden Vaults
https://registry.terraform.io/providers/maxlaverse/bitwarden
Mozilla Public License 2.0
59 stars 9 forks source link

Error: unable to parse result of 'list object' command: unexpected end of JSON input, output: #147

Open yavasura opened 1 month ago

yavasura commented 1 month ago

Hi there,

Short story

Error: unable to parse result of 'list object' command: unexpected end of JSON input, output: │ │ with data.bitwarden_org_collection.bw-org-collection, │ on main.tf line 5, in data "bitwarden_org_collection" "bw-org-collection": │ 5: data "bitwarden_org_collection" "bw-org-collection" { │

Terraform Version

Terraform v1.9.4 on linux_amd64

Affected Resource(s)

Terraform Configuration Files

data "bitwarden_item_login" "login" {
  search = "login.name"
}
data "bitwarden_org_collection" "bw-org-collection" {
  search          = "linux-${lower(replace(var.APP_NAME," ","-"))}-${var.ENVIRONMENT}-vault"
  organization_id = data.bitwarden_organization.bw-organisation.id
}

Expected Behavior

Should succeed to read those data resources as CLI which I copied from export TF_LOG=TRACE works

Actual Behavior

Errors like this:

│ Error: unable to parse result of 'list object' command: unexpected end of JSON input, output: │ │ with data.bitwarden_org_collection.bw-org-collection, │ on main.tf line 5, in data "bitwarden_org_collection" "bw-org-collection": │ 5: data "bitwarden_org_collection" "bw-org-collection" {

maxlaverse commented 1 month ago

Hi @yavasura ! A couple of questions to get this debugging forward:

yavasura commented 1 month ago

Hi @maxlaverse !

It reads organisation and folder it fails to read bitwarden_org_collection and login.

It used to work and it started to fail.

there is no output after Error: unable to parse result of 'list object' command: unexpected end of JSON input, output: ?

│ Error: unable to parse result of 'list object' command: unexpected end of JSON input, output: │ │ with data.bitwarden_org_collection.bw-org-collection, │ on main.tf line 5, in data "bitwarden_org_collection" "bw-org-collection": │ 5: data "bitwarden_org_collection" "bw-org-collection" {

have you tried different search string ? What's actually the search string you're using ?

it used to work, but started to fail. One of the search strings is "proxmox.local"

how are you setting up the provider ?

terraform { required_version = "~> 1.9.3" required_providers { bitwarden = { source = "maxlaverse/bitwarden" version = ">= 0.7.0" } } }

provider "bitwarden" { email = "@gmail.com" master_password = "" }

maxlaverse commented 4 weeks ago

Thanks for the additional information. Could you try with the Bitwarden CLI in version v2023.2.0 ? (the version used in CI, just to be sure). Which version are you using ?

yavasura commented 4 weeks ago

bw --version 2024.3.1

With 2023.2.0 it worked

maxlaverse commented 2 weeks ago

Hi @yavasura! I haven't been able to reproduce yet. Any chance you could help with that ?

Here is the Terraform file I have been using with provider in v0.8.0 + Bitwarden 2024.3.1 & 2024.7.2

terraform {
  required_providers {
    bitwarden = {
      source  = "maxlaverse/bitwarden"
      version = ">= 0.7.0"
    }
  }
}

provider "bitwarden" {
  email           = "test@laverse.net"
  master_password = "test1234"
  server          = "http://127.0.0.1:8080/"
}

data "bitwarden_organization" "bw-organisation" {
  search = "org-174439"
}

data "bitwarden_org_collection" "bw-org-collection" {
  search          = "proxmox.local"
  organization_id = data.bitwarden_organization.bw-organisation.id
}

resource "local_file" "foo" {
  content  = data.bitwarden_org_collection.bw-org-collection.id
  filename = "my_organization_id.txt"
}

The weird thing here is that listing the organization collection doesn't fail, but the output of the command is not JSON (probably empty, if the logs are correct).

Would you know how to compile the provider yourself and would you be willing to do so ? I'm wondering if the CLI outputs anything on stderr, despite the exit code being 0. Else, I could also add an environment variable to output stderr and stdout in the logs, and release a new version. I didn't want to do it by default (using the integrated log level), to reduce the risk of leaking anything private unwillingly. I can check again if there is a better way.

maxlaverse commented 2 weeks ago

Could you retry with TF_LOG=trace and version 0.8.1 @yavasura ? The output of the list command should appear in the logs