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
60 stars 9 forks source link

Terraform plan/refresh produces "Not found" errors #63

Closed maxlaverse closed 1 year ago

maxlaverse commented 1 year ago

Issue created out of https://github.com/maxlaverse/terraform-provider-bitwarden/issues/61, reported by @leynebe

Terraform Version

$ terraform -v
Terraform v1.3.7
on linux_amd64

Affected Resource(s)

Terraform Configuration Files

resource "bitwarden_item_login" "app" {
  name            = "${local.bw_item_prefix}-app"
  username        = local.APP_USER
  password        = local.APP_PASSWORD
  organization_id = local.bw_organization_id
  notes           = local.bw_notes
  favorite        = false
  collection_ids  = [local.bw_collection_app]

  uri {
    value = local.domain
  }

  dynamic "field" {
    for_each = local.bw_fields
    content {
      name = field.key
      text = field.value
    }
  }

  field {
    name = "service"
    text = "app"
  }
}

Debug Output

No debug output yet

Panic Output

No panic output

Expected Behavior

Items should have been refreshed during planning

Actual Behavior

Errors with 404s not found 216559774-aef38898-bed5-411a-919b-aab3762f8d17

Steps to Reproduce

Issue happen to @leynebe

This might warrant its own ticket but I'm also occasionally encountering a failure in tf refresh of login items when applying (after a failed apply)

It happened to me as well after removing the local Vault

Important Factoids

Are there anything atypical about your accounts that we should know? For example: Running in EC2 Classic? Custom version of OpenStack? Tight ACLs?

References

Are there any other GitHub issues (open or closed) or Pull Requests that should be linked here? For example:

maxlaverse commented 1 year ago

I realized this error is not supposed to happen, as we translate this specific Not found. output into an object not found error: https://github.com/maxlaverse/terraform-provider-bitwarden/blob/6ce0c3f9f83faf9357acc4e3860d01f5f3bf0ec0/internal/bitwarden/bw/client.go#L153-L155

I'm thinking this could be the non-thread safe bytes.Buffer messing up with the output, which would eventually not match what we're looking for: https://github.com/maxlaverse/terraform-provider-bitwarden/blob/6ce0c3f9f83faf9357acc4e3860d01f5f3bf0ec0/internal/command/cmd.go#L61-L73

I'll try to simplify this method and see if the problem occurs again

maxlaverse commented 1 year ago

Couldn't reproduce. I'll assume it fix but we can re-open it if necessary