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",
}),
});
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",
}))
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.Map{
"version": pulumi.Any("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
})
}
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",
}),
});
});
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());
}
}
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
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 string
- The unique name of the resource.
- args SecretArgs
- The arguments to resource properties.
- opts CustomResourceOptions
- Bag of options to control resource's behavior.
- resource_name str
- The unique name of the resource.
- args 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 string
- The unique name of the resource.
- args SecretArgs
- The arguments to resource properties.
- opts ResourceOption
- Bag of options to control resource's behavior.
- name string
- The unique name of the resource.
- args SecretArgs
- The arguments to resource properties.
- opts CustomResourceOptions
- Bag of options to control resource's behavior.
- name String
- The unique name of the resource.
- args 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",
});
example, err := kv.NewSecret(ctx, "vaultSecretResource", &kv.SecretArgs{
DataJson: pulumi.String("string"),
Path: pulumi.String("string"),
Namespace: pulumi.String("string"),
})
var vaultSecretResource = new Secret("vaultSecretResource", SecretArgs.builder()
.dataJson("string")
.path("string")
.namespace("string")
.build());
vault_secret_resource = vault.kv.Secret("vaultSecretResource",
data_json="string",
path="string",
namespace="string")
const vaultSecretResource = new vault.kv.Secret("vaultSecretResource", {
dataJson: "string",
path: "string",
namespace: "string",
});
type: vault:kv:Secret
properties:
dataJson: string
namespace: string
path: string
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
The Secret resource accepts the following input properties:
- Data
Json string - JSON-encoded string that will be written as the secret data at the given path.
- Path string
- Full path of the KV-V1 secret.
- Namespace 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 string - JSON-encoded string that will be written as the secret data at the given path.
- Path string
- Full path of the KV-V1 secret.
- Namespace 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 String - JSON-encoded string that will be written as the secret data at the given path.
- path String
- Full path of the KV-V1 secret.
- namespace 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 string - JSON-encoded string that will be written as the secret data at the given path.
- path string
- Full path of the KV-V1 secret.
- namespace 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 str - JSON-encoded string that will be written as the secret data at the given path.
- path str
- Full path of the KV-V1 secret.
- namespace 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.
- data
Json String - JSON-encoded string that will be written as the secret data at the given path.
- path String
- Full path of the KV-V1 secret.
- namespace 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, object>
- 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]interface{}
- 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,Object>
- 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]: any}
- 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, Any]
- 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<Any>
- 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, Any]] = 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)
Resource lookup is not supported in YAML
- name
- The unique name of the resulting resource.
- id
- 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
- The unique name of the resulting resource.
- id
- The unique provider ID of the resource to lookup.
- name
- The unique name of the resulting resource.
- id
- 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
- The unique name of the resulting resource.
- id
- 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
- The unique name of the resulting resource.
- id
- 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.
- Data Dictionary<string, object>
- 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 string - JSON-encoded string that will be written as the secret data at the given path.
- Namespace 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 string
- Full path of the KV-V1 secret.
- Data map[string]interface{}
- 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 string - JSON-encoded string that will be written as the secret data at the given path.
- Namespace 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 string
- Full path of the KV-V1 secret.
- data Map<String,Object>
- 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 String - JSON-encoded string that will be written as the secret data at the given path.
- namespace 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 String
- Full path of the KV-V1 secret.
- data {[key: string]: any}
- 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 string - JSON-encoded string that will be written as the secret data at the given path.
- namespace 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 string
- Full path of the KV-V1 secret.
- data Mapping[str, Any]
- 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 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 str
- Full path of the KV-V1 secret.
- data Map<Any>
- 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 String - JSON-encoded string that will be written as the secret data at the given path.
- namespace 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 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
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.