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

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

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

    public var args: NetworkEndpointArgs = NetworkEndpointArgs()

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

/**
 * A Network endpoint represents a IP address and port combination that is
 * part of a specific network endpoint group (NEG). NEGs are zonal
 * collections of these endpoints for GCP resources within a
 * single subnet. **NOTE**: Network endpoints cannot be created outside of a
 * network endpoint group.
 * > **NOTE** In case the Endpoint's Instance is recreated, 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 NetworkEndpoint, see:
 * * [API documentation](https://cloud.google.com/compute/docs/reference/rest/beta/networkEndpointGroups)
 * * How-to Guides
 *     * [Official Documentation](https://cloud.google.com/load-balancing/docs/negs/)
 * ## Example Usage
 * ### Network Endpoint
 * 
 * ```typescript
 * import * as pulumi from "@pulumi/pulumi";
 * import * as gcp from "@pulumi/gcp";
 * const myImage = gcp.compute.getImage({
 *     family: "debian-11",
 *     project: "debian-cloud",
 * });
 * const _default = new gcp.compute.Network("default", {
 *     name: "neg-network",
 *     autoCreateSubnetworks: false,
 * });
 * const defaultSubnetwork = new gcp.compute.Subnetwork("default", {
 *     name: "neg-subnetwork",
 *     ipCidrRange: "10.0.0.1/16",
 *     region: "us-central1",
 *     network: _default.id,
 * });
 * const endpoint_instance = new gcp.compute.Instance("endpoint-instance", {
 *     networkInterfaces: [{
 *         accessConfigs: [{}],
 *         subnetwork: defaultSubnetwork.id,
 *     }],
 *     name: "endpoint-instance",
 *     machineType: "e2-medium",
 *     bootDisk: {
 *         initializeParams: {
 *             image: myImage.then(myImage => myImage.selfLink),
 *         },
 *     },
 * });
 * const default_endpoint = new gcp.compute.NetworkEndpoint("default-endpoint", {
 *     networkEndpointGroup: neg.name,
 *     instance: endpoint_instance.name,
 *     port: neg.defaultPort,
 *     ipAddress: endpoint_instance.networkInterfaces.apply(networkInterfaces => networkInterfaces[0].networkIp),
 * });
 * const group = new gcp.compute.NetworkEndpointGroup("group", {
 *     name: "my-lb-neg",
 *     network: _default.id,
 *     subnetwork: defaultSubnetwork.id,
 *     defaultPort: 90,
 *     zone: "us-central1-a",
 * });
 * ```
 * ```python
 * import pulumi
 * import pulumi_gcp as gcp
 * my_image = gcp.compute.get_image(family="debian-11",
 *     project="debian-cloud")
 * default = gcp.compute.Network("default",
 *     name="neg-network",
 *     auto_create_subnetworks=False)
 * default_subnetwork = gcp.compute.Subnetwork("default",
 *     name="neg-subnetwork",
 *     ip_cidr_range="10.0.0.1/16",
 *     region="us-central1",
 *     network=default.id)
 * endpoint_instance = gcp.compute.Instance("endpoint-instance",
 *     network_interfaces=[gcp.compute.InstanceNetworkInterfaceArgs(
 *         access_configs=[gcp.compute.InstanceNetworkInterfaceAccessConfigArgs()],
 *         subnetwork=default_subnetwork.id,
 *     )],
 *     name="endpoint-instance",
 *     machine_type="e2-medium",
 *     boot_disk=gcp.compute.InstanceBootDiskArgs(
 *         initialize_params=gcp.compute.InstanceBootDiskInitializeParamsArgs(
 *             image=my_image.self_link,
 *         ),
 *     ))
 * default_endpoint = gcp.compute.NetworkEndpoint("default-endpoint",
 *     network_endpoint_group=neg["name"],
 *     instance=endpoint_instance.name,
 *     port=neg["defaultPort"],
 *     ip_address=endpoint_instance.network_interfaces[0].network_ip)
 * group = gcp.compute.NetworkEndpointGroup("group",
 *     name="my-lb-neg",
 *     network=default.id,
 *     subnetwork=default_subnetwork.id,
 *     default_port=90,
 *     zone="us-central1-a")
 * ```
 * ```csharp
 * using System.Collections.Generic;
 * using System.Linq;
 * using Pulumi;
 * using Gcp = Pulumi.Gcp;
 * return await Deployment.RunAsync(() =>
 * {
 *     var myImage = Gcp.Compute.GetImage.Invoke(new()
 *     {
 *         Family = "debian-11",
 *         Project = "debian-cloud",
 *     });
 *     var @default = new Gcp.Compute.Network("default", new()
 *     {
 *         Name = "neg-network",
 *         AutoCreateSubnetworks = false,
 *     });
 *     var defaultSubnetwork = new Gcp.Compute.Subnetwork("default", new()
 *     {
 *         Name = "neg-subnetwork",
 *         IpCidrRange = "10.0.0.1/16",
 *         Region = "us-central1",
 *         Network = @default.Id,
 *     });
 *     var endpoint_instance = new Gcp.Compute.Instance("endpoint-instance", new()
 *     {
 *         NetworkInterfaces = new[]
 *         {
 *             new Gcp.Compute.Inputs.InstanceNetworkInterfaceArgs
 *             {
 *                 AccessConfigs = new[]
 *                 {
 *                     null,
 *                 },
 *                 Subnetwork = defaultSubnetwork.Id,
 *             },
 *         },
 *         Name = "endpoint-instance",
 *         MachineType = "e2-medium",
 *         BootDisk = new Gcp.Compute.Inputs.InstanceBootDiskArgs
 *         {
 *             InitializeParams = new Gcp.Compute.Inputs.InstanceBootDiskInitializeParamsArgs
 *             {
 *                 Image = myImage.Apply(getImageResult => getImageResult.SelfLink),
 *             },
 *         },
 *     });
 *     var default_endpoint = new Gcp.Compute.NetworkEndpoint("default-endpoint", new()
 *     {
 *         NetworkEndpointGroup = neg.Name,
 *         Instance = endpoint_instance.Name,
 *         Port = neg.DefaultPort,
 *         IpAddress = endpoint_instance.NetworkInterfaces.Apply(networkInterfaces => networkInterfaces[0].NetworkIp),
 *     });
 *     var @group = new Gcp.Compute.NetworkEndpointGroup("group", new()
 *     {
 *         Name = "my-lb-neg",
 *         Network = @default.Id,
 *         Subnetwork = defaultSubnetwork.Id,
 *         DefaultPort = 90,
 *         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 {
 * 		myImage, err := compute.LookupImage(ctx, &compute.LookupImageArgs{
 * 			Family:  pulumi.StringRef("debian-11"),
 * 			Project: pulumi.StringRef("debian-cloud"),
 * 		}, nil)
 * 		if err != nil {
 * 			return err
 * 		}
 * 		_, err = compute.NewNetwork(ctx, "default", &compute.NetworkArgs{
 * 			Name:                  pulumi.String("neg-network"),
 * 			AutoCreateSubnetworks: pulumi.Bool(false),
 * 		})
 * 		if err != nil {
 * 			return err
 * 		}
 * 		defaultSubnetwork, err := compute.NewSubnetwork(ctx, "default", &compute.SubnetworkArgs{
 * 			Name:        pulumi.String("neg-subnetwork"),
 * 			IpCidrRange: pulumi.String("10.0.0.1/16"),
 * 			Region:      pulumi.String("us-central1"),
 * 			Network:     _default.ID(),
 * 		})
 * 		if err != nil {
 * 			return err
 * 		}
 * 		_, err = compute.NewInstance(ctx, "endpoint-instance", &compute.InstanceArgs{
 * 			NetworkInterfaces: compute.InstanceNetworkInterfaceArray{
 * 				&compute.InstanceNetworkInterfaceArgs{
 * 					AccessConfigs: compute.InstanceNetworkInterfaceAccessConfigArray{
 * 						nil,
 * 					},
 * 					Subnetwork: defaultSubnetwork.ID(),
 * 				},
 * 			},
 * 			Name:        pulumi.String("endpoint-instance"),
 * 			MachineType: pulumi.String("e2-medium"),
 * 			BootDisk: &compute.InstanceBootDiskArgs{
 * 				InitializeParams: &compute.InstanceBootDiskInitializeParamsArgs{
 * 					Image: pulumi.String(myImage.SelfLink),
 * 				},
 * 			},
 * 		})
 * 		if err != nil {
 * 			return err
 * 		}
 * 		_, err = compute.NewNetworkEndpoint(ctx, "default-endpoint", &compute.NetworkEndpointArgs{
 * 			NetworkEndpointGroup: pulumi.Any(neg.Name),
 * 			Instance:             endpoint_instance.Name,
 * 			Port:                 pulumi.Any(neg.DefaultPort),
 * 			IpAddress: endpoint_instance.NetworkInterfaces.ApplyT(func(networkInterfaces []compute.InstanceNetworkInterface) (*string, error) {
 * 				return &networkInterfaces[0].NetworkIp, nil
 * 			}).(pulumi.StringPtrOutput),
 * 		})
 * 		if err != nil {
 * 			return err
 * 		}
 * 		_, err = compute.NewNetworkEndpointGroup(ctx, "group", &compute.NetworkEndpointGroupArgs{
 * 			Name:        pulumi.String("my-lb-neg"),
 * 			Network:     _default.ID(),
 * 			Subnetwork:  defaultSubnetwork.ID(),
 * 			DefaultPort: pulumi.Int(90),
 * 			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.ComputeFunctions;
 * import com.pulumi.gcp.compute.inputs.GetImageArgs;
 * import com.pulumi.gcp.compute.Network;
 * import com.pulumi.gcp.compute.NetworkArgs;
 * import com.pulumi.gcp.compute.Subnetwork;
 * import com.pulumi.gcp.compute.SubnetworkArgs;
 * import com.pulumi.gcp.compute.Instance;
 * import com.pulumi.gcp.compute.InstanceArgs;
 * import com.pulumi.gcp.compute.inputs.InstanceNetworkInterfaceArgs;
 * import com.pulumi.gcp.compute.inputs.InstanceBootDiskArgs;
 * import com.pulumi.gcp.compute.inputs.InstanceBootDiskInitializeParamsArgs;
 * import com.pulumi.gcp.compute.NetworkEndpoint;
 * import com.pulumi.gcp.compute.NetworkEndpointArgs;
 * import com.pulumi.gcp.compute.NetworkEndpointGroup;
 * import com.pulumi.gcp.compute.NetworkEndpointGroupArgs;
 * 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) {
 *         final var myImage = ComputeFunctions.getImage(GetImageArgs.builder()
 *             .family("debian-11")
 *             .project("debian-cloud")
 *             .build());
 *         var default_ = new Network("default", NetworkArgs.builder()
 *             .name("neg-network")
 *             .autoCreateSubnetworks(false)
 *             .build());
 *         var defaultSubnetwork = new Subnetwork("defaultSubnetwork", SubnetworkArgs.builder()
 *             .name("neg-subnetwork")
 *             .ipCidrRange("10.0.0.1/16")
 *             .region("us-central1")
 *             .network(default_.id())
 *             .build());
 *         var endpoint_instance = new Instance("endpoint-instance", InstanceArgs.builder()
 *             .networkInterfaces(InstanceNetworkInterfaceArgs.builder()
 *                 .accessConfigs()
 *                 .subnetwork(defaultSubnetwork.id())
 *                 .build())
 *             .name("endpoint-instance")
 *             .machineType("e2-medium")
 *             .bootDisk(InstanceBootDiskArgs.builder()
 *                 .initializeParams(InstanceBootDiskInitializeParamsArgs.builder()
 *                     .image(myImage.applyValue(getImageResult -> getImageResult.selfLink()))
 *                     .build())
 *                 .build())
 *             .build());
 *         var default_endpoint = new NetworkEndpoint("default-endpoint", NetworkEndpointArgs.builder()
 *             .networkEndpointGroup(neg.name())
 *             .instance(endpoint_instance.name())
 *             .port(neg.defaultPort())
 *             .ipAddress(endpoint_instance.networkInterfaces().applyValue(networkInterfaces -> networkInterfaces[0].networkIp()))
 *             .build());
 *         var group = new NetworkEndpointGroup("group", NetworkEndpointGroupArgs.builder()
 *             .name("my-lb-neg")
 *             .network(default_.id())
 *             .subnetwork(defaultSubnetwork.id())
 *             .defaultPort("90")
 *             .zone("us-central1-a")
 *             .build());
 *     }
 * }
 * ```
 * ```yaml
 * resources:
 *   default-endpoint:
 *     type: gcp:compute:NetworkEndpoint
 *     properties:
 *       networkEndpointGroup: ${neg.name}
 *       instance: ${["endpoint-instance"].name}
 *       port: ${neg.defaultPort}
 *       ipAddress: ${["endpoint-instance"].networkInterfaces[0].networkIp}
 *   endpoint-instance:
 *     type: gcp:compute:Instance
 *     properties:
 *       networkInterfaces:
 *         - accessConfigs:
 *             - {}
 *           subnetwork: ${defaultSubnetwork.id}
 *       name: endpoint-instance
 *       machineType: e2-medium
 *       bootDisk:
 *         initializeParams:
 *           image: ${myImage.selfLink}
 *   group:
 *     type: gcp:compute:NetworkEndpointGroup
 *     properties:
 *       name: my-lb-neg
 *       network: ${default.id}
 *       subnetwork: ${defaultSubnetwork.id}
 *       defaultPort: '90'
 *       zone: us-central1-a
 *   default:
 *     type: gcp:compute:Network
 *     properties:
 *       name: neg-network
 *       autoCreateSubnetworks: false
 *   defaultSubnetwork:
 *     type: gcp:compute:Subnetwork
 *     name: default
 *     properties:
 *       name: neg-subnetwork
 *       ipCidrRange: 10.0.0.1/16
 *       region: us-central1
 *       network: ${default.id}
 * variables:
 *   myImage:
 *     fn::invoke:
 *       Function: gcp:compute:getImage
 *       Arguments:
 *         family: debian-11
 *         project: debian-cloud
 * ```
 * 
 * ## Import
 * NetworkEndpoint can be imported using any of these accepted formats:
 * * `projects/{{project}}/zones/{{zone}}/networkEndpointGroups/{{network_endpoint_group}}/{{instance}}/{{ip_address}}/{{port}}`
 * * `{{project}}/{{zone}}/{{network_endpoint_group}}/{{instance}}/{{ip_address}}/{{port}}`
 * * `{{zone}}/{{network_endpoint_group}}/{{instance}}/{{ip_address}}/{{port}}`
 * * `{{network_endpoint_group}}/{{instance}}/{{ip_address}}/{{port}}`
 * When using the `pulumi import` command, NetworkEndpoint can be imported using one of the formats above. For example:
 * ```sh
 * $ pulumi import gcp:compute/networkEndpoint:NetworkEndpoint default projects/{{project}}/zones/{{zone}}/networkEndpointGroups/{{network_endpoint_group}}/{{instance}}/{{ip_address}}/{{port}}
 * ```
 * ```sh
 * $ pulumi import gcp:compute/networkEndpoint:NetworkEndpoint default {{project}}/{{zone}}/{{network_endpoint_group}}/{{instance}}/{{ip_address}}/{{port}}
 * ```
 * ```sh
 * $ pulumi import gcp:compute/networkEndpoint:NetworkEndpoint default {{zone}}/{{network_endpoint_group}}/{{instance}}/{{ip_address}}/{{port}}
 * ```
 * ```sh
 * $ pulumi import gcp:compute/networkEndpoint:NetworkEndpoint default {{network_endpoint_group}}/{{instance}}/{{ip_address}}/{{port}}
 * ```
 */
public class NetworkEndpoint internal constructor(
    override val javaResource: com.pulumi.gcp.compute.NetworkEndpoint,
) : KotlinCustomResource(javaResource, NetworkEndpointMapper) {
    /**
     * The name for a specific VM instance that the IP address belongs to.
     * This is required for network endpoints of type GCE_VM_IP_PORT.
     * The instance must be in the same zone of network endpoint group.
     */
    public val instance: Output?
        get() = javaResource.instance().applyValue({ args0 -> args0.map({ args0 -> args0 }).orElse(null) })

    /**
     * IPv4 address of network endpoint. The IP address must belong
     * to a VM in GCE (either the primary IP or as part of an aliased IP
     * range).
     */
    public val ipAddress: Output
        get() = javaResource.ipAddress().applyValue({ args0 -> args0 })

    /**
     * The network endpoint group this endpoint is part of.
     * - - -
     */
    public val networkEndpointGroup: Output
        get() = javaResource.networkEndpointGroup().applyValue({ args0 -> args0 })

    /**
     * Port number of network endpoint.
     * **Note** `port` is required unless the Network Endpoint Group is created
     * with the type of `GCE_VM_IP`
     */
    public val port: Output?
        get() = javaResource.port().applyValue({ args0 -> args0.map({ args0 -> args0 }).orElse(null) })

    /**
     * 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 })

    /**
     * Zone where the containing network endpoint group is located.
     */
    public val zone: Output
        get() = javaResource.zone().applyValue({ args0 -> args0 })
}

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

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

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

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




© 2015 - 2024 Weber Informatics LLC | Privacy Policy