Skip to content

Commit 158ebf8

Browse files
committed
feat(cloud_sql): add disabling psc on PSA+PSC instances examples
1 parent 1cfc3de commit 158ebf8

File tree

3 files changed

+81
-0
lines changed

3 files changed

+81
-0
lines changed

cloud_sql/mysql_instance_psa_psc/main.tf

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,5 +89,30 @@ resource "google_compute_forwarding_rule" "default" {
8989
target = data.google_sql_database_instance.default.psc_service_attachment_link
9090
}
9191

92+
# [START cloud_sql_mysql_instance_disable_psc_instance]
93+
resource "google_sql_database_instance" "disable_psc_example" {
94+
name = "mysql-disable-psc-example"
95+
region = "us-central1"
96+
database_version = "MYSQL_8_0"
97+
98+
depends_on = [google_service_networking_connection.default]
99+
100+
settings {
101+
tier = "db-f1-micro"
102+
ip_configuration {
103+
psc_config {
104+
psc_enabled = false
105+
allowed_consumer_projects = [] # clear consumer projects
106+
}
107+
ipv4_enabled = false
108+
private_network = google_compute_network.peering_network.id
109+
}
110+
}
111+
# set `deletion_protection` to true, will ensure that one cannot accidentally delete this instance by
112+
# use of Terraform whereas `deletion_protection_enabled` flag protects this instance at the GCP level.
113+
deletion_protection = false
114+
}
115+
# [END cloud_sql_mysql_instance_disable_psc_instance]
116+
92117
# [END cloud_sql_mysql_instance_psa_psc_parent_tag]
93118

cloud_sql/postgres_instance_psa_psc/main.tf

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,4 +93,34 @@ resource "google_compute_forwarding_rule" "default" {
9393
target = data.google_sql_database_instance.default.psc_service_attachment_link
9494
}
9595

96+
97+
# [START cloud_sql_postgres_instance_disable_psc_instance]
98+
resource "google_sql_database_instance" "disable_psc_example" {
99+
name = "postgres-disable-psc-example"
100+
region = "us-central1"
101+
database_version = "POSTGRES_17"
102+
103+
depends_on = [google_service_networking_connection.default]
104+
105+
settings {
106+
tier = "db-custom-2-7680"
107+
availability_type = "REGIONAL"
108+
backup_configuration {
109+
enabled = true
110+
}
111+
ip_configuration {
112+
psc_config {
113+
psc_enabled = false
114+
allowed_consumer_projects = [] # clear consumer projects
115+
}
116+
ipv4_enabled = false
117+
private_network = google_compute_network.peering_network.id
118+
}
119+
}
120+
# set `deletion_protection` to true, will ensure that one cannot accidentally delete this instance by
121+
# use of Terraform whereas `deletion_protection_enabled` flag protects this instance at the GCP level.
122+
deletion_protection = false # Set to "true" to prevent destruction of the resource
123+
}
124+
# [END cloud_sql_postgres_instance_disable_psc_instance]
125+
96126
# [END cloud_sql_postgres_instance_psa_psc_parent_tag]

cloud_sql/sqlserver_instance_psa_psc/main.tf

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,5 +90,31 @@ resource "google_compute_forwarding_rule" "default" {
9090
target = data.google_sql_database_instance.default.psc_service_attachment_link
9191
}
9292

93+
# [START cloud_sql_sqlserver_instance_disable_psc_instance]
94+
resource "google_sql_database_instance" "disable_psc_example" {
95+
name = "sqlserver-disable-psc-example"
96+
region = "us-central1"
97+
database_version = "SQLSERVER_2019_STANDARD"
98+
root_password = "INSERT-PASSWORD-HERE"
99+
100+
depends_on = [google_service_networking_connection.default]
101+
102+
settings {
103+
tier = "db-custom-2-7680"
104+
ip_configuration {
105+
psc_config {
106+
psc_enabled = false
107+
allowed_consumer_projects = [] # clear consumer projects
108+
}
109+
ipv4_enabled = false
110+
private_network = google_compute_network.peering_network.id
111+
}
112+
}
113+
# set `deletion_protection` to true, will ensure that one cannot accidentally delete this instance by
114+
# use of Terraform whereas `deletion_protection_enabled` flag protects this instance at the GCP level.
115+
deletion_protection = false
116+
}
117+
# [END cloud_sql_sqlserver_instance_disable_psc_instance]
118+
93119
# [END cloud_sql_sqlserver_instance_psa_psc_parent_tag]
94120

0 commit comments

Comments
 (0)