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

com.pulumi.gcp.compute.kotlin.InstanceGroupMembership.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.12.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.String
import kotlin.Suppress
import kotlin.Unit

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

    public var args: InstanceGroupMembershipArgs = InstanceGroupMembershipArgs()

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

/**
 * Represents the Instance membership to the Instance Group.
 * > **NOTE** You can use this resource instead of the `instances` field in the
 * `gcp.compute.InstanceGroup`, however it's not recommended to use it alongside this field.
 * It might cause inconsistencies, as they can end up competing over control.
 * > **NOTE** This resource has been added to avoid a situation, where after
 * Instance is recreated, it's removed from Instance Group and it's needed to
 * perform `apply` twice. To avoid situations like this, please use this resource
 * with the lifecycle `update_triggered_by` method, with the passed Instance's ID.
 * To get more information about InstanceGroupMembership, see:
 * * [API documentation](https://cloud.google.com/compute/docs/reference/rest/v1/instanceGroups)
 * * How-to Guides
 *     * [Add instances](https://cloud.google.com/compute/docs/reference/rest/v1/instanceGroups/addInstances)
 *     * [Remove instances](https://cloud.google.com/compute/docs/reference/rest/v1/instanceGroups/removeInstances)
 *     * [List instances](https://cloud.google.com/compute/docs/reference/rest/v1/instanceGroups/listInstances)
 * ## Example Usage
 * ### Instance Group Membership
 * 
 * ```typescript
 * import * as pulumi from "@pulumi/pulumi";
 * import * as gcp from "@pulumi/gcp";
 * const default_network = new gcp.compute.Network("default-network", {name: "network"});
 * const default_instance = new gcp.compute.Instance("default-instance", {
 *     name: "instance",
 *     machineType: "e2-medium",
 *     bootDisk: {
 *         initializeParams: {
 *             image: "debian-cloud/debian-11",
 *         },
 *     },
 *     networkInterfaces: [{
 *         network: default_network.name,
 *     }],
 * });
 * const default_instance_group = new gcp.compute.InstanceGroup("default-instance-group", {name: "instance-group"});
 * const default_ig_membership = new gcp.compute.InstanceGroupMembership("default-ig-membership", {
 *     instance: default_instance.selfLink,
 *     instanceGroup: default_instance_group.name,
 * });
 * ```
 * ```python
 * import pulumi
 * import pulumi_gcp as gcp
 * default_network = gcp.compute.Network("default-network", name="network")
 * default_instance = gcp.compute.Instance("default-instance",
 *     name="instance",
 *     machine_type="e2-medium",
 *     boot_disk=gcp.compute.InstanceBootDiskArgs(
 *         initialize_params=gcp.compute.InstanceBootDiskInitializeParamsArgs(
 *             image="debian-cloud/debian-11",
 *         ),
 *     ),
 *     network_interfaces=[gcp.compute.InstanceNetworkInterfaceArgs(
 *         network=default_network.name,
 *     )])
 * default_instance_group = gcp.compute.InstanceGroup("default-instance-group", name="instance-group")
 * default_ig_membership = gcp.compute.InstanceGroupMembership("default-ig-membership",
 *     instance=default_instance.self_link,
 *     instance_group=default_instance_group.name)
 * ```
 * ```csharp
 * using System.Collections.Generic;
 * using System.Linq;
 * using Pulumi;
 * using Gcp = Pulumi.Gcp;
 * return await Deployment.RunAsync(() =>
 * {
 *     var default_network = new Gcp.Compute.Network("default-network", new()
 *     {
 *         Name = "network",
 *     });
 *     var default_instance = new Gcp.Compute.Instance("default-instance", new()
 *     {
 *         Name = "instance",
 *         MachineType = "e2-medium",
 *         BootDisk = new Gcp.Compute.Inputs.InstanceBootDiskArgs
 *         {
 *             InitializeParams = new Gcp.Compute.Inputs.InstanceBootDiskInitializeParamsArgs
 *             {
 *                 Image = "debian-cloud/debian-11",
 *             },
 *         },
 *         NetworkInterfaces = new[]
 *         {
 *             new Gcp.Compute.Inputs.InstanceNetworkInterfaceArgs
 *             {
 *                 Network = default_network.Name,
 *             },
 *         },
 *     });
 *     var default_instance_group = new Gcp.Compute.InstanceGroup("default-instance-group", new()
 *     {
 *         Name = "instance-group",
 *     });
 *     var default_ig_membership = new Gcp.Compute.InstanceGroupMembership("default-ig-membership", new()
 *     {
 *         Instance = default_instance.SelfLink,
 *         InstanceGroup = default_instance_group.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 {
 * 		_, err := compute.NewNetwork(ctx, "default-network", &compute.NetworkArgs{
 * 			Name: pulumi.String("network"),
 * 		})
 * 		if err != nil {
 * 			return err
 * 		}
 * 		_, err = compute.NewInstance(ctx, "default-instance", &compute.InstanceArgs{
 * 			Name:        pulumi.String("instance"),
 * 			MachineType: pulumi.String("e2-medium"),
 * 			BootDisk: &compute.InstanceBootDiskArgs{
 * 				InitializeParams: &compute.InstanceBootDiskInitializeParamsArgs{
 * 					Image: pulumi.String("debian-cloud/debian-11"),
 * 				},
 * 			},
 * 			NetworkInterfaces: compute.InstanceNetworkInterfaceArray{
 * 				&compute.InstanceNetworkInterfaceArgs{
 * 					Network: default_network.Name,
 * 				},
 * 			},
 * 		})
 * 		if err != nil {
 * 			return err
 * 		}
 * 		_, err = compute.NewInstanceGroup(ctx, "default-instance-group", &compute.InstanceGroupArgs{
 * 			Name: pulumi.String("instance-group"),
 * 		})
 * 		if err != nil {
 * 			return err
 * 		}
 * 		_, err = compute.NewInstanceGroupMembership(ctx, "default-ig-membership", &compute.InstanceGroupMembershipArgs{
 * 			Instance:      default_instance.SelfLink,
 * 			InstanceGroup: default_instance_group.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.Network;
 * import com.pulumi.gcp.compute.NetworkArgs;
 * import com.pulumi.gcp.compute.Instance;
 * import com.pulumi.gcp.compute.InstanceArgs;
 * import com.pulumi.gcp.compute.inputs.InstanceBootDiskArgs;
 * import com.pulumi.gcp.compute.inputs.InstanceBootDiskInitializeParamsArgs;
 * import com.pulumi.gcp.compute.inputs.InstanceNetworkInterfaceArgs;
 * import com.pulumi.gcp.compute.InstanceGroup;
 * import com.pulumi.gcp.compute.InstanceGroupArgs;
 * import com.pulumi.gcp.compute.InstanceGroupMembership;
 * import com.pulumi.gcp.compute.InstanceGroupMembershipArgs;
 * 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 default_network = new Network("default-network", NetworkArgs.builder()
 *             .name("network")
 *             .build());
 *         var default_instance = new Instance("default-instance", InstanceArgs.builder()
 *             .name("instance")
 *             .machineType("e2-medium")
 *             .bootDisk(InstanceBootDiskArgs.builder()
 *                 .initializeParams(InstanceBootDiskInitializeParamsArgs.builder()
 *                     .image("debian-cloud/debian-11")
 *                     .build())
 *                 .build())
 *             .networkInterfaces(InstanceNetworkInterfaceArgs.builder()
 *                 .network(default_network.name())
 *                 .build())
 *             .build());
 *         var default_instance_group = new InstanceGroup("default-instance-group", InstanceGroupArgs.builder()
 *             .name("instance-group")
 *             .build());
 *         var default_ig_membership = new InstanceGroupMembership("default-ig-membership", InstanceGroupMembershipArgs.builder()
 *             .instance(default_instance.selfLink())
 *             .instanceGroup(default_instance_group.name())
 *             .build());
 *     }
 * }
 * ```
 * ```yaml
 * resources:
 *   default-network:
 *     type: gcp:compute:Network
 *     properties:
 *       name: network
 *   default-instance:
 *     type: gcp:compute:Instance
 *     properties:
 *       name: instance
 *       machineType: e2-medium
 *       bootDisk:
 *         initializeParams:
 *           image: debian-cloud/debian-11
 *       networkInterfaces:
 *         - network: ${["default-network"].name}
 *   default-instance-group:
 *     type: gcp:compute:InstanceGroup
 *     properties:
 *       name: instance-group
 *   default-ig-membership:
 *     type: gcp:compute:InstanceGroupMembership
 *     properties:
 *       instance: ${["default-instance"].selfLink}
 *       instanceGroup: ${["default-instance-group"].name}
 * ```
 * 
 * ## Import
 * InstanceGroupMembership can be imported using any of these accepted formats:
 * * `projects/{{project}}/zones/{{zone}}/instanceGroups/{{instance_group}}/{{instance}}`
 * * `{{project}}/{{zone}}/{{instance_group}}/{{instance}}`
 * * `{{zone}}/{{instance_group}}/{{instance}}`
 * * `{{instance_group}}/{{instance}}`
 * When using the `pulumi import` command, InstanceGroupMembership can be imported using one of the formats above. For example:
 * ```sh
 * $ pulumi import gcp:compute/instanceGroupMembership:InstanceGroupMembership default projects/{{project}}/zones/{{zone}}/instanceGroups/{{instance_group}}/{{instance}}
 * ```
 * ```sh
 * $ pulumi import gcp:compute/instanceGroupMembership:InstanceGroupMembership default {{project}}/{{zone}}/{{instance_group}}/{{instance}}
 * ```
 * ```sh
 * $ pulumi import gcp:compute/instanceGroupMembership:InstanceGroupMembership default {{zone}}/{{instance_group}}/{{instance}}
 * ```
 * ```sh
 * $ pulumi import gcp:compute/instanceGroupMembership:InstanceGroupMembership default {{instance_group}}/{{instance}}
 * ```
 */
public class InstanceGroupMembership internal constructor(
    override val javaResource: com.pulumi.gcp.compute.InstanceGroupMembership,
) : KotlinCustomResource(javaResource, InstanceGroupMembershipMapper) {
    /**
     * An instance being added to the InstanceGroup
     */
    public val instance: Output
        get() = javaResource.instance().applyValue({ args0 -> args0 })

    /**
     * Represents an Instance Group resource name that the instance belongs to.
     * - - -
     */
    public val instanceGroup: Output
        get() = javaResource.instanceGroup().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 })

    /**
     * A reference to the zone where the instance group resides.
     */
    public val zone: Output?
        get() = javaResource.zone().applyValue({ args0 -> args0.map({ args0 -> args0 }).orElse(null) })
}

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

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

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

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




© 2015 - 2025 Weber Informatics LLC | Privacy Policy