Skip to content

googleComputeNetworkEndpointGroup

Network endpoint groups (NEGs) are zonal resources that represent collections of IP address and port combinations for GCP resources within a single subnet. Each IP address and port combination is called a network endpoint.

Network endpoint groups can be used as backends in backend services for HTTP(S), TCP proxy, and SSL proxy load balancers. You cannot use NEGs as a backend with internal load balancers. Because NEG backends allow you to specify IP addresses and ports, you can distribute traffic in a granular fashion among applications or containers running within VM instances.

Recreating a network endpoint group that's in use by another resource will give a resourceInUseByAnotherResource error. Use lifecycleCreateBeforeDestroy to avoid this type of error.

To get more information about NetworkEndpointGroup, see:

Example Usage - Network Endpoint Group

/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as google from "./.gen/providers/google";
/*The following providers are missing schema information and might need manual adjustments to synthesize correctly: google.
For a more precise conversion please use the --provider flag in convert.*/
const googleComputeNetworkDefault = new google.computeNetwork.ComputeNetwork(
  this,
  "default",
  {
    auto_create_subnetworks: false,
    name: "neg-network",
  }
);
const googleComputeSubnetworkDefault =
  new google.computeSubnetwork.ComputeSubnetwork(this, "default_1", {
    ip_cidr_range: "10.0.0.0/16",
    name: "neg-subnetwork",
    network: googleComputeNetworkDefault.id,
    region: "us-central1",
  });
/*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
googleComputeSubnetworkDefault.overrideLogicalId("default");
new google.computeNetworkEndpointGroup.ComputeNetworkEndpointGroup(
  this,
  "neg",
  {
    default_port: "90",
    name: "my-lb-neg",
    network: googleComputeNetworkDefault.id,
    subnetwork: googleComputeSubnetworkDefault.id,
    zone: "us-central1-a",
  }
);

Example Usage - Network Endpoint Group Non Gcp

/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as google from "./.gen/providers/google";
/*The following providers are missing schema information and might need manual adjustments to synthesize correctly: google.
For a more precise conversion please use the --provider flag in convert.*/
const googleComputeNetworkDefault = new google.computeNetwork.ComputeNetwork(
  this,
  "default",
  {
    name: "neg-network",
  }
);
const googleComputeNetworkEndpointGroupNeg =
  new google.computeNetworkEndpointGroup.ComputeNetworkEndpointGroup(
    this,
    "neg",
    {
      default_port: "90",
      name: "my-lb-neg",
      network: googleComputeNetworkDefault.id,
      network_endpoint_type: "NON_GCP_PRIVATE_IP_PORT",
      zone: "us-central1-a",
    }
  );
new google.computeNetworkEndpoint.ComputeNetworkEndpoint(
  this,
  "default-endpoint",
  {
    ip_address: "127.0.0.1",
    network_endpoint_group: googleComputeNetworkEndpointGroupNeg.name,
    port: googleComputeNetworkEndpointGroupNeg.defaultPort,
  }
);

Argument Reference

The following arguments are supported:

  • name - (Required) Name of the resource; provided by the client when the resource is created. The name must be 1-63 characters long, and comply with RFC1035. Specifically, the name must be 1-63 characters long and match the regular expression [aZ]([AZ09]*[aZ09])? which means the first character must be a lowercase letter, and all following characters must be a dash, lowercase letter, or digit, except the last character, which cannot be a dash.

  • network - (Required) The network to which all network endpoints in the NEG belong. Uses "default" project network if unspecified.


  • description - (Optional) An optional description of this resource. Provide this property when you create the resource.

  • networkEndpointType - (Optional) Type of network endpoints in this network endpoint group. NON_GCP_PRIVATE_IP_PORT is used for hybrid connectivity network endpoint groups (see https://cloud.google.com/load-balancing/docs/hybrid). Note that NON_GCP_PRIVATE_IP_PORT can only be used with Backend Services that 1) have the following load balancing schemes: EXTERNAL, EXTERNAL_MANAGED, INTERNAL_MANAGED, and INTERNAL_SELF_MANAGED and 2) support the RATE or CONNECTION balancing modes. Possible values include: GCE_VM_IP, GCE_VM_IP_PORT, and NON_GCP_PRIVATE_IP_PORT. Default value is gceVmIpPort. Possible values are gceVmIp, gceVmIpPort, and nonGcpPrivateIpPort.

  • subnetwork - (Optional) Optional subnetwork to which all network endpoints in the NEG belong.

  • defaultPort - (Optional) The default port used if the port number is not specified in the network endpoint.

  • zone - (Optional) Zone where the network endpoint group is located.

  • project - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used.

Attributes Reference

In addition to the arguments listed above, the following computed attributes are exported:

  • id - an identifier for the resource with format projects/{{project}}/zones/{{zone}}/networkEndpointGroups/{{name}}

  • size - Number of network endpoints in the network endpoint group.

  • selfLink - The URI of the created resource.

Timeouts

This resource provides the following Timeouts configuration options:

  • create - Default is 20 minutes.
  • delete - Default is 20 minutes.

Import

NetworkEndpointGroup can be imported using any of these accepted formats:

$ terraform import google_compute_network_endpoint_group.default projects/{{project}}/zones/{{zone}}/networkEndpointGroups/{{name}}
$ terraform import google_compute_network_endpoint_group.default {{project}}/{{zone}}/{{name}}
$ terraform import google_compute_network_endpoint_group.default {{zone}}/{{name}}
$ terraform import google_compute_network_endpoint_group.default {{name}}

User Project Overrides

This resource supports User Project Overrides.