blob: 3eea98af5262ce66500fbe119e71170b33beccb8 [file] [log] [blame]
---
# ----------------------------------------------------------------------------
#
# *** AUTO GENERATED CODE *** Type: MMv1 ***
#
# ----------------------------------------------------------------------------
#
# This file is automatically generated by Magic Modules and manual
# changes will be clobbered when the file is regenerated.
#
# Please read more about how to change this file in
# .github/CONTRIBUTING.md.
#
# ----------------------------------------------------------------------------
subcategory: "Compute Engine"
description: |-
Network endpoint groups (NEGs) are zonal resources that represent
collections of IP address and port combinations for GCP resources within a
single subnet.
---
# google\_compute\_network\_endpoint\_group
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:
* [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/)
<div class = "oics-button" style="float: right; margin: 0 0 -15px">
<a href="https://console.cloud.google.com/cloudshell/open?cloudshell_git_repo=https%3A%2F%2Fgithub.com%2Fterraform-google-modules%2Fdocs-examples.git&cloudshell_working_dir=network_endpoint_group&cloudshell_image=gcr.io%2Fcloudshell-images%2Fcloudshell%3Alatest&open_in_editor=main.tf&cloudshell_print=.%2Fmotd&cloudshell_tutorial=.%2Ftutorial.md" target="_blank">
<img alt="Open in Cloud Shell" src="//gstatic.com/cloudssh/images/open-btn.svg" style="max-height: 44px; margin: 32px auto; max-width: 100%;">
</a>
</div>
## Example Usage - Network Endpoint Group
```hcl
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
}
```
<div class = "oics-button" style="float: right; margin: 0 0 -15px">
<a href="https://console.cloud.google.com/cloudshell/open?cloudshell_git_repo=https%3A%2F%2Fgithub.com%2Fterraform-google-modules%2Fdocs-examples.git&cloudshell_working_dir=network_endpoint_group_non_gcp&cloudshell_image=gcr.io%2Fcloudshell-images%2Fcloudshell%3Alatest&open_in_editor=main.tf&cloudshell_print=.%2Fmotd&cloudshell_tutorial=.%2Ftutorial.md" target="_blank">
<img alt="Open in Cloud Shell" src="//gstatic.com/cloudssh/images/open-btn.svg" style="max-height: 44px; margin: 32px auto; max-width: 100%;">
</a>
</div>
## Example Usage - Network Endpoint Group Non Gcp
```hcl
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"
}
```
## 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 `[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.
## 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.
* `self_link` - The URI of the created resource.
## Timeouts
This resource provides the following
[Timeouts](https://developer.hashicorp.com/terraform/plugin/sdkv2/resources/retries-and-customizable-timeouts) configuration options:
- `create` - Default is 20 minutes.
- `delete` - Default is 20 minutes.
## Import
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](https://developer.hashicorp.com/terraform/language/import) to import NetworkEndpointGroup using one of the formats above. For example:
```tf
import {
id = "projects/{{project}}/zones/{{zone}}/networkEndpointGroups/{{name}}"
to = google_compute_network_endpoint_group.default
}
```
When using the [`terraform import` command](https://developer.hashicorp.com/terraform/cli/commands/import), 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}}
```
## User Project Overrides
This resource supports [User Project Overrides](https://registry.terraform.io/providers/hashicorp/google/latest/docs/guides/provider_reference#user_project_override).