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

com.pulumi.gcp.compute.kotlin.TargetPool.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: 8.10.0.0
Show newest version
@file:Suppress("NAME_SHADOWING", "DEPRECATION")

package com.pulumi.gcp.compute.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.Double
import kotlin.String
import kotlin.Suppress
import kotlin.Unit
import kotlin.collections.List

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

    public var args: TargetPoolArgs = TargetPoolArgs()

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

/**
 * Manages a Target Pool within GCE. This is a collection of instances used as
 * target of a network load balancer (Forwarding Rule). For more information see
 * [the official
 * documentation](https://cloud.google.com/compute/docs/load-balancing/network/target-pools)
 * and [API](https://cloud.google.com/compute/docs/reference/latest/targetPools).
 * ## Example Usage
 * 
 * ```typescript
 * import * as pulumi from "@pulumi/pulumi";
 * import * as gcp from "@pulumi/gcp";
 * const defaultHttpHealthCheck = new gcp.compute.HttpHealthCheck("default", {
 *     name: "default",
 *     requestPath: "/",
 *     checkIntervalSec: 1,
 *     timeoutSec: 1,
 * });
 * const _default = new gcp.compute.TargetPool("default", {
 *     name: "instance-pool",
 *     instances: [
 *         "us-central1-a/myinstance1",
 *         "us-central1-b/myinstance2",
 *     ],
 *     healthChecks: defaultHttpHealthCheck.name,
 * });
 * ```
 * ```python
 * import pulumi
 * import pulumi_gcp as gcp
 * default_http_health_check = gcp.compute.HttpHealthCheck("default",
 *     name="default",
 *     request_path="/",
 *     check_interval_sec=1,
 *     timeout_sec=1)
 * default = gcp.compute.TargetPool("default",
 *     name="instance-pool",
 *     instances=[
 *         "us-central1-a/myinstance1",
 *         "us-central1-b/myinstance2",
 *     ],
 *     health_checks=default_http_health_check.name)
 * ```
 * ```csharp
 * using System.Collections.Generic;
 * using System.Linq;
 * using Pulumi;
 * using Gcp = Pulumi.Gcp;
 * return await Deployment.RunAsync(() =>
 * {
 *     var defaultHttpHealthCheck = new Gcp.Compute.HttpHealthCheck("default", new()
 *     {
 *         Name = "default",
 *         RequestPath = "/",
 *         CheckIntervalSec = 1,
 *         TimeoutSec = 1,
 *     });
 *     var @default = new Gcp.Compute.TargetPool("default", new()
 *     {
 *         Name = "instance-pool",
 *         Instances = new[]
 *         {
 *             "us-central1-a/myinstance1",
 *             "us-central1-b/myinstance2",
 *         },
 *         HealthChecks = defaultHttpHealthCheck.Name,
 *     });
 * });
 * ```
 * ```go
 * package main
 * import (
 * 	"github.com/pulumi/pulumi-gcp/sdk/v7/go/gcp/compute"
 * 	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
 * )
 * func main() {
 * 	pulumi.Run(func(ctx *pulumi.Context) error {
 * 		defaultHttpHealthCheck, err := compute.NewHttpHealthCheck(ctx, "default", &compute.HttpHealthCheckArgs{
 * 			Name:             pulumi.String("default"),
 * 			RequestPath:      pulumi.String("/"),
 * 			CheckIntervalSec: pulumi.Int(1),
 * 			TimeoutSec:       pulumi.Int(1),
 * 		})
 * 		if err != nil {
 * 			return err
 * 		}
 * 		_, err = compute.NewTargetPool(ctx, "default", &compute.TargetPoolArgs{
 * 			Name: pulumi.String("instance-pool"),
 * 			Instances: pulumi.StringArray{
 * 				pulumi.String("us-central1-a/myinstance1"),
 * 				pulumi.String("us-central1-b/myinstance2"),
 * 			},
 * 			HealthChecks: defaultHttpHealthCheck.Name,
 * 		})
 * 		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.gcp.compute.HttpHealthCheck;
 * import com.pulumi.gcp.compute.HttpHealthCheckArgs;
 * import com.pulumi.gcp.compute.TargetPool;
 * import com.pulumi.gcp.compute.TargetPoolArgs;
 * 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 defaultHttpHealthCheck = new HttpHealthCheck("defaultHttpHealthCheck", HttpHealthCheckArgs.builder()
 *             .name("default")
 *             .requestPath("/")
 *             .checkIntervalSec(1)
 *             .timeoutSec(1)
 *             .build());
 *         var default_ = new TargetPool("default", TargetPoolArgs.builder()
 *             .name("instance-pool")
 *             .instances(
 *                 "us-central1-a/myinstance1",
 *                 "us-central1-b/myinstance2")
 *             .healthChecks(defaultHttpHealthCheck.name())
 *             .build());
 *     }
 * }
 * ```
 * ```yaml
 * resources:
 *   default:
 *     type: gcp:compute:TargetPool
 *     properties:
 *       name: instance-pool
 *       instances:
 *         - us-central1-a/myinstance1
 *         - us-central1-b/myinstance2
 *       healthChecks: ${defaultHttpHealthCheck.name}
 *   defaultHttpHealthCheck:
 *     type: gcp:compute:HttpHealthCheck
 *     name: default
 *     properties:
 *       name: default
 *       requestPath: /
 *       checkIntervalSec: 1
 *       timeoutSec: 1
 * ```
 * 
 * ## Import
 * Target pools can be imported using any of the following formats:
 * * `projects/{{project}}/regions/{{region}}/targetPools/{{name}}`
 * * `{{project}}/{{region}}/{{name}}`
 * * `{{region}}/{{name}}`
 * * `{{name}}`
 * When using the `pulumi import` command, target pools can be imported using one of the formats above. For example:
 * ```sh
 * $ pulumi import gcp:compute/targetPool:TargetPool default projects/{{project}}/regions/{{region}}/targetPools/{{name}}
 * ```
 * ```sh
 * $ pulumi import gcp:compute/targetPool:TargetPool default {{project}}/{{region}}/{{name}}
 * ```
 * ```sh
 * $ pulumi import gcp:compute/targetPool:TargetPool default {{region}}/{{name}}
 * ```
 * ```sh
 * $ pulumi import gcp:compute/targetPool:TargetPool default {{name}}
 * ```
 */
public class TargetPool internal constructor(
    override val javaResource: com.pulumi.gcp.compute.TargetPool,
) : KotlinCustomResource(javaResource, TargetPoolMapper) {
    /**
     * URL to the backup target pool. Must also set
     * failover_ratio.
     */
    public val backupPool: Output?
        get() = javaResource.backupPool().applyValue({ args0 ->
            args0.map({ args0 ->
                args0
            }).orElse(null)
        })

    /**
     * Textual description field.
     */
    public val description: Output?
        get() = javaResource.description().applyValue({ args0 ->
            args0.map({ args0 ->
                args0
            }).orElse(null)
        })

    /**
     * Ratio (0 to 1) of failed nodes before using the
     * backup pool (which must also be set).
     */
    public val failoverRatio: Output?
        get() = javaResource.failoverRatio().applyValue({ args0 ->
            args0.map({ args0 ->
                args0
            }).orElse(null)
        })

    /**
     * List of zero or one health check name or self_link. Only
     * legacy `gcp.compute.HttpHealthCheck` is supported.
     */
    public val healthChecks: Output?
        get() = javaResource.healthChecks().applyValue({ args0 ->
            args0.map({ args0 ->
                args0
            }).orElse(null)
        })

    /**
     * List of instances in the pool. They can be given as
     * URLs, or in the form of "zone/name". Note that the instances need not exist
     * at the time of target pool creation, so there is no need to use the
     * interpolation to create a dependency on the instances from the
     * target pool.
     */
    public val instances: Output>
        get() = javaResource.instances().applyValue({ args0 -> args0.map({ args0 -> args0 }) })

    /**
     * A unique name for the resource, required by GCE. Changing
     * this forces a new resource to be created.
     * - - -
     */
    public val name: Output
        get() = javaResource.name().applyValue({ args0 -> args0 })

    /**
     * The ID of the project in which the resource belongs. If it
     * is not provided, the provider project is used.
     */
    public val project: Output
        get() = javaResource.project().applyValue({ args0 -> args0 })

    /**
     * Where the target pool resides. Defaults to project
     * region.
     */
    public val region: Output
        get() = javaResource.region().applyValue({ args0 -> args0 })

    /**
     * The resource URL for the security policy associated with this target pool.
     */
    public val securityPolicy: Output?
        get() = javaResource.securityPolicy().applyValue({ args0 ->
            args0.map({ args0 ->
                args0
            }).orElse(null)
        })

    /**
     * The URI of the created resource.
     */
    public val selfLink: Output
        get() = javaResource.selfLink().applyValue({ args0 -> args0 })

    /**
     * How to distribute load. Options are "NONE" (no
     * affinity). "CLIENT_IP" (hash of the source/dest addresses / ports), and
     * "CLIENT_IP_PROTO" also includes the protocol (default "NONE").
     */
    public val sessionAffinity: Output?
        get() = javaResource.sessionAffinity().applyValue({ args0 ->
            args0.map({ args0 ->
                args0
            }).orElse(null)
        })
}

public object TargetPoolMapper : ResourceMapper {
    override fun supportsMappingOfType(javaResource: Resource): Boolean =
        com.pulumi.gcp.compute.TargetPool::class == javaResource::class

    override fun map(javaResource: Resource): TargetPool = TargetPool(
        javaResource as
            com.pulumi.gcp.compute.TargetPool,
    )
}

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

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




© 2015 - 2024 Weber Informatics LLC | Privacy Policy