A set of network endpoints belonging to a network endpoint group (NEG). A single 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.
This resource is authoritative for a single NEG. Any endpoints not specified by this resource will be deleted when the resource configuration is applied.
To get more information about NetworkEndpoints, see:
resource "google_compute_network_endpoints" "default-endpoints" {
network_endpoint_group = google_compute_network_endpoint_group.neg.name
network_endpoints {
instance = google_compute_instance.endpoint-instance1.name
port = google_compute_network_endpoint_group.neg.default_port
ip_address = google_compute_instance.endpoint-instance1.network_interface[0].network_ip
}
network_endpoints {
instance = google_compute_instance.endpoint-instance2.name
port = google_compute_network_endpoint_group.neg.default_port
ip_address = google_compute_instance.endpoint-instance2.network_interface[0].network_ip
}
}
data "google_compute_image" "my_image" {
family = "debian-11"
project = "debian-cloud"
}
resource "google_compute_instance" "endpoint-instance1" {
name = "endpoint-instance1"
machine_type = "e2-medium"
boot_disk {
initialize_params {
image = data.google_compute_image.my_image.self_link
}
}
network_interface {
subnetwork = google_compute_subnetwork.default.id
access_config {
}
}
}
resource "google_compute_instance" "endpoint-instance2" {
name = "endpoint-instance2"
machine_type = "e2-medium"
boot_disk {
initialize_params {
image = data.google_compute_image.my_image.self_link
}
}
network_interface {
subnetwork = google_compute_subnetwork.default.id
access_config {
}
}
}
resource "google_compute_network_endpoint_group" "group" {
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.1/16"
region = "us-central1"
network = google_compute_network.default.id
}
The following arguments are supported:
network_endpoint_group
-
(Required)
The network endpoint group these endpoints are part of.network_endpoints
-
(Optional)
The network endpoints to be added to the enclosing network endpoint group
(NEG). Each endpoint specifies an IP address and port, along with
additional information depending on the NEG type.
Structure is documented below.
zone
-
(Optional)
Zone where the containing 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.
The network_endpoints
block supports:
instance
-
(Optional)
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 as the network endpoint group.
port
-
(Optional)
Port number of network endpoint.
Note port
is required unless the Network Endpoint Group is created
with the type of GCE_VM_IP
ip_address
-
(Required)
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).
In addition to the arguments listed above, the following computed attributes are exported:
id
- an identifier for the resource with format {{project}}/{{zone}}/{{network_endpoint_group}}/endpoints
This resource provides the following Timeouts configuration options:
create
- Default is 20 minutes.update
- Default is 20 minutes.delete
- Default is 20 minutes.NetworkEndpoints can be imported using any of these accepted formats:
projects/{{project}}/zones/{{zone}}/networkEndpointGroups/{{network_endpoint_group}}
{{project}}/{{zone}}/{{network_endpoint_group}}
{{zone}}/{{network_endpoint_group}}
{{network_endpoint_group}}
In Terraform v1.5.0 and later, use an import
block to import NetworkEndpoints using one of the formats above. For example:
import {
id = "projects/{{project}}/zones/{{zone}}/networkEndpointGroups/{{network_endpoint_group}}"
to = google_compute_network_endpoints.default
}
When using the terraform import
command, NetworkEndpoints can be imported using one of the formats above. For example:
$ terraform import google_compute_network_endpoints.default projects/{{project}}/zones/{{zone}}/networkEndpointGroups/{{network_endpoint_group}}
$ terraform import google_compute_network_endpoints.default {{project}}/{{zone}}/{{network_endpoint_group}}
$ terraform import google_compute_network_endpoints.default {{zone}}/{{network_endpoint_group}}
$ terraform import google_compute_network_endpoints.default {{network_endpoint_group}}
This resource supports User Project Overrides.