Skip to content

googleComputeTargetInstance

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:

Example Usage - Target Instance Basic

/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as google from "./.gen/providers/google";
/*The following providers are missing schema information and might need manual adjustments to synthesize correctly: google.
For a more precise conversion please use the --provider flag in convert.*/
const dataGoogleComputeImageVmimage =
  new google.dataGoogleComputeImage.DataGoogleComputeImage(this, "vmimage", {
    family: "debian-11",
    project: "debian-cloud",
  });
const googleComputeInstanceTargetVm =
  new google.computeInstance.ComputeInstance(this, "target-vm", {
    boot_disk: [
      {
        initialize_params: [
          {
            image: dataGoogleComputeImageVmimage.selfLink,
          },
        ],
      },
    ],
    machine_type: "e2-medium",
    name: "target-vm",
    network_interface: [
      {
        network: "default",
      },
    ],
    zone: "us-central1-a",
  });
new google.computeTargetInstance.ComputeTargetInstance(this, "default", {
  instance: googleComputeInstanceTargetVm.id,
  name: "target",
});

Example Usage - Target Instance Custom Network

/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as google from "./.gen/providers/google";
/*The following providers are missing schema information and might need manual adjustments to synthesize correctly: google.
For a more precise conversion please use the --provider flag in convert.*/
const dataGoogleComputeImageVmimage =
  new google.dataGoogleComputeImage.DataGoogleComputeImage(this, "vmimage", {
    family: "debian-10",
    project: "debian-cloud",
    provider: "${google-beta}",
  });
const dataGoogleComputeNetworkTargetVm =
  new google.dataGoogleComputeNetwork.DataGoogleComputeNetwork(
    this,
    "target-vm",
    {
      name: "default",
      provider: "${google-beta}",
    }
  );
const googleComputeInstanceTargetVm =
  new google.computeInstance.ComputeInstance(this, "target-vm_2", {
    boot_disk: [
      {
        initialize_params: [
          {
            image: dataGoogleComputeImageVmimage.selfLink,
          },
        ],
      },
    ],
    machine_type: "e2-medium",
    name: "custom-network-target-vm",
    network_interface: [
      {
        network: "default",
      },
    ],
    provider: "${google-beta}",
    zone: "us-central1-a",
  });
/*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
googleComputeInstanceTargetVm.overrideLogicalId("target-vm");
new google.computeTargetInstance.ComputeTargetInstance(this, "custom_network", {
  instance: googleComputeInstanceTargetVm.id,
  name: "custom-network",
  network: dataGoogleComputeNetworkTargetVm.selfLink,
  provider: "${google-beta}",
});

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 [aZ]([AZ09]*[aZ09])? 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.

  • natPolicy - (Optional) NAT option controlling how IPs are NAT'ed to the instance. Currently only NO_NAT (default value) is supported. Default value is noNat. Possible values are noNat.

  • 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.

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}}/targetInstances/{{name}}

  • creationTimestamp - Creation timestamp in RFC3339 text format.

  • selfLink - The URI of the created resource.

Timeouts

This resource provides the following Timeouts configuration options:

  • create - Default is 20 minutes.
  • delete - Default is 20 minutes.

Import

TargetInstance can be imported using any of these accepted formats:

$ 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}}

User Project Overrides

This resource supports User Project Overrides.