Skip to content

Terraform Bitwarden provider to read, create, or update logins, secure notes, folders, org-collections in your Bitwarden & Vaultwarden Vaults

License

Notifications You must be signed in to change notification settings

maxlaverse/terraform-provider-bitwarden

Repository files navigation

Terraform Provider for Bitwarden

Tests Coverage Status Go Version Releases Downloads

A provider for Terraform/OpenTofu to manage Bitwarden Password Manager and Secrets Manager resource. This project is not associated with the Bitwarden project nor Bitwarden, Inc.

Explore the docs on Terraform»    or    Explore the docs on OpenTofu»


Table of Contents

Supported Versions

The plugin has been tested with the following components:

The provider is likely to work with older versions, but those haven't necessarily been tested. If you encounter issues with recent versions of the Bitwarden CLI, consider trying out the Embedded Client.

Usage

The complete documentation for this provider can be found on the Terraform Registry docs.

Bitwarden Secret

terraform {
  required_providers {
    bitwarden = {
      source  = "maxlaverse/bitwarden"
      version = ">= 0.13.6"
    }
  }
}

# Configure the Bitwarden Provider
provider "bitwarden" {
  access_token = "0.client_id.client_secret:dGVzdC1lbmNyeXB0aW9uLWtleQ=="
}

# Source a project
data "bitwarden_project" "example" {
  id = "37a66d6a-96c1-4f04-9a3c-b1fc0135669e"
}

# Create a Secret
resource "bitwarden_secret" "example" {
  project_id = data.bitwarden_project.example.id

  key   = "ACCESS_KEY"
  value = "THIS-VALUE"
}

See the examples directory for more examples.

Password Manager

terraform {
  required_providers {
    bitwarden = {
      source  = "maxlaverse/bitwarden"
      version = ">= 0.13.6"
    }
  }
}

# Configure the Bitwarden Provider
provider "bitwarden" {
  email = "[email protected]"

  # Specify a server URL when using a self-hosted version of Bitwarden
  # or similar (e.g., Vaultwarden), or the European instances:
  #
  # server = "https://vault.bitwarden.eu"

  # If you have the opportunity, you can try out the embedded client which
  # removes the need for a locally installed Bitwarden CLI. Please note that
  # this feature is still considered experimental and not recommended for
  # production use yet.
  #
  # experimental {
  #   embedded_client = true
  # }
}

# Create a Bitwarden Login item
resource "bitwarden_item_login" "example" {
  name     = "Example"
  username = "service-account"
  password = "<sensitive>"
}

# or use an existing Bitwarden resource
data "bitwarden_item_login" "example" {
  search = "Example"
}

See the examples directory for more examples.

Embedded Client

Since version 0.9.0, the provider contains an embedded client that can directly interact with Bitwarden's API, removing the need for a locally installed Bitwarden CLI. The embedded client makes the provider faster, easier to use, but it still requires more testing and feedback. For now, a feature flag needs to be set in order to use it (experimental.embedded_client).

Security Considerations

When not using the Embedded Client, the provider downloads the encrypted Vault locally during plan or apply operations as would the Bitwarden CLI if you used it directly. Currently, the Terraform SDK doesn't offer a way to remove the encrypted Vault once changes have been applied. The issue hashicorp/terraform-plugin-sdk#63 tracks discussions for adding such a feature.

If you want find out more about this file, you can read Terraform's documentation on Data Storage. Please note that this file is stored at <your-project>/.bitwarden/ by default, in order to not interfere with your local Vaults.

Developing the Provider

If you wish to work on the provider, you need the following software:

Mage is a make/rake-like build tool using Go. You can list all available targets by running mage

Building the Provider

To compile the provider, run mage build. You can then instruct Terraform use your compiled version of the provider by running mage setup:install.

Running Tests

The provider includes several types of tests:

  1. Offline Tests: Run tests that don't require a Bitwarden backend (e.g. schema validation, unit tests):

    $ mage test:offline
  2. Integration Tests: There are three types of integration tests:

    a. With the Embedded Client against the official Bitwarden instance. This requires Bitwarden credentials and object identifiers in .env.official file (see .env.official-example):

    $ mage test:integrationPwdOfficialWithEmbeddedClient

    b. With the Embedded Client against a local Vaultwarden instance. First ensure start Vaultwarden locally:

    $ mage vaultwarden

    Then, run the tests:

    $ mage test:integrationPwdVaultwardenWithEmbeddedClient

    c. With the Bitwarden CLI against a local Vaultwarden instance. First ensure start Vaultwarden locally:

    $ mage vaultwarden

    Then, run the tests:

    $ mage test:integrationPwdVaultwardenWithCLI
  3. Run All Tests: To run the complete test suite:

    $ mage test:all

To clean up test artifacts and clear the test cache:

$ mage clean

Documentation

To generate or update documentation, run:

$ mage docs

Disclaimer

While we strive to ensure the reliability and security of this application, we cannot be held liable for any data loss, unauthorized access, or breaches that may result from the way data is stored or processed by third-party providers. This includes, but is not limited to, unencrypted storage of passwords, attachments, and other user information.

Users are strongly encouraged to perform regular backups of their files and database to mitigate potential data loss. In the event of a loss or security concern, please contact us as soon as possible so we can assist where feasible.

License

Distributed under the Mozilla License. See LICENSE for more information.