anasinnyk/terraform-provider-onepassword

Support Upsert

Closed this issue ยท 7 comments

Hi,

I'm trying to use your Provider which is working great. One thing I am not able to understand how to use ( or maybe is not supported? ) is how to upsert an existing entry.

Looks at this TF code example:

data "onepassword_vault" "test" {
  name = "test vault"
}

data "onepassword_item_login" "test" {
  name = "test-item"
  vault = "${data.onepassword_vault.test.id}"
}

resource "onepassword_item_login" "test" {
  name = "${data.onepassword_item_login.test.name}"
  vault = "${data.onepassword_item_login.test.vault}"

  url = "http://test.com"
}

Expected:
The existing entry is updated into the URL field

Actually:
The entry is created with the same identical name in the same vault.

Any help on this is highly appreciated :)

Thank you in advance!

Sorry for the late answer. It's an expected situation. That's because of op CLI tool not supported update operation. OP CLI - https://1password.com/downloads/command-line/

Discussion on 1Password forum https://discussions.agilebits.com/discussion/84324/cli-delete-update-logins

Thank you for the reply. I was not aware the tool behind is lacking it. I'll try to be pushy there in order to see if we can get something out of it.

Meanwhile do you think it would be difficult for you to provide an argument like update = true which would load all the data out of the item, delete it and create it again with that data + the new ones given in Terraform?

@julianxhokaxhiu I think it's not possible because I use the id in terraform state.
But for your case, we can use terraform import (this provider support it). And after import, we can edit an item and it proposes to recreate it.

https://www.terraform.io/docs/import/

try do next steps:

  1. declare resource
data "onepassword_vault" "test" {
  name = "test vault"
}

resource "onepassword_item_login" "test" {
  name = "test-item"
  vault = "${data.onepassword_item_login.test.vault}"

  url = "http://test.com"
}
  1. run terraform import onepassword_item_login.test test-item
  2. run terraform apply - should propose recreate item.

I'll try and let you know.

@julianxhokaxhiu I think all works fine. Thank for your interesting to the project. I closed this issue.

As I'm using this at work and not for a personal project, I didn't had a chance to try it yet. But I'll let you know how it goes and in case we can re-open the issue if needed.

Thank you in advance and sorry again.