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

What is the expected syntax for date fields? #50

Closed irons closed 7 months ago

irons commented 2 years ago

Your environment

Terraform Provider Version: 1.0.2

Connect Server Version: 1.2.0

OS: macOS 11.6.1

Terraform Version: 1.0.6

What happened?

I've been unable to find acceptable Terraform syntax for creating a date-typed 1Password field. Attempts so far have all resulted in "400 Bad Request" results back from terraform apply. Here are five potential formats that I've tried, along with one string-typed field to show that the date formatting succeeds.

locals {
  date  = "2021-10-29T23:26:27Z"
  vault = "[redacted vault ID]"
}

resource "onepassword_item" "secret-date-metadata" {
  vault    = local.vault
  title    = "Test of date field creation"
  category = "password"
  password = "bibbity bobbity boo plus my birthdate"

  section {
    label = "Dates"

    field {
      type  = "DATE"
      label = "Expiration date as date"

      # All of these potential values result in "400 Bad Request" from terraform apply
      # value = local.date
      # value = formatdate("YYYY/MM/DD", local.date)
      # value = formatdate("MM/DD/YYYY", local.date)
      # value = "2021/10/29"
      value = 1635800957
    }

    field {
      type  = "STRING"
      label = "Expiration date as string"
      value = formatdate("YYYY/MM/DD", local.date)
    }
  }
}

What did you expect to happen?

I expected at least one of those five value-setting lines to set a value without an error. I arrived at the 1635800957 epoch date by looking at how the JSON data came back from the op CLI after setting a date field interactively, but setting it also failed.

Ideally, I'd like to find a date format acceptable to 1Password Connect's Terraform provider that can be emitted by Terraform's formatdate function (epoch date is not on that list).

Steps to reproduce

  1. Plug in a valid vault ID in the locals block, and apply the above file.

Notes & Logs

│ Error: Unable to update item. Receieved "400 Bad Request" for "/v1/vaults/[redacted-vault-ID]/items/l3bwryhvzkf3eyx2aye2xh3nyu"
│ 
│   with onepassword_item.secret-date-metadata,
│   on date-format.tf line 5, in resource "onepassword_item" "secret-date-metadata":
│    5: resource "onepassword_item" "secret-date-metadata" {
bloudraak commented 9 months ago

When I passed in an invalid date format, I noticed the Terraform provider hinted about the format.

Since so many applications use RFC3339 to exchange dates I made a feature request #135 to support it.

volodymyrZotov commented 7 months ago

Currently, the valid format is YYYY-MM-DD. It will print more user-friendly error in this PR #150

See the documentation for the details