Closed nathaclmpaulino closed 2 weeks ago
Hey @nathaclmpaulino! 👋🏻
There is already a field that contains the vault identifier: it's named uuid
. It's mentioned in the onepassword_vault
Data Source schema:
uuid (String) The UUID of the vault to retrieve. This field will be populated with the UUID of the vault if the vault it looked up by its name.
So your snippet would look like this with the appropriate vault identifier:
data "onepassword_vault" "vault" {
name = "my-vault"
}
resource "onepassword_item" "item" {
vault = data.onepassword_vault.vault.uuid
...
}
Does this address the use case you're trying to achieve?
Yes! This works for my use case! Sorry to open this feature request issue! I'll closed it now!
Just one question though, do you have plans to add a onepassword_vault
as a resource in the provider?
Summary
Create a new read-only attribute on the onepassword_vault datasource to be able to get only the
vault_id
instead of theid
which is the Terraform Resource Identifier associated to it.Use cases
The most common use case for datasources in Terraform is to have access to a specific attribute in a resource which is not mapped in your Terraform code. Since we don't have a resource that creates a 1Password Vault for us, the only way to get the ID to create an onepassword_item resource in Terraform is using the datasource. In a terraform context, the code will be similiar this:
But doing this will throw an error:
Proposed solution
The proposed solution is to create a new read-only attribute on the onepassword_vault datasource named
vault_id
which will change the snippet above to be like this:And that will not trigger an error.
Is there a workaround to accomplish this today?
Accordingly to the datasource docs, the id value is in the format
vaults/<vault_id>
, so to avoid the previous error today on Terraform code, we can have something like this: