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

com.pulumi.gcp.compute.kotlin.InstanceGroup.kt Maven / Gradle / Ivy

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

package com.pulumi.gcp.compute.kotlin

import com.pulumi.core.Output
import com.pulumi.gcp.compute.kotlin.outputs.InstanceGroupNamedPort
import com.pulumi.gcp.compute.kotlin.outputs.InstanceGroupNamedPort.Companion.toKotlin
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.List

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

    public var args: InstanceGroupArgs = InstanceGroupArgs()

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

/**
 * Creates a group of dissimilar Compute Engine virtual machine instances.
 * For more information, see [the official documentation](https://cloud.google.com/compute/docs/instance-groups/#unmanaged_instance_groups)
 * and [API](https://cloud.google.com/compute/docs/reference/latest/instanceGroups)
 * ## Example Usage
 * ### Empty Instance Group
 * 
 * ```typescript
 * import * as pulumi from "@pulumi/pulumi";
 * import * as gcp from "@pulumi/gcp";
 * const test = new gcp.compute.InstanceGroup("test", {
 *     name: "test",
 *     description: "Test instance group",
 *     zone: "us-central1-a",
 *     network: _default.id,
 * });
 * ```
 * ```python
 * import pulumi
 * import pulumi_gcp as gcp
 * test = gcp.compute.InstanceGroup("test",
 *     name="test",
 *     description="Test instance group",
 *     zone="us-central1-a",
 *     network=default["id"])
 * ```
 * ```csharp
 * using System.Collections.Generic;
 * using System.Linq;
 * using Pulumi;
 * using Gcp = Pulumi.Gcp;
 * return await Deployment.RunAsync(() =>
 * {
 *     var test = new Gcp.Compute.InstanceGroup("test", new()
 *     {
 *         Name = "test",
 *         Description = "Test instance group",
 *         Zone = "us-central1-a",
 *         Network = @default.Id,
 *     });
 * });
 * ```
 * ```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 {
 * 		_, err := compute.NewInstanceGroup(ctx, "test", &compute.InstanceGroupArgs{
 * 			Name:        pulumi.String("test"),
 * 			Description: pulumi.String("Test instance group"),
 * 			Zone:        pulumi.String("us-central1-a"),
 * 			Network:     pulumi.Any(_default.Id),
 * 		})
 * 		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.InstanceGroup;
 * import com.pulumi.gcp.compute.InstanceGroupArgs;
 * 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 test = new InstanceGroup("test", InstanceGroupArgs.builder()
 *             .name("test")
 *             .description("Test instance group")
 *             .zone("us-central1-a")
 *             .network(default_.id())
 *             .build());
 *     }
 * }
 * ```
 * ```yaml
 * resources:
 *   test:
 *     type: gcp:compute:InstanceGroup
 *     properties:
 *       name: test
 *       description: Test instance group
 *       zone: us-central1-a
 *       network: ${default.id}
 * ```
 * 
 * ### Example Usage - With instances and named ports
 * 
 * ```typescript
 * import * as pulumi from "@pulumi/pulumi";
 * import * as gcp from "@pulumi/gcp";
 * const webservers = new gcp.compute.InstanceGroup("webservers", {
 *     name: "webservers",
 *     description: "Test instance group",
 *     instances: [
 *         test.id,
 *         test2.id,
 *     ],
 *     namedPorts: [
 *         {
 *             name: "http",
 *             port: 8080,
 *         },
 *         {
 *             name: "https",
 *             port: 8443,
 *         },
 *     ],
 *     zone: "us-central1-a",
 * });
 * ```
 * ```python
 * import pulumi
 * import pulumi_gcp as gcp
 * webservers = gcp.compute.InstanceGroup("webservers",
 *     name="webservers",
 *     description="Test instance group",
 *     instances=[
 *         test["id"],
 *         test2["id"],
 *     ],
 *     named_ports=[
 *         {
 *             "name": "http",
 *             "port": 8080,
 *         },
 *         {
 *             "name": "https",
 *             "port": 8443,
 *         },
 *     ],
 *     zone="us-central1-a")
 * ```
 * ```csharp
 * using System.Collections.Generic;
 * using System.Linq;
 * using Pulumi;
 * using Gcp = Pulumi.Gcp;
 * return await Deployment.RunAsync(() =>
 * {
 *     var webservers = new Gcp.Compute.InstanceGroup("webservers", new()
 *     {
 *         Name = "webservers",
 *         Description = "Test instance group",
 *         Instances = new[]
 *         {
 *             test.Id,
 *             test2.Id,
 *         },
 *         NamedPorts = new[]
 *         {
 *             new Gcp.Compute.Inputs.InstanceGroupNamedPortArgs
 *             {
 *                 Name = "http",
 *                 Port = 8080,
 *             },
 *             new Gcp.Compute.Inputs.InstanceGroupNamedPortArgs
 *             {
 *                 Name = "https",
 *                 Port = 8443,
 *             },
 *         },
 *         Zone = "us-central1-a",
 *     });
 * });
 * ```
 * ```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 {
 * 		_, err := compute.NewInstanceGroup(ctx, "webservers", &compute.InstanceGroupArgs{
 * 			Name:        pulumi.String("webservers"),
 * 			Description: pulumi.String("Test instance group"),
 * 			Instances: pulumi.StringArray{
 * 				test.Id,
 * 				test2.Id,
 * 			},
 * 			NamedPorts: compute.InstanceGroupNamedPortTypeArray{
 * 				&compute.InstanceGroupNamedPortTypeArgs{
 * 					Name: pulumi.String("http"),
 * 					Port: pulumi.Int(8080),
 * 				},
 * 				&compute.InstanceGroupNamedPortTypeArgs{
 * 					Name: pulumi.String("https"),
 * 					Port: pulumi.Int(8443),
 * 				},
 * 			},
 * 			Zone: pulumi.String("us-central1-a"),
 * 		})
 * 		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.InstanceGroup;
 * import com.pulumi.gcp.compute.InstanceGroupArgs;
 * import com.pulumi.gcp.compute.inputs.InstanceGroupNamedPortArgs;
 * 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 webservers = new InstanceGroup("webservers", InstanceGroupArgs.builder()
 *             .name("webservers")
 *             .description("Test instance group")
 *             .instances(
 *                 test.id(),
 *                 test2.id())
 *             .namedPorts(
 *                 InstanceGroupNamedPortArgs.builder()
 *                     .name("http")
 *                     .port("8080")
 *                     .build(),
 *                 InstanceGroupNamedPortArgs.builder()
 *                     .name("https")
 *                     .port("8443")
 *                     .build())
 *             .zone("us-central1-a")
 *             .build());
 *     }
 * }
 * ```
 * ```yaml
 * resources:
 *   webservers:
 *     type: gcp:compute:InstanceGroup
 *     properties:
 *       name: webservers
 *       description: Test instance group
 *       instances:
 *         - ${test.id}
 *         - ${test2.id}
 *       namedPorts:
 *         - name: http
 *           port: '8080'
 *         - name: https
 *           port: '8443'
 *       zone: us-central1-a
 * ```
 * 
 * ## Import
 * Instance groups can be imported using the `zone` and `name` with an optional `project`, e.g.
 * * `projects/{{project_id}}/zones/{{zone}}/instanceGroups/{{instance_group_id}}`
 * * `{{project_id}}/{{zone}}/{{instance_group_id}}`
 * * `{{zone}}/{{instance_group_id}}`
 * When using the `pulumi import` command, instance groups can be imported using one of the formats above. For example:
 * ```sh
 * $ pulumi import gcp:compute/instanceGroup:InstanceGroup default {{zone}}/{{instance_group_id}}
 * ```
 * ```sh
 * $ pulumi import gcp:compute/instanceGroup:InstanceGroup default {{project_id}}/{{zone}}/{{instance_group_id}}
 * ```
 * ```sh
 * $ pulumi import gcp:compute/instanceGroup:InstanceGroup default projects/{{project_id}}/zones/{{zone}}/instanceGroups/{{instance_group_id}}
 * ```
 */
public class InstanceGroup internal constructor(
    override val javaResource: com.pulumi.gcp.compute.InstanceGroup,
) : KotlinCustomResource(javaResource, InstanceGroupMapper) {
    /**
     * An optional textual description of the instance
     * group.
     */
    public val description: Output?
        get() = javaResource.description().applyValue({ args0 ->
            args0.map({ args0 ->
                args0
            }).orElse(null)
        })

    /**
     * The list of instances in the group, in `self_link` format.
     * When adding instances they must all be in the same network and zone as the instance group.
     */
    public val instances: Output>
        get() = javaResource.instances().applyValue({ args0 -> args0.map({ args0 -> args0 }) })

    /**
     * The name of the instance group. Must be 1-63
     * characters long and comply with
     * [RFC1035](https://www.ietf.org/rfc/rfc1035.txt). Supported characters
     * include lowercase letters, numbers, and hyphens.
     */
    public val name: Output
        get() = javaResource.name().applyValue({ args0 -> args0 })

    /**
     * The named port configuration. See the section below
     * for details on configuration. Structure is documented below.
     */
    public val namedPorts: Output>?
        get() = javaResource.namedPorts().applyValue({ args0 ->
            args0.map({ args0 ->
                args0.map({ args0 ->
                    args0.let({ args0 -> toKotlin(args0) })
                })
            }).orElse(null)
        })

    /**
     * The URL of the network the instance group is in. If
     * this is different from the network where the instances are in, the creation
     * fails. Defaults to the network where the instances are in (if neither
     * `network` nor `instances` is specified, this field will be blank).
     */
    public val network: Output
        get() = javaResource.network().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 })

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

    /**
     * The number of instances in the group.
     */
    public val size: Output
        get() = javaResource.size().applyValue({ args0 -> args0 })

    /**
     * The zone that this instance group should be created in.
     * - - -
     */
    public val zone: Output
        get() = javaResource.zone().applyValue({ args0 -> args0 })
}

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

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

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

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




© 2015 - 2024 Weber Informatics LLC | Privacy Policy