11/* *
2- * Copyright 2022 Google LLC
2+ * Copyright 2025 Google LLC
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
1616
1717# [START cloud_sql_postgres_instance_psa_psc]
1818
19- # [START vpc_postgres_instance_private_ip_network ]
19+ # [START vpc_postgres_instance_psa_psc_network ]
2020resource "google_compute_network" "peering_network" {
2121 name = " private-network"
2222 auto_create_subnetworks = " false"
2323}
24- # [END vpc_postgres_instance_private_ip_network ]
24+ # [END vpc_postgres_instance_psa_psc_network ]
2525
26- # [START vpc_postgres_instance_private_ip_address ]
26+ # [START vpc_postgres_instance_psa_psc_address ]
2727resource "google_compute_global_address" "private_ip_address" {
2828 name = " private-ip-address"
2929 purpose = " VPC_PEERING"
3030 address_type = " INTERNAL"
3131 prefix_length = 16
3232 network = google_compute_network. peering_network . id
3333}
34- # [END vpc_postgres_instance_private_ip_address ]
34+ # [END vpc_postgres_instance_psa_psc_address ]
3535
36- # [START vpc_postgres_instance_private_ip_service_connection ]
36+ # [START vpc_postgres_instance_psa_psc_service_connection ]
3737resource "google_service_networking_connection" "default" {
3838 network = google_compute_network. peering_network . id
3939 service = " servicenetworking.googleapis.com"
4040 reserved_peering_ranges = [google_compute_global_address . private_ip_address . name ]
4141}
42- # [END vpc_postgres_instance_private_ip_service_connection ]
42+ # [END vpc_postgres_instance_psa_psc_service_connection ]
4343
4444# [START cloud_sql_postgres_instance_psa_psc_instance]
4545resource "google_sql_database_instance" "default" {
4646 name = " postgres-instance"
4747 region = " us-central1"
48- database_version = " POSTGRES_14 "
48+ database_version = " POSTGRES_17 "
4949
5050 depends_on = [google_service_networking_connection . default ]
5151
@@ -64,20 +64,22 @@ resource "google_sql_database_instance" "default" {
6464 private_network = google_compute_network. peering_network . id
6565 }
6666 }
67+ # set `deletion_protection` to true, will ensure that one cannot accidentally delete this instance by
68+ # use of Terraform whereas `deletion_protection_enabled` flag protects this instance at the GCP level.
6769 deletion_protection = false # Set to "true" to prevent destruction of the resource
6870}
6971# [END cloud_sql_postgres_instance_psa_psc_instance]
7072
71- # [START cloud_sql_postgres_instance_private_ip_routes ]
73+ # [START cloud_sql_postgres_instance_psa_psc_routes ]
7274resource "google_compute_network_peering_routes_config" "peering_routes" {
7375 peering = google_service_networking_connection. default . peering
7476 network = google_compute_network. peering_network . name
7577 import_custom_routes = true
7678 export_custom_routes = true
7779}
78- # [END cloud_sql_postgres_instance_private_ip_routes ]
80+ # [END cloud_sql_postgres_instance_psa_psc_routes ]
7981
80- # [START cloud_sql_postgres_instance_psc_endpoint ]
82+ # [START cloud_sql_postgres_instance_psa_psc_endpoint ]
8183resource "google_compute_address" "default" {
8284 name = " psc-compute-address"
8385 region = " us-central1"
@@ -98,6 +100,6 @@ resource "google_compute_forwarding_rule" "default" {
98100 load_balancing_scheme = " "
99101 target = data. google_sql_database_instance . default . psc_service_attachment_link
100102}
101- # [END cloud_sql_postgres_instance_psc_endpoint ]
103+ # [END cloud_sql_postgres_instance_psa_psc_endpoint ]
102104
103105# [END cloud_sql_postgres_instance_psa_psc]
0 commit comments