1Password / terraform-provider-onepassword

Use the 1Password Terraform Provider to reference, create, or update items in your 1Password Vaults.
https://1password.com/secrets
MIT License
323 stars 44 forks source link

Allow creating entries with multi-line strings #163

Open toadjaune opened 5 months ago

toadjaune commented 5 months ago

Summary

Currently, when creating a value in a custom field, line breaks get turned into spaces, although 1Password does support having values spanning several lines with text field type.

Use cases

Basically, I'd like to do something along the lines of :

resource "onepassword_item" "example" {
  vault = "<some_vault_id>"
  title    = "Example"
  category = "login"
  section {
    label = "Custom section"
    field {
      label = "multi-line string"
      type  = "STRING"
      value = <<-EOT
        line1
        line2
      EOT
    }
  }
}

This results in the following entry : image

When attempting to manually edit the resulting entry, I can't transform it into a multi-line string. However, if I add a new field of type "text", I can enter multi-line values : image

This leads me to believe that the underlying 1Password data model has two types of strings, one allowing multi-line values, the other not.

If that's the case, however, this is not exposed to terraform, as importing the entry after this manual addition yields this state :

resource "onepassword_item" "example" {
    [...]
    section {
        id    = "6d78330e-cf14-a8ab-44d7-d8d2e244e91e"
        label = "Custom section"
        field {
            id      = "iv33n3zfkfcnhrydqvnfruf3jm"
            label   = "multi-line string"
            purpose = null
            type    = "STRING"
            value   = (sensitive value)
        }
        field {
            id      = "h3ehk63snul76a6raioe637w4a"
            label   = "manual text"
            purpose = null
            type    = "STRING"
            value   = (sensitive value)
        }
    }
}

As you can see, terraform doesn't see the type difference between those two values.

Also, attempting to enter anything else as type (for example, TEXT), yields the following error : Error: expected section.0.field.5.type to be one of [STRING EMAIL CONCEALED URL OTP DATE MONTH_YEAR MENU], got TEXT

I haven't attempted to manipulate those entries directly from the 1Password CLI, to see if the problem is exclusively in the terraform provider, or in the underlying CLI.

Proposed solution

I'm assuming that those two strings are indeed different types in the 1Password data model, if that's not the case, those suggestions break apart :

  1. (ideal) : Expose both types to the CLI and terraform provider
  2. Make terraform switch its STRING type to using the underlying type allowing multi-line strings.

Is there a workaround to accomplish this today?

Not that I know of. It's still possible to create entries with multi-line strings, the line breaks will just get mangled.

References & Prior Work