All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.pulumi.vault.kv.kotlin.Secret.kt Maven / Gradle / Ivy

Go to download

Build cloud applications and infrastructure by combining the safety and reliability of infrastructure as code with the power of the Kotlin programming language.

There is a newer version: 6.6.0.0
Show newest version
@file:Suppress("NAME_SHADOWING", "DEPRECATION")

package com.pulumi.vault.kv.kotlin

import com.pulumi.core.Output
import com.pulumi.kotlin.KotlinCustomResource
import com.pulumi.kotlin.PulumiTagMarker
import com.pulumi.kotlin.ResourceMapper
import com.pulumi.kotlin.options.CustomResourceOptions
import com.pulumi.kotlin.options.CustomResourceOptionsBuilder
import com.pulumi.resources.Resource
import kotlin.Any
import kotlin.Boolean
import kotlin.String
import kotlin.Suppress
import kotlin.Unit
import kotlin.collections.Map

/**
 * Builder for [Secret].
 */
@PulumiTagMarker
public class SecretResourceBuilder internal constructor() {
    public var name: String? = null

    public var args: SecretArgs = SecretArgs()

    public var opts: CustomResourceOptions = CustomResourceOptions()

    /**
     * @param name The _unique_ name of the resulting resource.
     */
    public fun name(`value`: String) {
        this.name = value
    }

    /**
     * @param block The arguments to use to populate this resource's properties.
     */
    public suspend fun args(block: suspend SecretArgsBuilder.() -> Unit) {
        val builder = SecretArgsBuilder()
        block(builder)
        this.args = builder.build()
    }

    /**
     * @param block A bag of options that control this resource's behavior.
     */
    public suspend fun opts(block: suspend CustomResourceOptionsBuilder.() -> Unit) {
        this.opts = com.pulumi.kotlin.options.CustomResourceOptions.opts(block)
    }

    internal fun build(): Secret {
        val builtJavaResource = com.pulumi.vault.kv.Secret(
            this.name,
            this.args.toJava(),
            this.opts.toJava(),
        )
        return Secret(builtJavaResource)
    }
}

/**
 * Writes a KV-V1 secret to a given path in Vault.
 * For more information on Vault's KV-V1 secret backend
 * [see here](https://www.vaultproject.io/docs/secrets/kv/kv-v1).
 * ## Example Usage
 * 
 * ```typescript
 * 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",
 *     }),
 * });
 * ```
 * ```python
 * 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",
 *     }))
 * ```
 * ```csharp
 * 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
 *         {
 *             ["zip"] = "zap",
 *             ["foo"] = "bar",
 *         }),
 *     });
 * });
 * ```
 * ```go
 * 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
 * 	})
 * }
 * ```
 * ```java
 * 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());
 *     }
 * }
 * ```
 * ```yaml
 * 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).
 * ## Import
 * KV-V1 secrets can be imported using the `path`, e.g.
 * ```sh
 * $ pulumi import vault:kv/secret:Secret secret kvv1/secret
 * ```
 */
public class Secret internal constructor(
    override val javaResource: com.pulumi.vault.kv.Secret,
) : KotlinCustomResource(javaResource, SecretMapper) {
    /**
     * 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.
     */
    public val `data`: Output>
        get() = javaResource.`data`().applyValue({ args0 ->
            args0.map({ args0 ->
                args0.key.to(args0.value)
            }).toMap()
        })

    /**
     * JSON-encoded string that will be
     * written as the secret data at the given path.
     */
    public val dataJson: Output
        get() = javaResource.dataJson().applyValue({ args0 -> args0 })

    /**
     * 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](https://www.terraform.io/docs/providers/vault/index.html#namespace).
     * *Available only for Vault Enterprise*.
     */
    public val namespace: Output?
        get() = javaResource.namespace().applyValue({ args0 -> args0.map({ args0 -> args0 }).orElse(null) })

    /**
     * Full path of the KV-V1 secret.
     */
    public val path: Output
        get() = javaResource.path().applyValue({ args0 -> args0 })
}

public object SecretMapper : ResourceMapper {
    override fun supportsMappingOfType(javaResource: Resource): Boolean =
        com.pulumi.vault.kv.Secret::class == javaResource::class

    override fun map(javaResource: Resource): Secret = Secret(
        javaResource as
            com.pulumi.vault.kv.Secret,
    )
}

/**
 * @see [Secret].
 * @param name The _unique_ name of the resulting resource.
 * @param block Builder for [Secret].
 */
public suspend fun secret(name: String, block: suspend SecretResourceBuilder.() -> Unit): Secret {
    val builder = SecretResourceBuilder()
    builder.name(name)
    block(builder)
    return builder.build()
}

/**
 * @see [Secret].
 * @param name The _unique_ name of the resulting resource.
 */
public fun secret(name: String): Secret {
    val builder = SecretResourceBuilder()
    builder.name(name)
    return builder.build()
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy