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 lifecycle.create_before_destroy
to avoid this type of error.
To get more information about NetworkEndpointGroup, see:
resource "google_compute_network_endpoint_group" "neg" {
name = "my-lb-neg"
network = google_compute_network.default.id
subnetwork = google_compute_subnetwork.default.id
default_port = "90"
zone = "us-central1-a"
}
resource "google_compute_network" "default" {
name = "neg-network"
auto_create_subnetworks = false
}
resource "google_compute_subnetwork" "default" {
name = "neg-subnetwork"
ip_cidr_range = "10.0.0.0/16"
region = "us-central1"
network = google_compute_network.default.id
}
resource "google_compute_network_endpoint_group" "neg" {
name = "my-lb-neg"
network = google_compute_network.default.id
default_port = "90"
zone = "us-central1-a"
network_endpoint_type = "NON_GCP_PRIVATE_IP_PORT"
}
resource "google_compute_network_endpoint" "default-endpoint" {
network_endpoint_group = google_compute_network_endpoint_group.neg.name
port = google_compute_network_endpoint_group.neg.default_port
ip_address = "127.0.0.1"
}
resource "google_compute_network" "default" {
name = "neg-network"
}
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 [a-z]([-a-z0-9]*[a-z0-9])?
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.
network_endpoint_type
-
(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, NON_GCP_PRIVATE_IP_PORT, INTERNET_IP_PORT, INTERNET_FQDN_PORT, SERVERLESS, and PRIVATE_SERVICE_CONNECT.
Default value is GCE_VM_IP_PORT
.
Possible values are: GCE_VM_IP
, GCE_VM_IP_PORT
, NON_GCP_PRIVATE_IP_PORT
, INTERNET_IP_PORT
, INTERNET_FQDN_PORT
, SERVERLESS
, PRIVATE_SERVICE_CONNECT
.
subnetwork
-
(Optional)
Optional subnetwork to which all network endpoints in the NEG belong.
default_port
-
(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.
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.
self_link
- The URI of the created resource.This resource provides the following Timeouts configuration options:
create
- Default is 20 minutes.delete
- Default is 20 minutes.NetworkEndpointGroup can be imported using any of these accepted formats:
projects/{{project}}/zones/{{zone}}/networkEndpointGroups/{{name}}
{{project}}/{{zone}}/{{name}}
{{zone}}/{{name}}
{{name}}
In Terraform v1.5.0 and later, use an import
block to import NetworkEndpointGroup using one of the formats above. For example:
import {
id = "projects/{{project}}/zones/{{zone}}/networkEndpointGroups/{{name}}"
to = google_compute_network_endpoint_group.default
}
When using the terraform import
command, NetworkEndpointGroup can be imported using one of the formats above. For example:
$ 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}}
This resource supports User Project Overrides.