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

com.pulumi.random.kotlin.RandomPet.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: 4.16.6.0
Show newest version
@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.Int
import kotlin.String
import kotlin.Suppress
import kotlin.Unit
import kotlin.collections.Map

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

    public var args: RandomPetArgs = RandomPetArgs()

    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 RandomPetArgsBuilder.() -> Unit) {
        val builder = RandomPetArgsBuilder()
        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(): RandomPet {
        val builtJavaResource = com.pulumi.random.RandomPet(
            this.name,
            this.args.toJava(),
            this.opts.toJava(),
        )
        return RandomPet(builtJavaResource)
    }
}

/**
 * The resource `random.RandomPet` generates random pet names that are intended to be used as unique identifiers for other resources.
 * This resource can be used in conjunction with resources that have the `create_before_destroy` lifecycle flag set, to avoid conflicts with unique names during the brief period where both the old and new resources exist concurrently.
 * ## Example Usage
 * ```java
 * package generated_program;
 * import com.pulumi.Context;
 * import com.pulumi.Pulumi;
 * import com.pulumi.core.Output;
 * import com.pulumi.random.RandomPet;
 * import com.pulumi.random.RandomPetArgs;
 * import com.pulumi.aws.ec2.Instance;
 * import com.pulumi.aws.ec2.InstanceArgs;
 * 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 serverRandomPet = new RandomPet("serverRandomPet", RandomPetArgs.builder()
 *             .keepers(Map.of("ami_id", var_.ami_id()))
 *             .build());
 *         var serverInstance = new Instance("serverInstance", InstanceArgs.builder()
 *             .tags(Map.of("Name", serverRandomPet.id().applyValue(id -> String.format("web-server-%s", id))))
 *             .ami(serverRandomPet.keepers().applyValue(keepers -> keepers.amiId()))
 *             .build());
 *     }
 * }
 * ```
 */
public class RandomPet internal constructor(
    override val javaResource: com.pulumi.random.RandomPet,
) : KotlinCustomResource(javaResource, RandomPetMapper) {
    /**
     * 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 (in words) of the pet name. Defaults to 2
     */
    public val length: Output
        get() = javaResource.length().applyValue({ args0 -> args0 })

    /**
     * A string to prefix the name with.
     */
    public val prefix: Output?
        get() = javaResource.prefix().applyValue({ args0 -> args0.map({ args0 -> args0 }).orElse(null) })

    /**
     * The character to separate words in the pet name. Defaults to "-"
     */
    public val separator: Output
        get() = javaResource.separator().applyValue({ args0 -> args0 })
}

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

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

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

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




© 2015 - 2024 Weber Informatics LLC | Privacy Policy