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

vault.kv.Secret

Explore with Pulumi AI

Writes a KV-V1 secret to a given path in Vault.

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

Example Usage

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

const kvv1 = new vault.Mount("kvv1", {
    path: "kvv1",
    type: "kv",
    options: {
        version: "1",
    },
    description: "KV Version 1 secret engine mount",
});
const secret = new vault.kv.Secret("secret", {
    path: pulumi.interpolate`${kvv1.path}/secret`,
    dataJson: JSON.stringify({
        zip: "zap",
        foo: "bar",
    }),
});
Copy
import pulumi
import json
import pulumi_vault as vault

kvv1 = vault.Mount("kvv1",
    path="kvv1",
    type="kv",
    options={
        "version": "1",
    },
    description="KV Version 1 secret engine mount")
secret = vault.kv.Secret("secret",
    path=kvv1.path.apply(lambda path: f"{path}/secret"),
    data_json=json.dumps({
        "zip": "zap",
        "foo": "bar",
    }))
Copy
package main

import (
	"encoding/json"
	"fmt"

	"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 {
		kvv1, err := vault.NewMount(ctx, "kvv1", &vault.MountArgs{
			Path: pulumi.String("kvv1"),
			Type: pulumi.String("kv"),
			Options: pulumi.StringMap{
				"version": pulumi.String("1"),
			},
			Description: pulumi.String("KV Version 1 secret engine mount"),
		})
		if err != nil {
			return err
		}
		tmpJSON0, err := json.Marshal(map[string]interface{}{
			"zip": "zap",
			"foo": "bar",
		})
		if err != nil {
			return err
		}
		json0 := string(tmpJSON0)
		_, err = kv.NewSecret(ctx, "secret", &kv.SecretArgs{
			Path: kvv1.Path.ApplyT(func(path string) (string, error) {
				return fmt.Sprintf("%v/secret", path), nil
			}).(pulumi.StringOutput),
			DataJson: pulumi.String(json0),
		})
		if err != nil {
			return err
		}
		return nil
	})
}
Copy
using System.Collections.Generic;
using System.Linq;
using System.Text.Json;
using Pulumi;
using Vault = Pulumi.Vault;

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

    var secret = new Vault.Kv.Secret("secret", new()
    {
        Path = kvv1.Path.Apply(path => $"{path}/secret"),
        DataJson = JsonSerializer.Serialize(new Dictionary<string, object?>
        {
            ["zip"] = "zap",
            ["foo"] = "bar",
        }),
    });

});
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.Secret;
import com.pulumi.vault.kv.SecretArgs;
import static com.pulumi.codegen.internal.Serialization.*;
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 kvv1 = new Mount("kvv1", MountArgs.builder()
            .path("kvv1")
            .type("kv")
            .options(Map.of("version", "1"))
            .description("KV Version 1 secret engine mount")
            .build());

        var secret = new Secret("secret", SecretArgs.builder()
            .path(kvv1.path().applyValue(path -> String.format("%s/secret", path)))
            .dataJson(serializeJson(
                jsonObject(
                    jsonProperty("zip", "zap"),
                    jsonProperty("foo", "bar")
                )))
            .build());

    }
}
Copy
resources:
  kvv1:
    type: vault:Mount
    properties:
      path: kvv1
      type: kv
      options:
        version: '1'
      description: KV Version 1 secret engine mount
  secret:
    type: vault:kv:Secret
    properties:
      path: ${kvv1.path}/secret
      dataJson:
        fn::toJSON:
          zip: zap
          foo: bar
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 Secret Resource

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

Constructor syntax

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

@overload
def Secret(resource_name: str,
           opts: Optional[ResourceOptions] = None,
           data_json: Optional[str] = None,
           path: Optional[str] = None,
           namespace: Optional[str] = None)
func NewSecret(ctx *Context, name string, args SecretArgs, opts ...ResourceOption) (*Secret, error)
public Secret(string name, SecretArgs args, CustomResourceOptions? opts = null)
public Secret(String name, SecretArgs args)
public Secret(String name, SecretArgs args, CustomResourceOptions options)
type: vault:kv:Secret
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. SecretArgs
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. SecretArgs
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. SecretArgs
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. SecretArgs
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. SecretArgs
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 vaultSecretResource = new Vault.Kv.Secret("vaultSecretResource", new()
{
    DataJson = "string",
    Path = "string",
    Namespace = "string",
});
Copy
example, err := kv.NewSecret(ctx, "vaultSecretResource", &kv.SecretArgs{
	DataJson:  pulumi.String("string"),
	Path:      pulumi.String("string"),
	Namespace: pulumi.String("string"),
})
Copy
var vaultSecretResource = new Secret("vaultSecretResource", SecretArgs.builder()
    .dataJson("string")
    .path("string")
    .namespace("string")
    .build());
Copy
vault_secret_resource = vault.kv.Secret("vaultSecretResource",
    data_json="string",
    path="string",
    namespace="string")
Copy
const vaultSecretResource = new vault.kv.Secret("vaultSecretResource", {
    dataJson: "string",
    path: "string",
    namespace: "string",
});
Copy
type: vault:kv:Secret
properties:
    dataJson: string
    namespace: string
    path: string
Copy

Secret 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 Secret resource accepts the following input properties:

DataJson This property is required. string
JSON-encoded string that will be written as the secret data at the given path.
Path
This property is required.
Changes to this property will trigger replacement.
string
Full path of the KV-V1 secret.
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.
DataJson This property is required. string
JSON-encoded string that will be written as the secret data at the given path.
Path
This property is required.
Changes to this property will trigger replacement.
string
Full path of the KV-V1 secret.
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.
dataJson This property is required. String
JSON-encoded string that will be written as the secret data at the given path.
path
This property is required.
Changes to this property will trigger replacement.
String
Full path of the KV-V1 secret.
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.
dataJson This property is required. string
JSON-encoded string that will be written as the secret data at the given path.
path
This property is required.
Changes to this property will trigger replacement.
string
Full path of the KV-V1 secret.
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.
data_json This property is required. str
JSON-encoded string that will be written as the secret data at the given path.
path
This property is required.
Changes to this property will trigger replacement.
str
Full path of the KV-V1 secret.
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.
dataJson This property is required. String
JSON-encoded string that will be written as the secret data at the given path.
path
This property is required.
Changes to this property will trigger replacement.
String
Full path of the KV-V1 secret.
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 Secret resource produces the following output properties:

Data Dictionary<string, string>
A mapping whose keys are the top-level data keys returned from Vault and whose values are the corresponding values. This map can only represent string data, so any non-string values returned from Vault are serialized as JSON.
Id string
The provider-assigned unique ID for this managed resource.
Data map[string]string
A mapping whose keys are the top-level data keys returned from Vault and whose values are the corresponding values. This map can only represent string data, so any non-string values returned from Vault are serialized as JSON.
Id string
The provider-assigned unique ID for this managed resource.
data Map<String,String>
A mapping whose keys are the top-level data keys returned from Vault and whose values are the corresponding values. This map can only represent string data, so any non-string values returned from Vault are serialized as JSON.
id String
The provider-assigned unique ID for this managed resource.
data {[key: string]: string}
A mapping whose keys are the top-level data keys returned from Vault and whose values are the corresponding values. This map can only represent string data, so any non-string values returned from Vault are serialized as JSON.
id string
The provider-assigned unique ID for this managed resource.
data Mapping[str, str]
A mapping whose keys are the top-level data keys returned from Vault and whose values are the corresponding values. This map can only represent string data, so any non-string values returned from Vault are serialized as JSON.
id str
The provider-assigned unique ID for this managed resource.
data Map<String>
A mapping whose keys are the top-level data keys returned from Vault and whose values are the corresponding values. This map can only represent string data, so any non-string values returned from Vault are serialized as JSON.
id String
The provider-assigned unique ID for this managed resource.

Look up Existing Secret Resource

Get an existing Secret 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?: SecretState, opts?: CustomResourceOptions): Secret
@staticmethod
def get(resource_name: str,
        id: str,
        opts: Optional[ResourceOptions] = None,
        data: Optional[Mapping[str, str]] = None,
        data_json: Optional[str] = None,
        namespace: Optional[str] = None,
        path: Optional[str] = None) -> Secret
func GetSecret(ctx *Context, name string, id IDInput, state *SecretState, opts ...ResourceOption) (*Secret, error)
public static Secret Get(string name, Input<string> id, SecretState? state, CustomResourceOptions? opts = null)
public static Secret get(String name, Output<String> id, SecretState state, CustomResourceOptions options)
resources:  _:    type: vault:kv:Secret    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:
Data Dictionary<string, string>
A mapping whose keys are the top-level data keys returned from Vault and whose values are the corresponding values. This map can only represent string data, so any non-string values returned from Vault are serialized as JSON.
DataJson string
JSON-encoded string that will be written as the secret data at the given path.
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.
Path Changes to this property will trigger replacement. string
Full path of the KV-V1 secret.
Data map[string]string
A mapping whose keys are the top-level data keys returned from Vault and whose values are the corresponding values. This map can only represent string data, so any non-string values returned from Vault are serialized as JSON.
DataJson string
JSON-encoded string that will be written as the secret data at the given path.
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.
Path Changes to this property will trigger replacement. string
Full path of the KV-V1 secret.
data Map<String,String>
A mapping whose keys are the top-level data keys returned from Vault and whose values are the corresponding values. This map can only represent string data, so any non-string values returned from Vault are serialized as JSON.
dataJson String
JSON-encoded string that will be written as the secret data at the given path.
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.
path Changes to this property will trigger replacement. String
Full path of the KV-V1 secret.
data {[key: string]: string}
A mapping whose keys are the top-level data keys returned from Vault and whose values are the corresponding values. This map can only represent string data, so any non-string values returned from Vault are serialized as JSON.
dataJson string
JSON-encoded string that will be written as the secret data at the given path.
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.
path Changes to this property will trigger replacement. string
Full path of the KV-V1 secret.
data Mapping[str, str]
A mapping whose keys are the top-level data keys returned from Vault and whose values are the corresponding values. This map can only represent string data, so any non-string values returned from Vault are serialized as JSON.
data_json str
JSON-encoded string that will be written as the secret data at the given path.
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.
path Changes to this property will trigger replacement. str
Full path of the KV-V1 secret.
data Map<String>
A mapping whose keys are the top-level data keys returned from Vault and whose values are the corresponding values. This map can only represent string data, so any non-string values returned from Vault are serialized as JSON.
dataJson String
JSON-encoded string that will be written as the secret data at the given path.
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.
path Changes to this property will trigger replacement. String
Full path of the KV-V1 secret.

Import

KV-V1 secrets can be imported using the path, e.g.

$ pulumi import vault:kv/secret:Secret secret kvv1/secret
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.