Yandex Cloud
Search
Contact UsGet started
  • Blog
  • Pricing
  • Documentation
  • All Services
  • System Status
    • Featured
    • Infrastructure & Network
    • Data Platform
    • Containers
    • Developer tools
    • Serverless
    • Security
    • Monitoring & Resources
    • ML & AI
    • Business tools
  • All Solutions
    • By industry
    • By use case
    • Economics and Pricing
    • Security
    • Technical Support
    • Customer Stories
    • Gateway to Russia
    • Cloud for Startups
    • Education and Science
  • Blog
  • Pricing
  • Documentation
Yandex project
© 2025 Yandex.Cloud LLC
Yandex Lockbox
  • Getting started
    • All guides
    • Creating secrets
    • Updating a secret
    • Configuring access to a secret
    • Getting information about a secret
    • Deleting a secret
    • Deactivating and activating a secret
    • Secret version management
    • Viewing operations with a secret
  • Quotas and limits
  • Access management
  • Pricing policy
  • Terraform reference
  • Monitoring metrics
  • Audit Trails events
  • Release notes
  • FAQ

In this article:

  • Creating a new user secret version
  • Creating a new generated secret version
  • Getting information about a version
  • Creating a version based on an existing version
  • Changing the current version
  • Scheduling a version for deletion
  • See also
  1. Step-by-step guides
  2. Secret version management

Secret version management

Written by
Yandex Cloud
Updated at May 5, 2025
  • Creating a new user secret version
  • Creating a new generated secret version
  • Getting information about a version
  • Creating a version based on an existing version
  • Changing the current version
  • Scheduling a version for deletion
  • See also

With secret version management, you can:

  • Create a new user secret version.
  • Create a new generated secret version.
  • Get information about a version.
  • Create a version based on an existing version.
  • Roll back to a particular version.
  • Schedule a version for deletion.

Creating a new user secret versionCreating a new user secret version

Management console
Terraform
API
  1. In the management console, select the folder the secret belongs to.

  2. In the list of services, select Lockbox.

  3. Click the name of the secret you need.

  4. Under Versions, click Add version.

  5. Add the following parameters:

    • (Optional) Description: Version description.
    • Key: Non-secret name you will use to identify a value.
    • Value: Explicitly represented secret data.
      You can create multiple key-value pairs per version.
  6. Click Add version.

With Terraform, you can quickly create a cloud infrastructure in Yandex Cloud and manage it using configuration files. These files store the infrastructure description written in HashiCorp Configuration Language (HCL). If you change the configuration files, Terraform automatically detects which part of your configuration is already deployed, and what should be added or removed.

Terraform is distributed under the Business Source License. The Yandex Cloud provider for Terraform is distributed under the MPL-2.0 license.

For more information about the provider resources, see the documentation on the Terraform website or mirror website.

If you do not have Terraform yet, install it and configure its Yandex Cloud provider.

  1. In the configuration file, define the parameters of the resources you want to create:

    resource "yandex_lockbox_secret_version_hashed" "my_version" {
      secret_id    = "<secret_ID>"
    
      key_1        = "<secret_1_key>"
      text_value_1 = "<secret_1_value>"
    
      key_2        = "<secret_2_key>"
      text_value_2 = "<secret_2_value>"
    }
    

    Where:

    • secret_id: ID of the secret you are creating a version for.
    • (Optional) description: Any comment on the secret version.
    • key_N: Secret key. Non-secret name you will use to identify a value.
    • text_value_N: Explicitly represented secret data.

    The key_N/text_value_N pairs are numbered sequentially from 1 to 10 (10 pairs are supported). If only one pair is required, use key_1/text_value_1.

    Note

    We recommend using yandex_lockbox_secret_version_hashed: it stores values in Terraform state in hashed format. We continue supporting yandex_lockbox_secret_version.

    For more information about yandex_lockbox_secret_version_hashed, see the relevant provider documentation.

  2. Create resources:

    1. In the terminal, change to the folder where you edited the configuration file.

    2. Make sure the configuration file is correct using the command:

      terraform validate
      

      If the configuration is correct, the following message is returned:

      Success! The configuration is valid.
      
    3. Run the command:

      terraform plan
      

      The terminal will display a list of resources with parameters. No changes are made at this step. If the configuration contains errors, Terraform will point them out.

    4. Apply the configuration changes:

      terraform apply
      
    5. Confirm the changes: type yes in the terminal and press Enter.

This creates a new version of the specified secret. You can check the new version and its settings using the management console or this CLI command:

yc lockbox secret list-versions <secret_ID>

To create a new secret version, use the addVersion REST API method for the Secret resource or the SecretService/AddVersion gRPC API call.

Creating a new generated secret versionCreating a new generated secret version

Management console
Terraform
  1. In the management console, select the folder the secret belongs to.
  2. In the list of services, select Lockbox.
  3. Click the name of the secret you need.
  4. Under Versions, click Add version.
  5. (Optional) Add Description of the version.
  6. (Optional) To change other parameters, click Edit secret and specify:
    • Secret type: You can either leave the generated type or select the user type.

    • Key and Automatic generation options, for the generated secret type.

    • Key and Value, for the user secret type.

      You can create multiple key-value pairs per version.

  7. Click Add version or Save.

Secret generation with Yandex CloudSecret generation with Yandex Cloud

With Terraform, you can quickly create a cloud infrastructure in Yandex Cloud and manage it using configuration files. These files store the infrastructure description written in HashiCorp Configuration Language (HCL). If you change the configuration files, Terraform automatically detects which part of your configuration is already deployed, and what should be added or removed.

Terraform is distributed under the Business Source License. The Yandex Cloud provider for Terraform is distributed under the MPL-2.0 license.

For more information about the provider resources, see the documentation on the Terraform website or mirror website.

If you do not have Terraform yet, install it and configure its Yandex Cloud provider.

  1. You can create a new generated secret version when creating it. Specify the secret generation parameters in the yandex_lockbox_secret resource description under password_payload_specification and create a new secret version with a reference to the secret:

    # Creating a generated secret
    resource "yandex_lockbox_secret" "my_secret" {
      name = "<secret_name>"
    
      password_payload_specification {
        password_key        = "<secret_key>"
        length              = "<length>"
        include_uppercase   = true
        include_lowercase   = true
        include_digits      = true
        include_punctuation = true
      }
    }
    
    # Creating a secret version
    resource "yandex_lockbox_secret_version" "my_version" {
      secret_id = yandex_lockbox_secret.my_secret.id
    }
    

    Where:

    • password_payload_specification: Secret generating parameters:
      • password_key: Secret key. Non-secret name you will use to identify a value.
      • length: Length of the generated secret value. This is a required parameter.
      • include_uppercase : Use uppercase Latin letters (A...Z). The default value is true.
      • include_lowercase: Use lowercase Latin letters (a...z). The default value is true.
      • include_digits: Use numbers (0...9). The default value is true.
      • include_punctuation: Use special characters. The default value is true.

    For more information about the yandex_lockbox_secret resource parameters in Terraform, see the relevant provider documentation.

  2. Apply the changes:

    1. In the terminal, change to the folder where you edited the configuration file.

    2. Make sure the configuration file is correct using the command:

      terraform validate
      

      If the configuration is correct, the following message is returned:

      Success! The configuration is valid.
      
    3. Run the command:

      terraform plan
      

      The terminal will display a list of resources with parameters. No changes are made at this step. If the configuration contains errors, Terraform will point them out.

    4. Apply the configuration changes:

      terraform apply
      
    5. Confirm the changes: type yes in the terminal and press Enter.

You can check the new secret and its contents using the management console or this CLI command:

yc lockbox payload get <secret_name_or_ID>

Secret generation with a custom scriptSecret generation with a custom script

You can create a new generated secret version using a secret generation script of your own. The script's output value will not be displayed in Terraform State.

Example of a bash secret generation script
#!/bin/bash
choose() { echo ${1:RANDOM%${#1}:1}; }

{
    choose 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
    choose 'abcdefghijklmnopqrstuvwxyz'
    choose '0123456789'
    choose '!@#$%^\&'
    for i in $( seq 1 $(( 4 + RANDOM % 8 )) )
    do
        choose '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
    done
} | sort -R | tr -d '\n'
echo ""
  1. In the yandex_lockbox_secret_version resource description under entries, specify the command.path parameter, i.e., path to the secret generation script.

    # Creating a secret version with a password generation script
    resource "yandex_lockbox_secret_version" "my_version" {
      secret_id = "<secret_ID>"
    
      entries {
        key = "<secret_key>"
        command {
          path = "<path_to_script>"
        }
      }
    }
    

    Where:

    • secret_id: ID of the secret you are creating a version for.
    • key: Secret key. Non-secret name you will use to identify a value.
    • path: Path to the secret generation script.

    For more information about the yandex_lockbox_secret_version resource parameters in Terraform, see the relevant provider documentation.

  2. Apply the changes:

    1. In the terminal, change to the folder where you edited the configuration file.

    2. Make sure the configuration file is correct using the command:

      terraform validate
      

      If the configuration is correct, the following message is returned:

      Success! The configuration is valid.
      
    3. Run the command:

      terraform plan
      

      The terminal will display a list of resources with parameters. No changes are made at this step. If the configuration contains errors, Terraform will point them out.

    4. Apply the configuration changes:

      terraform apply
      
    5. Confirm the changes: type yes in the terminal and press Enter.

You can check the new secret and its contents using the management console or this CLI command:

yc lockbox payload get <secret_name_or_ID>

Getting information about a versionGetting information about a version

Management console
CLI
API
  1. In the management console, select the folder the secret belongs to.
  2. In the list of services, select Lockbox.
  3. Click the name of the secret you need.
  4. Under Versions, you will see a list of all secret versions with information about them.
  5. Click a version to see the details about its key-value pairs.

If you do not have the Yandex Cloud CLI yet, install and initialize it.

The folder specified when creating the CLI profile is used by default. To change the default folder, use the yc config set folder-id <folder_ID> command. You can specify a different folder using the --folder-name or --folder-id parameter.

  1. View the description of the CLI command to view secret versions:

    yc lockbox secret list-version --help
    
  2. Run this command:

    yc lockbox secret list-version <secret_name>
    

It will return information about all versions of the secret, key names included. Secret version values will not be displayed.

To get information about a version, use the listVersions REST API method for the Secret resource or the SecretService/ListVersions gRPC API call.

Creating a version based on an existing versionCreating a version based on an existing version

Management console
CLI
API
  1. In the management console, select the folder the secret belongs to.
  2. In the list of services, select Lockbox.
  3. Click the name of the secret you need.
  4. Under Versions, next to the appropriate version, click .
  5. Select Create a new version from this one.
  6. Edit or add the following parameters:
    • (Optional) Description: Version description.
    • Key: Non-secret name you will use to identify a value.
    • For a user secret, Value: Secret data in an explicit form.
      You can create multiple key-value pairs per version.
    • For a generated secret, you can change the key and the value parameters. To do this, click Edit secret and specify new parameters.
  7. Click Add version.

If you do not have the Yandex Cloud CLI yet, install and initialize it.

The folder specified when creating the CLI profile is used by default. To change the default folder, use the yc config set folder-id <folder_ID> command. You can specify a different folder using the --folder-name or --folder-id parameter.

  1. View the description of the CLI command to create a new secret version:

    yc lockbox secret add-version --help
    
  2. Run this command:

    yc lockbox secret add-version <secret_name> \
      --description <secret_version_description> \
      --payload "<array_with_secret_version_contents>" \
      --base-version-id <existing_secret_version_ID>
    

    Where:

    • <secret_name>: Name of the secret you are creating a version for.
    • --description: Description of the new secret version (optional).
    • --payload: Contents of the new secret version as a YAML or JSON array.
    • --base-version-id: ID of the secret version used to create a new secret. If this parameter is not specified, the new version will be created based on the current version.

    Result:

    id: e6qor8pe3ju7********
    secret_id: e6qkkp3k29jf********
    created_at: "2024-04-25T13:49:26.621Z"
    status: ACTIVE
    payload_entry_keys:
      - secret-key1
      - secret-key2
    

To create a version based on an existing version, use the addVersion REST API method for the Secret resource or the SecretService/AddVersion gRPC API call.

Changing the current versionChanging the current version

Management console
API
  1. In the management console, select the folder the secret belongs to.
  2. In the list of services, select Lockbox.
  3. Click the name of the secret you need.
  4. Under Versions, next to the appropriate version, click .
  5. Select Set as current version.
  6. Click Set as current version.

To change the current version, use the addVersion REST API method for the Secret resource or the SecretService/AddVersion gRPC API call and specify the required version.

Scheduling a version for deletionScheduling a version for deletion

Management console
CLI
Terraform
API
  1. In the management console, select the folder the secret belongs to.
  2. In the list of services, select Lockbox.
  3. Click the name of the secret you need.
  4. Under Versions, next to the appropriate version, click .
  5. Select Schedule destruction.
  6. Enter the deletion pending period.
  7. Click Schedule.

If you do not have the Yandex Cloud CLI yet, install and initialize it.

The folder specified when creating the CLI profile is used by default. To change the default folder, use the yc config set folder-id <folder_ID> command. You can specify a different folder using the --folder-name or --folder-id parameter.

  1. See the description of the CLI command to schedule version deletion:

    yc lockbox secret schedule-version-destruction --help
    
  2. Schedule a version for deletion by specifying the secret name, version ID, and the deletion pending period. For example, 1 week: 168h:

    yc lockbox secret schedule-version-destruction <secret_name> \
      --version-id <version_ID> \
      --pending-period 168h
    

    Result:

    id: e6qor8pe3ju7********
    secret_id: e6qkkp3k29jf********
    created_at: "2023-11-08T13:14:34.676Z"
    destroy_at: "2023-11-15T17:06:28.795Z"
    status: SCHEDULED_FOR_DESTRUCTION
    payload_entry_keys:
      - secret-key
    

To schedule the removal of a version, remove the resource description for that version from the configuration file. You cannot use Terraform to set time to deletion, it will be set by default: 7 days.

To schedule a version for deletion, use the scheduleVersionDestruction REST API method for the Secret resource or the SecretService/ScheduleVersionDestruction gRPC API call.

See alsoSee also

  • Secrets in Yandex Lockbox

Was the article helpful?

Previous
Deactivating and activating a secret
Next
Transmitting a secret to Yandex Serverless Containers
Yandex project
© 2025 Yandex.Cloud LLC