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

com.pulumi.random.kotlin.RandomString.kt Maven / Gradle / Ivy

@file:Suppress("NAME_SHADOWING", "DEPRECATION")

package com.pulumi.random.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.Boolean
import kotlin.Deprecated
import kotlin.Int
import kotlin.String
import kotlin.Suppress
import kotlin.Unit
import kotlin.collections.Map

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

    public var args: RandomStringArgs = RandomStringArgs()

    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 RandomStringArgsBuilder.() -> Unit) {
        val builder = RandomStringArgsBuilder()
        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.opts(block)
    }

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

/**
 * The resource `random.RandomString` generates a random permutation of alphanumeric characters and optionally special characters.
 * This resource *does* use a cryptographic random number generator.
 * Historically this resource's intended usage has been ambiguous as the original example used it in a password. For backwards compatibility it will continue to exist. For unique ids please use random_id, for sensitive random values please use random_password.
 * ## Example Usage
 * ```java
 * package generated_program;
 * import com.pulumi.Context;
 * import com.pulumi.Pulumi;
 * import com.pulumi.core.Output;
 * import com.pulumi.random.RandomString;
 * import com.pulumi.random.RandomStringArgs;
 * 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 random = new RandomString("random", RandomStringArgs.builder()
 *             .length(16)
 *             .overrideSpecial("/@£$")
 *             .special(true)
 *             .build());
 *     }
 * }
 * ```
 * ## Import
 * You can import external strings into your Pulumi programs as RandomString resources as follows:
 * ```sh
 *  $ import random:index/randomString:RandomString newString myspecialdata
 * ```
 * This command will encode the `myspecialdata` token in Pulumi state and generate a code suggestion to include a new RandomString resource in your Pulumi program. Include the suggested code and do a `pulumi up`. Your data is now stored in Pulumi, and you can reference it in your Pulumi program as `newString.result`.
 * If the data needs to be stored securily as a secret, consider using the RandomPassword resource instead.
 */
public class RandomString internal constructor(
    override val javaResource: com.pulumi.random.RandomString,
) : KotlinCustomResource(javaResource, RandomStringMapper) {
    /**
     * Arbitrary map of values that, when changed, will trigger recreation of resource. See the main provider documentation for more information.
     */
    public val keepers: Output>?
        get() = javaResource.keepers().applyValue({ args0 ->
            args0.map({ args0 ->
                args0.map({ args0 ->
                    args0.key.to(args0.value)
                }).toMap()
            }).orElse(null)
        })

    /**
     * The length of the string desired. The minimum value for length is 1 and, length must also be >= (`min_upper` + `min_lower` + `min_numeric` + `min_special`).
     */
    public val length: Output
        get() = javaResource.length().applyValue({ args0 -> args0 })

    /**
     * Include lowercase alphabet characters in the result. Default value is `true`.
     */
    public val lower: Output
        get() = javaResource.lower().applyValue({ args0 -> args0 })

    /**
     * Minimum number of lowercase alphabet characters in the result. Default value is `0`.
     */
    public val minLower: Output
        get() = javaResource.minLower().applyValue({ args0 -> args0 })

    /**
     * Minimum number of numeric characters in the result. Default value is `0`.
     */
    public val minNumeric: Output
        get() = javaResource.minNumeric().applyValue({ args0 -> args0 })

    /**
     * Minimum number of special characters in the result. Default value is `0`.
     */
    public val minSpecial: Output
        get() = javaResource.minSpecial().applyValue({ args0 -> args0 })

    /**
     * Minimum number of uppercase alphabet characters in the result. Default value is `0`.
     */
    public val minUpper: Output
        get() = javaResource.minUpper().applyValue({ args0 -> args0 })

    /**
     * Include numeric characters in the result. Default value is `true`. **NOTE**: This is deprecated, use `numeric` instead.
     */
    @Deprecated(
        message = """
  **NOTE**: This is deprecated, use `numeric` instead.
  """,
    )
    public val number: Output
        get() = javaResource.number().applyValue({ args0 -> args0 })

    /**
     * Include numeric characters in the result. Default value is `true`.
     */
    public val numeric: Output
        get() = javaResource.numeric().applyValue({ args0 -> args0 })

    /**
     * Supply your own list of special characters to use for string generation.  This overrides the default character list in the special argument.  The `special` argument must still be set to true for any overwritten characters to be used in generation.
     */
    public val overrideSpecial: Output?
        get() = javaResource.overrideSpecial().applyValue({ args0 ->
            args0.map({ args0 ->
                args0
            }).orElse(null)
        })

    /**
     * The generated random string.
     */
    public val result: Output
        get() = javaResource.result().applyValue({ args0 -> args0 })

    /**
     * Include special characters in the result. These are `!@#$%&*()-_=+[]{}<>:?`. Default value is `true`.
     */
    public val special: Output
        get() = javaResource.special().applyValue({ args0 -> args0 })

    /**
     * Include uppercase alphabet characters in the result. Default value is `true`.
     */
    public val upper: Output
        get() = javaResource.upper().applyValue({ args0 -> args0 })
}

public object RandomStringMapper : ResourceMapper {
    override fun supportsMappingOfType(javaResource: Resource): Boolean =
        com.pulumi.random.RandomString::class == javaResource::class

    override fun map(javaResource: Resource): RandomString = RandomString(
        javaResource as
            com.pulumi.random.RandomString,
    )
}

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

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




© 2015 - 2025 Weber Informatics LLC | Privacy Policy