From dc73960ebcbd4a546fd66fbc07b5a00737286395 Mon Sep 17 00:00:00 2001 From: Michele Cereda Date: Thu, 31 Jul 2025 18:14:00 +0200 Subject: [PATCH] feat(pulumi): add snippet to grab items' attachments from bitwarden password manager --- ...achment from bitwarden password manager.ts | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 snippets/pulumi/get item attachment from bitwarden password manager.ts diff --git a/snippets/pulumi/get item attachment from bitwarden password manager.ts b/snippets/pulumi/get item attachment from bitwarden password manager.ts new file mode 100644 index 0000000..8b4aa5f --- /dev/null +++ b/snippets/pulumi/get item attachment from bitwarden password manager.ts @@ -0,0 +1,54 @@ +import * as pulumi from "@pulumi/pulumi"; +import * as bitwarden from "@pulumi/bitwarden"; + +/* + * Get an Item's attachment from Bitwarden Password Manager + * ----------------- + * Only works for Bitwarden Password Manager, the Secrets Manager offers different resources. + * Refer . + * + * Requirements: + * - `pulumi package add 'terraform-provider' 'maxlaverse/bitwarden'` + * - `export BW_CLIENTID='user.abcdef01-2345-6789-abcd-ef0123456789' \ + * BW_CLIENTSECRET='someBitwardenApiKeySecret' BW_PASSWORD='someBitwardenMasterPassword'` + */ + +/* + * Just looking for it + * ----------------- + */ + +let bitwardenItem: pulumi.Output = bitwarden.getItemLoginOutput({ + search: "Some item in the whole vault", +}); + +/* + * Specifying successive resources + * ----------------- + */ + +const bitwardenOrganization: pulumi.Output = bitwarden.getOrganizationOutput({ + search: "Some organization", +}) +const bitwardenCollection: pulumi.Output = bitwarden.getOrgCollectionOutput({ + organizationId: bitwardenOrganization.apply(org => org.id!), + search: "Some collection in the organization", +}); +bitwardenItem = bitwarden.getItemLoginOutput({ + filterCollectionId: bitwardenCollection.apply(org => org.id!), + search: "Some item in the organization's collection", +}); + +/* + * Use the item's attachment + * ----------------- + */ + +const attachment: pulumi.Output = bitwarden.getAttachmentOutput({ + itemId: bitwardenItem.id!.apply(itemId => itemId!), + id: bitwardenItem.attachments!.apply( + attachments => attachments + .find(attachment => attachment.fileName === "ssh_key.pub")) + .apply(attachment => attachment!.id), +}); +attachment.apply(attachment => console.log(attachment.content));