A connectivity test are a static analysis of your resource configurations that enables you to evaluate connectivity to and from Google Cloud resources in your Virtual Private Cloud (VPC) network.
To get more information about ConnectivityTest, see:
resource "google_network_management_connectivity_test" "instance-test" {
name = "conn-test-instances"
source {
instance = google_compute_instance.source.id
}
destination {
instance = google_compute_instance.destination.id
}
protocol = "TCP"
labels = {
env = "test"
}
}
resource "google_compute_instance" "source" {
name = "source-vm"
machine_type = "e2-medium"
boot_disk {
initialize_params {
image = data.google_compute_image.debian_9.id
}
}
network_interface {
network = google_compute_network.vpc.id
access_config {
}
}
}
resource "google_compute_instance" "destination" {
name = "dest-vm"
machine_type = "e2-medium"
boot_disk {
initialize_params {
image = data.google_compute_image.debian_9.id
}
}
network_interface {
network = google_compute_network.vpc.id
access_config {
}
}
}
resource "google_compute_network" "vpc" {
name = "conn-test-net"
}
data "google_compute_image" "debian_9" {
family = "debian-11"
project = "debian-cloud"
}
resource "google_network_management_connectivity_test" "address-test" {
name = "conn-test-addr"
source {
ip_address = google_compute_address.source-addr.address
project_id = google_compute_address.source-addr.project
network = google_compute_network.vpc.id
network_type = "GCP_NETWORK"
}
destination {
ip_address = google_compute_address.dest-addr.address
project_id = google_compute_address.dest-addr.project
network = google_compute_network.vpc.id
}
protocol = "UDP"
}
resource "google_compute_network" "vpc" {
name = "connectivity-vpc"
}
resource "google_compute_subnetwork" "subnet" {
name = "connectivity-vpc-subnet"
ip_cidr_range = "10.0.0.0/16"
region = "us-central1"
network = google_compute_network.vpc.id
}
resource "google_compute_address" "source-addr" {
name = "src-addr"
subnetwork = google_compute_subnetwork.subnet.id
address_type = "INTERNAL"
address = "10.0.42.42"
region = "us-central1"
}
resource "google_compute_address" "dest-addr" {
name = "dest-addr"
subnetwork = google_compute_subnetwork.subnet.id
address_type = "INTERNAL"
address = "10.0.43.43"
region = "us-central1"
}
The following arguments are supported:
name
-
(Required)
Unique name for the connectivity test.
source
-
(Required)
Required. Source specification of the Connectivity Test.
You can use a combination of source IP address, virtual machine
(VM) instance, or Compute Engine network to uniquely identify the
source location.
Examples: If the source IP address is an internal IP address within
a Google Cloud Virtual Private Cloud (VPC) network, then you must
also specify the VPC network. Otherwise, specify the VM instance,
which already contains its internal IP address and VPC network
information.
If the source of the test is within an on-premises network, then
you must provide the destination VPC network.
If the source endpoint is a Compute Engine VM instance with multiple
network interfaces, the instance itself is not sufficient to
identify the endpoint. So, you must also specify the source IP
address or VPC network.
A reachability analysis proceeds even if the source location is
ambiguous. However, the test result may include endpoints that
you don't intend to test.
Structure is documented below.
destination
-
(Required)
Required. Destination specification of the Connectivity Test.
You can use a combination of destination IP address, Compute
Engine VM instance, or VPC network to uniquely identify the
destination location.
Even if the destination IP address is not unique, the source IP
location is unique. Usually, the analysis can infer the destination
endpoint from route information.
If the destination you specify is a VM instance and the instance has
multiple network interfaces, then you must also specify either a
destination IP address or VPC network to identify the destination
interface.
A reachability analysis proceeds even if the destination location
is ambiguous. However, the result can include endpoints that you
don't intend to test.
Structure is documented below.
ip_address
-
(Optional)
The IP address of the endpoint, which can be an external or
internal IP. An IPv6 address is only allowed when the test's
destination is a global load balancer VIP.
port
-
(Optional)
The IP protocol port of the endpoint. Only applicable when
protocol is TCP or UDP.
instance
-
(Optional)
A Compute Engine instance URI.
network
-
(Optional)
A Compute Engine network URI.
network_type
-
(Optional)
Type of the network where the endpoint is located.
Possible values are: GCP_NETWORK
, NON_GCP_NETWORK
.
project_id
-
(Optional)
Project ID where the endpoint is located. The Project ID can be
derived from the URI if you provide a VM instance or network URI.
The following are two cases where you must provide the project ID:
The destination
block supports:
ip_address
-
(Optional)
The IP address of the endpoint, which can be an external or
internal IP. An IPv6 address is only allowed when the test's
destination is a global load balancer VIP.
port
-
(Optional)
The IP protocol port of the endpoint. Only applicable when
protocol is TCP or UDP.
instance
-
(Optional)
A Compute Engine instance URI.
network
-
(Optional)
A Compute Engine network URI.
project_id
-
(Optional)
Project ID where the endpoint is located. The Project ID can be
derived from the URI if you provide a VM instance or network URI.
The following are two cases where you must provide the project ID:
description
-
(Optional)
The user-supplied description of the Connectivity Test.
Maximum of 512 characters.
protocol
-
(Optional)
IP Protocol of the test. When not provided, "TCP" is assumed.
related_projects
-
(Optional)
Other projects that may be relevant for reachability analysis.
This is applicable to scenarios where a test can cross project
boundaries.
labels
-
(Optional)
Resource labels to represent user-provided metadata.
Note: This field is non-authoritative, and will only manage the labels present in your configuration.
Please refer to the field effective_labels
for all of the labels present on the resource.
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}}/locations/global/connectivityTests/{{name}}
terraform_labels
-
The combination of labels configured directly on the resource
and default labels configured on the provider.
effective_labels
-
All of labels (key/value pairs) present on the resource in GCP, including the labels configured through Terraform, other clients and services.
This resource provides the following Timeouts configuration options:
create
- Default is 20 minutes.update
- Default is 20 minutes.delete
- Default is 20 minutes.ConnectivityTest can be imported using any of these accepted formats:
projects/{{project}}/locations/global/connectivityTests/{{name}}
{{project}}/{{name}}
{{name}}
In Terraform v1.5.0 and later, use an import
block to import ConnectivityTest using one of the formats above. For example:
import {
id = "projects/{{project}}/locations/global/connectivityTests/{{name}}"
to = google_network_management_connectivity_test.default
}
When using the terraform import
command, ConnectivityTest can be imported using one of the formats above. For example:
$ terraform import google_network_management_connectivity_test.default projects/{{project}}/locations/global/connectivityTests/{{name}}
$ terraform import google_network_management_connectivity_test.default {{project}}/{{name}}
$ terraform import google_network_management_connectivity_test.default {{name}}
This resource supports User Project Overrides.