1Password / terraform-provider-onepassword

Use the 1Password Terraform Provider to reference, create, or update items in your 1Password Vaults.
https://developer.1password.com/docs/terraform/
MIT License
322 stars 45 forks source link

For database items hostname is not set because label is server not hostname as the item schema expects #76

Closed monster-cookie closed 4 months ago

monster-cookie commented 1 year ago

Your environment

Terraform Provider Version: 1.1.4 Connect Server Version: 1.10.0 OS: Terraform Cloud so probably Ubuntu Terraform Version: Latest (1.4.2)

What happened?

Hostname for database category items is not set

What did you expect to happen?

Hostname for database items should be set

Steps to reproduce

  1. Create a database item in 1password
  2. Use the data resource for item to access the item
  3. The hostname field will be null instead of the value

Notes & Logs

The problem stems from onepassword\data_source_onepassword_item.go line 211 to 222 specifically line 220

    for _, f := range item.Fields {
        switch f.Purpose {
        case "USERNAME":
            data.Set("username", f.Value)
        case "PASSWORD":
            data.Set("password", f.Value)
        case "NOTES":
            data.Set("note_value", f.Value)
        default:
            if f.Section == nil {
                data.Set(strings.ToLower(f.Label), f.Value)
            }
        }
    }

In the case of database items 1connect sends and id for hostname but the label is set to server they probably should both be server as that makes more sense for a database.

The best work around I could come up with that didn't require a major refactor was to set that section like this.

    for _, f := range item.Fields {
        switch f.Purpose {
        case "USERNAME":
            data.Set("username", f.Value)
        case "PASSWORD":
            data.Set("password", f.Value)
        case "NOTES":
            data.Set("note_value", f.Value)
        default:
            if f.Section == nil {
                if f.Label == "server" {
                    data.Set(strings.ToLower(f.ID), f.Value)
                } else {
                    data.Set(strings.ToLower(f.Label), f.Value)
                }
            }
        }
    }

Basically use ID inste4ad of label for server this gets around the schema validation. Another option would be to solve the naming issue in 1password connect and use hostname or server for both ID and label.

sebastianreloaded commented 12 months ago

it's also not working with the latest version 1.2.0

sebastianreloaded commented 12 months ago

Workaround: rename label "server" to "hostname" or "url"