Terraform Provider for KSM

Keeper Secrets Manager Terraform provider for interacting with vault secrets in Terraform builds

Features

The Keeper Terraform Plugin utilizes Keeper Secrets Manager to provide access to secret credentials saved in the Keeper Vault. The Keeper Terraform plugin allows for injecting secrets directly into Terraform builds securely using Keeper's zero-knowledge infrastructure.

  • Retrieve secrets from the Keeper Vault to use in Terraform builds

  • Inject credentials directly into Terraform build scripts

  • Create new secrets and store them in the vault

  • Get Files from the Keeper Vault

circle-info

For a complete list of Keeper Secrets Manager features see the Overview

Prerequisites

This page documents the Secrets Manager Terraform integration. In order to utilize this integration, you will need:

  • Keeper Secrets Manager access (See the Quick Start Guide for more details)

    • Secrets Manager add-on enabled for your Keeper account

    • Membership in a Role with the Secrets Manager enforcement policy enabled

  • A Keeper Secrets Manager Application with secrets shared to it

  • An initialized Keeper Secrets Manager Configuration

    • The Terraform integration accepts JSON and Base 64 format configurations

Installation

Registry install

circle-info

The Keeper Secrets Manager provider page is located herearrow-up-right

To install this provider, add the following code to your Terraform configuration and run terraform init:

Find the source code in the GitHub repositoryarrow-up-right

Manual Installation

Download the latest version of the Terraform Provider for your platform from our GitHub releasearrow-up-right page and copy the archive to the corresponding Terraform plugin folder (creating any missing folders in the path). Initialize source with full provider URL: source = "github.com/keeper-security/secretsmanager"

circle-info

Use the archive matching your OS and CPU architecture (amd64 or arm64). The Mac OS and Linux commands below detect architecture automatically. Windows command shown is for amd64.

For help on manually installing Terraform Providers, please refer to the official Terraform documentationarrow-up-right.

Usage

Configure the Provider

The Keeper Secrets Managerarrow-up-right provider is used to interact with the resources supported by Keeper Secrets Manager. The provider needs to be configured with Keeper credentials before it can be used.

circle-info

For CI/CD environments, you can omit the credential attribute entirely and set the KEEPER_CREDENTIAL environment variable instead:

Configuration File Contents

  • appKey - (Required) Application key.

  • clientId - (Required) Client ID.

  • privateKey - (Required) Private key.

  • hostname - (Optional) By default the plugin connects to keepersecurity.com

circle-info

For more information on creating a Secrets Manager configuration, see the Configuration Documentation

Get Secrets Using Data Sources

A data source is provided for each standard Keeper record type, which facilitates easy fetching of secret credentials.

Data sources are accessed using the following format:

For example, using a Login type record:

To access any additional custom fields or standard fields for user defined record types use secretsmanager_fieldarrow-up-right data source

List of supported record types

Record Type
Data Source Name

"secretsmanager_address"

"secretsmanager_bank_account"

"secretsmanager_bank_card"

"secretsmanager_birth_certificate"

"secretsmanager_contact"

"secretsmanager_database_credentials"

"secretsmanager_driver_license"

"secretsmanager_encrypted_notes"

"secretsmanager_field"

"secretsmanager_file"

"secretsmanager_folder"

"secretsmanager_folders"

"secretsmanager_health_insurance"

"secretsmanager_login"

"secretsmanager_membership"

"secretsmanager_passport"

"secretsmanager_pam_database"

"secretsmanager_pam_directory"

"secretsmanager_pam_machine"

"secretsmanager_pam_user"

"secretsmanager_photo"

"secretsmanager_record"

Recordsarrow-up-right (for large volume requests)

"secretsmanager_records"

"secretsmanager_server_credentials"

"secretsmanager_software_license"

"secretsmanager_ssh_keys"

"secretsmanager_ssn_card"

To see the fields available to each data source see Record Types Data Source Referencearrow-up-right

For more information on record types see Record Types documentation and Commander usage.

Accessing Record Fields

To access a secret credential saved to a field in a record, access the field as part of the data source.

Access the field of a typed record data source

Use this format to access fields of a typed data resource

Example: access the password of a login type data source

Use the field data source to query any field in a record with Keeper Notation

Create a data source using the "secretsmanager_field" data source type, and specify a field query in the path property.

The field query uses the format: "<UID>/field/<field type>"

circle-info

If you don't know the record UID, you can look up by title using a wildcard * in place of the UID and the optional title attribute:

Returns an error if more than one accessible record matches the title.

Creating Records With Resources

Keeper provides Terraform resources for the major Keeper record types shown above. Using these resources, Keeper records can be created using the Keeper Secrets Manager Terraform plugin.

To create a record, use the resource corresponding to the record type that you would like to use.

Each record resource requires at least a folder_uid and title as well as values for each record field.

Example login resource

Folder UID

To create records, Keeper Secrets Manager requires a folder UID so it knows where to create new records.

A folder UID can be found in the Keeper Vault or by using Keeper Commander.

The target folder (or its parent shared folder) must be accessible by the Keeper Secrets Manager Application with Can Edit permissions.

Title

The record title.

Record Fields

The value and settings for each record field can be set in the resource. For information on the available fields per record type, see the resource definitionsarrow-up-right.

Each field is represented as an object in the resource.

Example login field

Setting Field Values

Use the value field to set the intended value for each field. The format of fields can differ, for example the login field type takes a string, while the name field takes an object with "first", "middle" and "last" fields.

For reference of each field's value format see the resource documentationarrow-up-right.

Setting Field Settings

Each field can be configured with various settings:

Field
Accepted Value
Description

label

string

The field label

required

boolean

if True, the field will be considered required by the Keeper Vault

privacy_screen

boolean

if True, the field will be hidden in the Keeper Vault

Password Field

The password field has some special features.

Password Generation

Records created using the Terraform plugin can have a password generated automatically. To have the plugin generate a password, do not provide a value field to the password, and instead use generate = "true"

The password generation can be configured to generate a password of a specified length using the complexity field

Additionally, password fields have an extra configuration setting: enforce_generation which when true will make the Keeper Vault enforce that the password can only be generated and not set by a user.

circle-info

To have Terraform regenerate a password, it needs to notice a difference in the generate field. To allow for triggering a difference, the generate field accepts both "true" and "yes" values. Change from one to the other to trigger a regeneration.

SSH Key Generation

The secretsmanager_ssh_keys resource can automatically generate an SSH key pair. To trigger generation, omit the key pair value and set generate = "true" on the key_pair field:

PAM Machine and PAM User resources also support generating a private PEM key via the private_pem_key field using the same generate / key_type / key_bits pattern.

circle-info

Like passwords, SSH key generation uses "true" or "yes" as valid values. Changing between the two triggers Terraform to detect a diff and regenerate the key pair on the next apply.

Examples

Read Credentials

This example provisions Keeper Secrets Manager, reads a login type data source, and accesses each field of the data source.

Create a Keeper Record

Create PAM Records

circle-info

These snippets assume the terraform and provider "secretsmanager" blocks are already configured as shown above.

Read PAM Data Source Outputs

circle-info

These snippets assume the terraform and provider "secretsmanager" blocks are already configured as shown above.

For more examples, check out the examples folderarrow-up-right in the source code.

Optimization

The secretsmanager_records data source allows you to fetch multiple Keeper Secrets Manager records in a single API call, significantly reducing API requests and improving performance when dealing with many secrets.

Fetch by UIDs (most efficient):

Fetch by exact titles:

Fetch by regex pattern:

circle-exclamation
circle-info

For detailed documentation including all available output attributes, see the secretsmanager_records referencearrow-up-right.

Accessing results by UID:

Records are available as a list via records, or as a UID-indexed map via records_by_uid:

Last updated

Was this helpful?