Manages a private VPC connection with a GCP service provider. For more information see the official documentation and API.
# Create a VPC network
resource "google_compute_network" "peering_network" {
name = "peering-network"
}
# Create an IP address
resource "google_compute_global_address" "private_ip_alloc" {
name = "private-ip-alloc"
purpose = "VPC_PEERING"
address_type = "INTERNAL"
prefix_length = 16
network = google_compute_network.peering_network.id
}
# Create a private connection
resource "google_service_networking_connection" "default" {
network = google_compute_network.peering_network.id
service = "servicenetworking.googleapis.com"
reserved_peering_ranges = [google_compute_global_address.private_ip_alloc.name]
}
# (Optional) Import or export custom routes
resource "google_compute_network_peering_routes_config" "peering_routes" {
peering = google_service_networking_connection.default.peering
network = google_compute_network.peering_network.name
import_custom_routes = true
export_custom_routes = true
}
The following arguments are supported:
network
- (Required) Name of VPC network connected with service producers using VPC peering.
service
- (Required) Provider peering service that is managing peering connectivity for a
service provider organization. For Google services that support this functionality it is
'servicenetworking.googleapis.com'.
reserved_peering_ranges
- (Required) Named IP address range(s) of PEERING type reserved for
this service provider. Note that invoking this method with a different range when connection
is already established will not reallocate already provisioned service producer subnetworks.
deletion_policy
- (Optional) The deletion policy for the service networking connection. Setting to ABANDON allows the resource to be abandoned rather than deleted. This will enable a successful terraform destroy when destroying CloudSQL instances. Use with care as it can lead to dangling resources.
In addition to the arguments listed above, the following computed attributes are exported:
peering
- (Computed) The name of the VPC Network Peering connection that was created by the service producer.ServiceNetworkingConnection can be imported using any of these accepted formats
{{peering-network}}:{{service}}
projects/{{project}}/global/networks/{{peering-network}}:{{service}}
In Terraform v1.5.0 and later, use an import
block to import NAME_HERE using one of the formats above. For example:
import {
id = "projects/{{project}}/global/networks/{{peering-network}}:{{service}}"
to = google_service_networking_connection.default
}
When using the terraform import
command, NAME_HERE can be imported using one of the formats above. For example:
$ terraform import google_service_networking_connection.default {{peering-network}}:{{service}}
$ terraform import google_service_networking_connection.default /projects/{{project}}/global/networks/{{peering-network}}:{{service}}
This resource supports User Project Overrides.