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.
To get more information about NetworkEndpoint, see:
resource "google_compute_network_endpoint" "default-endpoint" {
network_endpoint_group = google_compute_network_endpoint_group.neg.name
instance = google_compute_instance.endpoint-instance.name
port = google_compute_network_endpoint_group.neg.default_port
ip_address = google_compute_instance.endpoint-instance.network_interface[0].network_ip
}
data "google_compute_image" "my_image" {
family = "debian-11"
project = "debian-cloud"
}
resource "google_compute_instance" "endpoint-instance" {
name = "endpoint-instance"
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:
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).
network_endpoint_group
-
(Required)
The network endpoint group this endpoint is part of.
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 of 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
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.
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}}/{{instance}}/{{ip_address}}/{{port}}
This resource provides the following Timeouts configuration options:
create
- Default is 20 minutes.delete
- Default is 20 minutes.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}}
In Terraform v1.5.0 and later, use an import
block to import NetworkEndpoint using one of the formats above. For example:
import {
id = "projects/{{project}}/zones/{{zone}}/networkEndpointGroups/{{network_endpoint_group}}/{{instance}}/{{ip_address}}/{{port}}"
to = google_compute_network_endpoint.default
}
When using the terraform import
command, NetworkEndpoint can be imported using one of the formats above. For example:
$ terraform import google_compute_network_endpoint.default projects/{{project}}/zones/{{zone}}/networkEndpointGroups/{{network_endpoint_group}}/{{instance}}/{{ip_address}}/{{port}}
$ terraform import google_compute_network_endpoint.default {{project}}/{{zone}}/{{network_endpoint_group}}/{{instance}}/{{ip_address}}/{{port}}
$ terraform import google_compute_network_endpoint.default {{zone}}/{{network_endpoint_group}}/{{instance}}/{{ip_address}}/{{port}}
$ terraform import google_compute_network_endpoint.default {{network_endpoint_group}}/{{instance}}/{{ip_address}}/{{port}}
This resource supports User Project Overrides.