1. Packages
  2. HashiCorp Vault Provider
  3. API Docs
  4. kv
  5. SecretBackendV2
HashiCorp Vault v6.6.0 published on Thursday, Mar 13, 2025 by Pulumi

vault.kv.SecretBackendV2

Explore with Pulumi AI

Configures KV-V2 backend level settings that are applied to every key in the key-value store.

For more information on Vault’s KV-V2 secret backend see here.

Example Usage

import * as pulumi from "@pulumi/pulumi";
import * as vault from "@pulumi/vault";

const kvv2 = new vault.Mount("kvv2", {
    path: "kvv2",
    type: "kv",
    options: {
        version: "2",
    },
    description: "KV Version 2 secret engine mount",
});
const example = new vault.kv.SecretBackendV2("example", {
    mount: kvv2.path,
    maxVersions: 5,
    deleteVersionAfter: 12600,
    casRequired: true,
});
Copy
import pulumi
import pulumi_vault as vault

kvv2 = vault.Mount("kvv2",
    path="kvv2",
    type="kv",
    options={
        "version": "2",
    },
    description="KV Version 2 secret engine mount")
example = vault.kv.SecretBackendV2("example",
    mount=kvv2.path,
    max_versions=5,
    delete_version_after=12600,
    cas_required=True)
Copy
package main

import (
	"github.com/pulumi/pulumi-vault/sdk/v6/go/vault"
	"github.com/pulumi/pulumi-vault/sdk/v6/go/vault/kv"
	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		kvv2, err := vault.NewMount(ctx, "kvv2", &vault.MountArgs{
			Path: pulumi.String("kvv2"),
			Type: pulumi.String("kv"),
			Options: pulumi.StringMap{
				"version": pulumi.String("2"),
			},
			Description: pulumi.String("KV Version 2 secret engine mount"),
		})
		if err != nil {
			return err
		}
		_, err = kv.NewSecretBackendV2(ctx, "example", &kv.SecretBackendV2Args{
			Mount:              kvv2.Path,
			MaxVersions:        pulumi.Int(5),
			DeleteVersionAfter: pulumi.Int(12600),
			CasRequired:        pulumi.Bool(true),
		})
		if err != nil {
			return err
		}
		return nil
	})
}
Copy
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Vault = Pulumi.Vault;

return await Deployment.RunAsync(() => 
{
    var kvv2 = new Vault.Mount("kvv2", new()
    {
        Path = "kvv2",
        Type = "kv",
        Options = 
        {
            { "version", "2" },
        },
        Description = "KV Version 2 secret engine mount",
    });

    var example = new Vault.Kv.SecretBackendV2("example", new()
    {
        Mount = kvv2.Path,
        MaxVersions = 5,
        DeleteVersionAfter = 12600,
        CasRequired = true,
    });

});
Copy
package generated_program;

import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.vault.Mount;
import com.pulumi.vault.MountArgs;
import com.pulumi.vault.kv.SecretBackendV2;
import com.pulumi.vault.kv.SecretBackendV2Args;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;

public class App {
    public static void main(String[] args) {
        Pulumi.run(App::stack);
    }

    public static void stack(Context ctx) {
        var kvv2 = new Mount("kvv2", MountArgs.builder()
            .path("kvv2")
            .type("kv")
            .options(Map.of("version", "2"))
            .description("KV Version 2 secret engine mount")
            .build());

        var example = new SecretBackendV2("example", SecretBackendV2Args.builder()
            .mount(kvv2.path())
            .maxVersions(5)
            .deleteVersionAfter(12600)
            .casRequired(true)
            .build());

    }
}
Copy
resources:
  kvv2:
    type: vault:Mount
    properties:
      path: kvv2
      type: kv
      options:
        version: '2'
      description: KV Version 2 secret engine mount
  example:
    type: vault:kv:SecretBackendV2
    properties:
      mount: ${kvv2.path}
      maxVersions: 5
      deleteVersionAfter: 12600
      casRequired: true
Copy

Required Vault Capabilities

Use of this resource requires the create or update capability (depending on whether the resource already exists) on the given path, the delete capability if the resource is removed from configuration, and the read capability for drift detection (by default).

Create SecretBackendV2 Resource

Resources are created with functions called constructors. To learn more about declaring and configuring resources, see Resources.

Constructor syntax

new SecretBackendV2(name: string, args: SecretBackendV2Args, opts?: CustomResourceOptions);
@overload
def SecretBackendV2(resource_name: str,
                    args: SecretBackendV2Args,
                    opts: Optional[ResourceOptions] = None)

@overload
def SecretBackendV2(resource_name: str,
                    opts: Optional[ResourceOptions] = None,
                    mount: Optional[str] = None,
                    cas_required: Optional[bool] = None,
                    delete_version_after: Optional[int] = None,
                    max_versions: Optional[int] = None,
                    namespace: Optional[str] = None)
func NewSecretBackendV2(ctx *Context, name string, args SecretBackendV2Args, opts ...ResourceOption) (*SecretBackendV2, error)
public SecretBackendV2(string name, SecretBackendV2Args args, CustomResourceOptions? opts = null)
public SecretBackendV2(String name, SecretBackendV2Args args)
public SecretBackendV2(String name, SecretBackendV2Args args, CustomResourceOptions options)
type: vault:kv:SecretBackendV2
properties: # The arguments to resource properties.
options: # Bag of options to control resource's behavior.

Parameters

name This property is required. string
The unique name of the resource.
args This property is required. SecretBackendV2Args
The arguments to resource properties.
opts CustomResourceOptions
Bag of options to control resource's behavior.
resource_name This property is required. str
The unique name of the resource.
args This property is required. SecretBackendV2Args
The arguments to resource properties.
opts ResourceOptions
Bag of options to control resource's behavior.
ctx Context
Context object for the current deployment.
name This property is required. string
The unique name of the resource.
args This property is required. SecretBackendV2Args
The arguments to resource properties.
opts ResourceOption
Bag of options to control resource's behavior.
name This property is required. string
The unique name of the resource.
args This property is required. SecretBackendV2Args
The arguments to resource properties.
opts CustomResourceOptions
Bag of options to control resource's behavior.
name This property is required. String
The unique name of the resource.
args This property is required. SecretBackendV2Args
The arguments to resource properties.
options CustomResourceOptions
Bag of options to control resource's behavior.

Constructor example

The following reference example uses placeholder values for all input properties.

var secretBackendV2Resource = new Vault.Kv.SecretBackendV2("secretBackendV2Resource", new()
{
    Mount = "string",
    CasRequired = false,
    DeleteVersionAfter = 0,
    MaxVersions = 0,
    Namespace = "string",
});
Copy
example, err := kv.NewSecretBackendV2(ctx, "secretBackendV2Resource", &kv.SecretBackendV2Args{
	Mount:              pulumi.String("string"),
	CasRequired:        pulumi.Bool(false),
	DeleteVersionAfter: pulumi.Int(0),
	MaxVersions:        pulumi.Int(0),
	Namespace:          pulumi.String("string"),
})
Copy
var secretBackendV2Resource = new SecretBackendV2("secretBackendV2Resource", SecretBackendV2Args.builder()
    .mount("string")
    .casRequired(false)
    .deleteVersionAfter(0)
    .maxVersions(0)
    .namespace("string")
    .build());
Copy
secret_backend_v2_resource = vault.kv.SecretBackendV2("secretBackendV2Resource",
    mount="string",
    cas_required=False,
    delete_version_after=0,
    max_versions=0,
    namespace="string")
Copy
const secretBackendV2Resource = new vault.kv.SecretBackendV2("secretBackendV2Resource", {
    mount: "string",
    casRequired: false,
    deleteVersionAfter: 0,
    maxVersions: 0,
    namespace: "string",
});
Copy
type: vault:kv:SecretBackendV2
properties:
    casRequired: false
    deleteVersionAfter: 0
    maxVersions: 0
    mount: string
    namespace: string
Copy

SecretBackendV2 Resource Properties

To learn more about resource properties and how to use them, see Inputs and Outputs in the Architecture and Concepts docs.

Inputs

In Python, inputs that are objects can be passed either as argument classes or as dictionary literals.

The SecretBackendV2 resource accepts the following input properties:

Mount
This property is required.
Changes to this property will trigger replacement.
string
Path where KV-V2 engine is mounted.
CasRequired bool
If true, all keys will require the cas parameter to be set on all write requests.
DeleteVersionAfter int
If set, specifies the length of time before a version is deleted. Accepts duration in integer seconds.
MaxVersions int
The number of versions to keep per key.
Namespace Changes to this property will trigger replacement. string
The namespace to provision the resource in. The value should not contain leading or trailing forward slashes. The namespace is always relative to the provider's configured namespace. Available only for Vault Enterprise.
Mount
This property is required.
Changes to this property will trigger replacement.
string
Path where KV-V2 engine is mounted.
CasRequired bool
If true, all keys will require the cas parameter to be set on all write requests.
DeleteVersionAfter int
If set, specifies the length of time before a version is deleted. Accepts duration in integer seconds.
MaxVersions int
The number of versions to keep per key.
Namespace Changes to this property will trigger replacement. string
The namespace to provision the resource in. The value should not contain leading or trailing forward slashes. The namespace is always relative to the provider's configured namespace. Available only for Vault Enterprise.
mount
This property is required.
Changes to this property will trigger replacement.
String
Path where KV-V2 engine is mounted.
casRequired Boolean
If true, all keys will require the cas parameter to be set on all write requests.
deleteVersionAfter Integer
If set, specifies the length of time before a version is deleted. Accepts duration in integer seconds.
maxVersions Integer
The number of versions to keep per key.
namespace Changes to this property will trigger replacement. String
The namespace to provision the resource in. The value should not contain leading or trailing forward slashes. The namespace is always relative to the provider's configured namespace. Available only for Vault Enterprise.
mount
This property is required.
Changes to this property will trigger replacement.
string
Path where KV-V2 engine is mounted.
casRequired boolean
If true, all keys will require the cas parameter to be set on all write requests.
deleteVersionAfter number
If set, specifies the length of time before a version is deleted. Accepts duration in integer seconds.
maxVersions number
The number of versions to keep per key.
namespace Changes to this property will trigger replacement. string
The namespace to provision the resource in. The value should not contain leading or trailing forward slashes. The namespace is always relative to the provider's configured namespace. Available only for Vault Enterprise.
mount
This property is required.
Changes to this property will trigger replacement.
str
Path where KV-V2 engine is mounted.
cas_required bool
If true, all keys will require the cas parameter to be set on all write requests.
delete_version_after int
If set, specifies the length of time before a version is deleted. Accepts duration in integer seconds.
max_versions int
The number of versions to keep per key.
namespace Changes to this property will trigger replacement. str
The namespace to provision the resource in. The value should not contain leading or trailing forward slashes. The namespace is always relative to the provider's configured namespace. Available only for Vault Enterprise.
mount
This property is required.
Changes to this property will trigger replacement.
String
Path where KV-V2 engine is mounted.
casRequired Boolean
If true, all keys will require the cas parameter to be set on all write requests.
deleteVersionAfter Number
If set, specifies the length of time before a version is deleted. Accepts duration in integer seconds.
maxVersions Number
The number of versions to keep per key.
namespace Changes to this property will trigger replacement. String
The namespace to provision the resource in. The value should not contain leading or trailing forward slashes. The namespace is always relative to the provider's configured namespace. Available only for Vault Enterprise.

Outputs

All input properties are implicitly available as output properties. Additionally, the SecretBackendV2 resource produces the following output properties:

Id string
The provider-assigned unique ID for this managed resource.
Id string
The provider-assigned unique ID for this managed resource.
id String
The provider-assigned unique ID for this managed resource.
id string
The provider-assigned unique ID for this managed resource.
id str
The provider-assigned unique ID for this managed resource.
id String
The provider-assigned unique ID for this managed resource.

Look up Existing SecretBackendV2 Resource

Get an existing SecretBackendV2 resource’s state with the given name, ID, and optional extra properties used to qualify the lookup.

public static get(name: string, id: Input<ID>, state?: SecretBackendV2State, opts?: CustomResourceOptions): SecretBackendV2
@staticmethod
def get(resource_name: str,
        id: str,
        opts: Optional[ResourceOptions] = None,
        cas_required: Optional[bool] = None,
        delete_version_after: Optional[int] = None,
        max_versions: Optional[int] = None,
        mount: Optional[str] = None,
        namespace: Optional[str] = None) -> SecretBackendV2
func GetSecretBackendV2(ctx *Context, name string, id IDInput, state *SecretBackendV2State, opts ...ResourceOption) (*SecretBackendV2, error)
public static SecretBackendV2 Get(string name, Input<string> id, SecretBackendV2State? state, CustomResourceOptions? opts = null)
public static SecretBackendV2 get(String name, Output<String> id, SecretBackendV2State state, CustomResourceOptions options)
resources:  _:    type: vault:kv:SecretBackendV2    get:      id: ${id}
name This property is required.
The unique name of the resulting resource.
id This property is required.
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.
resource_name This property is required.
The unique name of the resulting resource.
id This property is required.
The unique provider ID of the resource to lookup.
name This property is required.
The unique name of the resulting resource.
id This property is required.
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.
name This property is required.
The unique name of the resulting resource.
id This property is required.
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.
name This property is required.
The unique name of the resulting resource.
id This property is required.
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.
The following state arguments are supported:
CasRequired bool
If true, all keys will require the cas parameter to be set on all write requests.
DeleteVersionAfter int
If set, specifies the length of time before a version is deleted. Accepts duration in integer seconds.
MaxVersions int
The number of versions to keep per key.
Mount Changes to this property will trigger replacement. string
Path where KV-V2 engine is mounted.
Namespace Changes to this property will trigger replacement. string
The namespace to provision the resource in. The value should not contain leading or trailing forward slashes. The namespace is always relative to the provider's configured namespace. Available only for Vault Enterprise.
CasRequired bool
If true, all keys will require the cas parameter to be set on all write requests.
DeleteVersionAfter int
If set, specifies the length of time before a version is deleted. Accepts duration in integer seconds.
MaxVersions int
The number of versions to keep per key.
Mount Changes to this property will trigger replacement. string
Path where KV-V2 engine is mounted.
Namespace Changes to this property will trigger replacement. string
The namespace to provision the resource in. The value should not contain leading or trailing forward slashes. The namespace is always relative to the provider's configured namespace. Available only for Vault Enterprise.
casRequired Boolean
If true, all keys will require the cas parameter to be set on all write requests.
deleteVersionAfter Integer
If set, specifies the length of time before a version is deleted. Accepts duration in integer seconds.
maxVersions Integer
The number of versions to keep per key.
mount Changes to this property will trigger replacement. String
Path where KV-V2 engine is mounted.
namespace Changes to this property will trigger replacement. String
The namespace to provision the resource in. The value should not contain leading or trailing forward slashes. The namespace is always relative to the provider's configured namespace. Available only for Vault Enterprise.
casRequired boolean
If true, all keys will require the cas parameter to be set on all write requests.
deleteVersionAfter number
If set, specifies the length of time before a version is deleted. Accepts duration in integer seconds.
maxVersions number
The number of versions to keep per key.
mount Changes to this property will trigger replacement. string
Path where KV-V2 engine is mounted.
namespace Changes to this property will trigger replacement. string
The namespace to provision the resource in. The value should not contain leading or trailing forward slashes. The namespace is always relative to the provider's configured namespace. Available only for Vault Enterprise.
cas_required bool
If true, all keys will require the cas parameter to be set on all write requests.
delete_version_after int
If set, specifies the length of time before a version is deleted. Accepts duration in integer seconds.
max_versions int
The number of versions to keep per key.
mount Changes to this property will trigger replacement. str
Path where KV-V2 engine is mounted.
namespace Changes to this property will trigger replacement. str
The namespace to provision the resource in. The value should not contain leading or trailing forward slashes. The namespace is always relative to the provider's configured namespace. Available only for Vault Enterprise.
casRequired Boolean
If true, all keys will require the cas parameter to be set on all write requests.
deleteVersionAfter Number
If set, specifies the length of time before a version is deleted. Accepts duration in integer seconds.
maxVersions Number
The number of versions to keep per key.
mount Changes to this property will trigger replacement. String
Path where KV-V2 engine is mounted.
namespace Changes to this property will trigger replacement. String
The namespace to provision the resource in. The value should not contain leading or trailing forward slashes. The namespace is always relative to the provider's configured namespace. Available only for Vault Enterprise.

Import

The KV-V2 secret backend can be imported using its unique ID, the ${mount}/config, e.g.

$ pulumi import vault:kv/secretBackendV2:SecretBackendV2 example kvv2/config
Copy

To learn more about importing existing cloud resources, see Importing resources.

Package Details

Repository
Vault pulumi/pulumi-vault
License
Apache-2.0
Notes
This Pulumi package is based on the vault Terraform Provider.