Represents a TargetInstance resource which defines an endpoint instance that terminates traffic of certain protocols. In particular, they are used in Protocol Forwarding, where forwarding rules can send packets to a non-NAT'ed target instance. Each target instance contains a single virtual machine instance that receives and handles traffic from the corresponding forwarding rules.
To get more information about TargetInstance, see:
resource "google_compute_target_instance" "default" {
name = "target"
instance = google_compute_instance.target-vm.id
}
data "google_compute_image" "vmimage" {
family = "debian-11"
project = "debian-cloud"
}
resource "google_compute_instance" "target-vm" {
name = "target-vm"
machine_type = "e2-medium"
zone = "us-central1-a"
boot_disk {
initialize_params {
image = data.google_compute_image.vmimage.self_link
}
}
network_interface {
network = "default"
}
}
resource "google_compute_target_instance" "custom_network" {
provider = google-beta
name = "custom-network"
instance = google_compute_instance.target-vm.id
network = data.google_compute_network.target-vm.self_link
}
data "google_compute_network" "target-vm" {
provider = google-beta
name = "default"
}
data "google_compute_image" "vmimage" {
provider = google-beta
family = "debian-10"
project = "debian-cloud"
}
resource "google_compute_instance" "target-vm" {
provider = google-beta
name = "custom-network-target-vm"
machine_type = "e2-medium"
zone = "us-central1-a"
boot_disk {
initialize_params {
image = data.google_compute_image.vmimage.self_link
}
}
network_interface {
network = "default"
}
}
resource "google_compute_network" "default" {
provider = google-beta
name = "custom-default-network"
auto_create_subnetworks = false
routing_mode = "REGIONAL"
}
resource "google_compute_subnetwork" "default" {
provider = google-beta
name = "custom-default-subnet"
ip_cidr_range = "10.1.2.0/24"
network = google_compute_network.default.id
private_ipv6_google_access = "DISABLE_GOOGLE_ACCESS"
purpose = "PRIVATE"
region = "southamerica-west1"
stack_type = "IPV4_ONLY"
}
data "google_compute_image" "vmimage" {
provider = google-beta
family = "debian-11"
project = "debian-cloud"
}
resource "google_compute_instance" "target-vm" {
provider = google-beta
name = "target-vm"
machine_type = "e2-medium"
zone = "southamerica-west1-a"
boot_disk {
initialize_params {
image = data.google_compute_image.vmimage.self_link
}
}
network_interface {
network = google_compute_network.default.self_link
subnetwork = google_compute_subnetwork.default.self_link
access_config {
}
}
}
resource "google_compute_region_security_policy" "policyddosprotection" {
provider = google-beta
region = "southamerica-west1"
name = "tf-test-policyddos%{random_suffix}"
description = "ddos protection security policy to set target instance"
type = "CLOUD_ARMOR_NETWORK"
ddos_protection_config {
ddos_protection = "ADVANCED_PREVIEW"
}
}
resource "google_compute_network_edge_security_service" "edge_sec_service" {
provider = google-beta
region = "southamerica-west1"
name = "tf-test-edgesec%{random_suffix}"
security_policy = google_compute_region_security_policy.policyddosprotection.self_link
}
resource "google_compute_region_security_policy" "regionsecuritypolicy" {
provider = google-beta
name = "region-secpolicy"
region = "southamerica-west1"
description = "basic security policy for target instance"
type = "CLOUD_ARMOR_NETWORK"
depends_on = [google_compute_network_edge_security_service.edge_sec_service]
}
resource "google_compute_target_instance" "default" {
provider = google-beta
name = "target-instance"
zone = "southamerica-west1-a"
instance = google_compute_instance.target-vm.id
security_policy = google_compute_region_security_policy.regionsecuritypolicy.self_link
}
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.
instance
-
(Required)
The Compute instance VM handling traffic for this target instance.
Accepts the instance self-link, relative path
(e.g. projects/project/zones/zone/instances/instance
) or name. If
name is given, the zone will default to the given zone or
the provider-default zone and the project will default to the
provider-level project.
network
-
(Optional, Beta)
The URL of the network this target instance uses to forward traffic. If not specified, the traffic will be forwarded to the network that the default network interface belongs to.
description
-
(Optional)
An optional description of this resource.
nat_policy
-
(Optional)
NAT option controlling how IPs are NAT'ed to the instance.
Currently only NO_NAT (default value) is supported.
Default value is NO_NAT
.
Possible values are: NO_NAT
.
security_policy
-
(Optional, Beta)
The resource URL for the security policy associated with this target instance.
zone
-
(Optional)
URL of the zone where the target instance resides.
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}}/targetInstances/{{name}}
creation_timestamp
-
Creation timestamp in RFC3339 text format.
self_link
- The URI of the created resource.This resource provides the following Timeouts configuration options:
create
- Default is 20 minutes.update
- Default is 20 minutes.delete
- Default is 20 minutes.TargetInstance can be imported using any of these accepted formats:
projects/{{project}}/zones/{{zone}}/targetInstances/{{name}}
{{project}}/{{zone}}/{{name}}
{{zone}}/{{name}}
{{name}}
In Terraform v1.5.0 and later, use an import
block to import TargetInstance using one of the formats above. For example:
import {
id = "projects/{{project}}/zones/{{zone}}/targetInstances/{{name}}"
to = google_compute_target_instance.default
}
When using the terraform import
command, TargetInstance can be imported using one of the formats above. For example:
$ terraform import google_compute_target_instance.default projects/{{project}}/zones/{{zone}}/targetInstances/{{name}}
$ terraform import google_compute_target_instance.default {{project}}/{{zone}}/{{name}}
$ terraform import google_compute_target_instance.default {{zone}}/{{name}}
$ terraform import google_compute_target_instance.default {{name}}
This resource supports User Project Overrides.