-
Notifications
You must be signed in to change notification settings - Fork 51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Complex examples needed #72
Comments
Hi Pascal, Now, to your specific issue: I'll have to admit that my Terraform chops are very rough, so my response may not be the most efficient way forward, but I've also reached out to the Secrets Automation developer team to see if they have better suggestions. I also hope I understand your question correctly. It sounds to me as if you'd like to retrieve a specific value from a custom field nested in a section. Is that about right? If so, here's what worked for me, given the following. resource "onepassword_item" "demo_sections" {
vault = var.demo_vault
title = "Demo Terraform Item with Sections"
category = "login"
username = "test@example.com"
section {
label = "Terraform_Section"
field {
label = "API_KEY"
type = "CONCEALED"
value = "Gr34tP4$$word"
}
field {
label = "HOSTNAME"
value = "example.com"
}
}
section {
label = "Terraform Second Section"
field {
label = "App Specific Password"
type = "CONCEALED"
password_recipe {
length = 40
symbols = false
}
}
field {
label = "User"
value = "demo"
}
}
} And a corresponding data block as follows: data "onepassword_item" "get_pass_example" {
vault = var.demo_vault
uuid = onepassword_item.demo_sections.uuid
} Now I just tested this in data.onepassword_item.get_pass_example.section[index(data.onepassword_item.get_pass_example.section.*.label, "Terraform_Section")].field[0].value That returns Now I notice that you are asking for a specific key, rather than values.... if that is actually the case, then you could get an array of keys for the keys(data.onepassword_item.get_pass_example.section[index(data.onepassword_item.get_pass_example.section.*.label, "Terraform_Section")].field[0]) and a specific key from that array with standard index subscripting on the output from the keys(data.onepassword_item.get_pass_example.section[index(data.onepassword_item.get_pass_example.section.*.label, "Terraform_Section")].field[0])[0] Now as I said, I'm no Terraform expert myself, so this may be a roundabout way of getting to your destination. I'll pass along any additional suggestions from our developers when available. But hopefully this is a start. And again, thank you for your suggestions for improving our documentation. |
Hi Pascal, Alas, one of our devs correctly understood your request and provided the following. The syntax to retrieve the value of the secret is nearly similar to my first value-retrieval syntax but is nested in a more useful Here’s an example terraform file that gets from an item the value of the field terraform {
required_providers {
onepassword = {
source = "1Password/onepassword"
version = "~> 1.1.4"
}
}
}
provider "onepassword" {
url = "http://localhost:8000/"
}
data "onepassword_item" "example" {
vault = "ar3v2gmnw73p4bhkphr7t6rv44"
uuid = "257ueonb6vek5fg4uwzl2qc73y"
}
output "custom_field" {
value = data.onepassword_item.example.section[index(data.onepassword_item.example.section.*.label, "off")].field[index(data.onepassword_item.example.section[index(data.onepassword_item.example.section.*.label, "off")].field.*.label, "title")].value
} There may be a slightly less syntactically-verbose way to drill down into that field but this was what we were able to make work most reliably. I hope that helps you out a bit! We'll also file an issue with our docs team to explore options for improving our terraform documentation with respect to this type of task. |
Hi Scott, Your reply helped a lot, thanks! I did something like this:
│ Error: Error in function call
|
Heey @pascalrobert, Glad to see that the suggested snippet that we've suggested worked for you and you even went beyond and made it friendlier. I really appreciate it and we should document such example in the repo as well. Also, I appreciate that you've identified some scenarios in which the provider doesn't work as expected. I will raise them with my team and try to look into them. We will keep you posted when we have new insight for you regarding these. |
Thanks for this, I was looking for an example of how to use a custom section.
|
Hello, After update to 1.2.0 this no longer works:
It does create the "XXX Data" section, but without any data in it. |
And the fix has been pushed with the 1.2.1 release. So you should be able to create fields within a section again @Scholdan. 😄 |
@pascalrobert @scottisloud, thank you for providing your examples! I decided to show how I adapted it for my needs. Below is an example of how to retrieve specific data from item.
|
@mrkhachaturov thank you for the nudge. using a map can improve readability.
|
We need more complex examples. For example, how to fetch an key from an item? I tried something like this:
data "onepassword_item" "secrets" {
vault = data.onepassword_vault.aw.uuid
title = "secrets"
}
data.onepassword_item.secrets.section[index(data.onepassword_item.secrets.section.*.label, "my-label")]
Didn't work. Also tried with:
data.onepassword_item.secrets.section[index(data.onepassword_item.secrets.section.*.field.label, "my-label")]
Didn't work either. So what's the correct way to get one key out of an item?
The text was updated successfully, but these errors were encountered: