Getting started with 1Password for your growing team, or refining your setup? Our Secured Success quickstart guide is for you.
Forum Discussion
mike99
2 years agoOccasional Contributor
"Correct" way to read custom fields in ```onepassword_item``` data source
Hi,
We're looking at migrating from HashiCorp Vault to 1Password as a secret provider for our terraform projects.
At present we have something like this:
```
provider "vault" {
address...
jerdew
2 years agoNew Contributor
I found this issue comment helpful: https://github.com/1Password/terraform-provider-onepassword/issues/117#issuecomment-2059385999
and ended up with
```
data "onepassword_item" "terraform" {
vault = "MyVault"
title = "MyTerraformItem"
}
locals {
op_terraform_fields = { for f in data.onepassword_item.terraform.section[0].field : f.label => {
id = f.id
purpose = f.purpose
type = f.type
value = f.value
}
}
# accessed like so: local.op_terraform_sections["Did You Get"].fields["that thing I sent you"].value
op_terraform_sections = { for s in data.onepassword_item.terraform.section : s.label => {
id = s.id
fields = { for f in s.field : f.label => {
id = f.id
purpose = f.purpose
type = f.type
value = f.value
} }
} if s.label != "" }
}
```
and then the 'fields' one is the sectionless section found at [0], and used by me as
provider "aws" {
region = "us-east-1"
access_key = local.op_terraform_fields["ACCESS_KEY"].value
secret_key = local.op_terraform_fields["SECRET_ACCESS_KEY"].value
}