| --- |
| # ---------------------------------------------------------------------------- |
| # |
| # *** 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: |- |
| Represents a TargetInstance resource which defines an endpoint instance |
| that terminates traffic of certain protocols. |
| --- |
| |
| # google\_compute\_target\_instance |
| |
| 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: |
| |
| * [API documentation](https://cloud.google.com/compute/docs/reference/v1/targetInstances) |
| * How-to Guides |
| * [Using Protocol Forwarding](https://cloud.google.com/compute/docs/protocol-forwarding) |
| |
| <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=target_instance_basic&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 - Target Instance Basic |
| |
| |
| ```hcl |
| 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" |
| } |
| } |
| ``` |
| <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=target_instance_custom_network&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 - Target Instance Custom Network |
| |
| |
| ```hcl |
| 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" |
| } |
| } |
| ``` |
| <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=target_instance_with_security_policy&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 - Target Instance With Security Policy |
| |
| |
| ```hcl |
| 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 |
| } |
| ``` |
| |
| ## 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. |
| |
| * `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](https://terraform.io/docs/providers/google/guides/provider_versions.html)) |
| 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](https://terraform.io/docs/providers/google/guides/provider_versions.html)) |
| 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. |
| |
| |
| ## 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}}` |
| |
| * `creation_timestamp` - |
| Creation timestamp in RFC3339 text format. |
| * `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. |
| - `update` - Default is 20 minutes. |
| - `delete` - Default is 20 minutes. |
| |
| ## Import |
| |
| |
| 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](https://developer.hashicorp.com/terraform/language/import) to import TargetInstance using one of the formats above. For example: |
| |
| ```tf |
| import { |
| id = "projects/{{project}}/zones/{{zone}}/targetInstances/{{name}}" |
| to = google_compute_target_instance.default |
| } |
| ``` |
| |
| When using the [`terraform import` command](https://developer.hashicorp.com/terraform/cli/commands/import), 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}} |
| ``` |
| |
| ## User Project Overrides |
| |
| This resource supports [User Project Overrides](https://registry.terraform.io/providers/hashicorp/google/latest/docs/guides/provider_reference#user_project_override). |