| --- |
| subcategory: "Compute Engine" |
| description: |- |
| Manages a Target Pool within GCE. |
| --- |
| |
| # google\_compute\_target\_pool |
| |
| Manages a Target Pool within GCE. This is a collection of instances used as |
| target of a network load balancer (Forwarding Rule). For more information see |
| [the official |
| documentation](https://cloud.google.com/compute/docs/load-balancing/network/target-pools) |
| and [API](https://cloud.google.com/compute/docs/reference/latest/targetPools). |
| |
| |
| ## Example Usage |
| |
| ```hcl |
| resource "google_compute_target_pool" "default" { |
| name = "instance-pool" |
| |
| instances = [ |
| "us-central1-a/myinstance1", |
| "us-central1-b/myinstance2", |
| ] |
| |
| health_checks = [ |
| google_compute_http_health_check.default.name, |
| ] |
| } |
| |
| resource "google_compute_http_health_check" "default" { |
| name = "default" |
| request_path = "/" |
| check_interval_sec = 1 |
| timeout_sec = 1 |
| } |
| ``` |
| |
| ## Argument Reference |
| |
| The following arguments are supported: |
| |
| * `name` - (Required) A unique name for the resource, required by GCE. Changing |
| this forces a new resource to be created. |
| |
| - - - |
| |
| * `backup_pool` - (Optional) URL to the backup target pool. Must also set |
| failover\_ratio. |
| |
| * `description` - (Optional) Textual description field. |
| |
| * `failover_ratio` - (Optional) Ratio (0 to 1) of failed nodes before using the |
| backup pool (which must also be set). |
| |
| * `health_checks` - (Optional) List of zero or one health check name or self_link. Only |
| legacy `google_compute_http_health_check` is supported. |
| |
| * `instances` - (Optional) List of instances in the pool. They can be given as |
| URLs, or in the form of "zone/name". Note that the instances need not exist |
| at the time of target pool creation, so there is no need to use the |
| Terraform interpolators to create a dependency on the instances from the |
| target pool. |
| |
| * `project` - (Optional) The ID of the project in which the resource belongs. If it |
| is not provided, the provider project is used. |
| |
| * `region` - (Optional) Where the target pool resides. Defaults to project |
| region. |
| |
| * `session_affinity` - (Optional) How to distribute load. Options are "NONE" (no |
| affinity). "CLIENT\_IP" (hash of the source/dest addresses / ports), and |
| "CLIENT\_IP\_PROTO" also includes the protocol (default "NONE"). |
| |
| * `security_policy` - (Optional, [Beta](https://terraform.io/docs/providers/google/guides/provider_versions.html)) The resource URL for the security policy associated with this target pool. |
| |
| ## 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}}/regions/{{region}}/targetPools/{{name}}` |
| |
| * `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: configuration options: |
| |
| - `create` - Default is 4 minutes. |
| - `update` - Default is 4 minutes. |
| - `delete` - Default is 4 minutes. |
| |
| ## Import |
| |
| Target pools can be imported using any of the following formats: |
| |
| * `projects/{{project}}/regions/{{region}}/targetPools/{{name}}` |
| * `{{project}}/{{region}}/{{name}}` |
| * `{{region}}/{{name}}` |
| * `{{name}}` |
| |
| In Terraform v1.5.0 and later, use an [`import` block](https://developer.hashicorp.com/terraform/language/import) to import target pools using one of the formats above. For example: |
| |
| ```tf |
| import { |
| id = "projects/{{project}}/regions/{{region}}/targetPools/{{name}}" |
| to = google_compute_target_pool.default |
| } |
| ``` |
| |
| When using the [`terraform import` command](https://developer.hashicorp.com/terraform/cli/commands/import), target pools can be imported using one of the formats above. For example: |
| |
| ``` |
| $ terraform import google_compute_target_pool.default projects/{{project}}/regions/{{region}}/targetPools/{{name}} |
| $ terraform import google_compute_target_pool.default {{project}}/{{region}}/{{name}} |
| $ terraform import google_compute_target_pool.default {{region}}/{{name}} |
| $ terraform import google_compute_target_pool.default {{name}} |
| ``` |