-
Notifications
You must be signed in to change notification settings - Fork 286
feat(cloud_sql): Add cloud sql psa+psc connectivity samples #808
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
173863d
feat(cloud_sql): Add cloud sql psa+psc connectivity samples
loeng2023 be61fa4
fix region tags
loeng2023 c5ac66e
Fix license year
loeng2023 684429b
Merge branch 'main' into bug-383556956
jackwotherspoon f3010e2
remove unnecessary region tags
loeng2023 727ef1f
add short description at beginning
loeng2023 8bf11fe
minor change
loeng2023 bc4eef2
avoid use auto-subnet ip as static ip
loeng2023 fc3c3ee
fix lint
loeng2023 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| /** | ||
| * Copyright 2022 Google LLC | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
loeng2023 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| # [START cloud_sql_mysql_instance_psa_psc] | ||
loeng2023 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| # [START vpc_mysql_instance_private_ip_network] | ||
| resource "google_compute_network" "peering_network" { | ||
| name = "private-network" | ||
| auto_create_subnetworks = "false" | ||
| } | ||
| # [END vpc_mysql_instance_private_ip_network] | ||
|
|
||
| # [START vpc_mysql_instance_private_ip_address] | ||
| resource "google_compute_global_address" "private_ip_address" { | ||
| name = "private-ip-address" | ||
| purpose = "VPC_PEERING" | ||
| address_type = "INTERNAL" | ||
| prefix_length = 16 | ||
| network = google_compute_network.peering_network.id | ||
| } | ||
| # [END vpc_mysql_instance_private_ip_address] | ||
|
|
||
| # [START vpc_mysql_instance_private_ip_service_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_address.name] | ||
| } | ||
| # [END vpc_mysql_instance_private_ip_service_connection] | ||
|
|
||
| # [START cloud_sql_mysql_instance_psa_psc_instance] | ||
| resource "google_sql_database_instance" "default" { | ||
| name = "mysql-instance" | ||
| region = "us-central1" | ||
| database_version = "MYSQL_8_0" | ||
|
|
||
| depends_on = [google_service_networking_connection.default] | ||
|
|
||
| settings { | ||
| tier = "db-f1-micro" | ||
| ip_configuration { | ||
| psc_config { | ||
| psc_enabled = true | ||
| allowed_consumer_projects = [] # Add consumer project IDs here. | ||
| } | ||
| ipv4_enabled = false | ||
| private_network = google_compute_network.peering_network.id | ||
| } | ||
| } | ||
| # set `deletion_protection` to true, will ensure that one cannot accidentally delete this instance by | ||
| # use of Terraform whereas `deletion_protection_enabled` flag protects this instance at the GCP level. | ||
| deletion_protection = false | ||
| } | ||
| # [END cloud_sql_mysql_instance_psa_psc_instance] | ||
|
|
||
| # [START cloud_sql_mysql_instance_private_ip_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 | ||
| } | ||
| # [END cloud_sql_mysql_instance_private_ip_routes] | ||
|
|
||
| # [START cloud_sql_mysql_instance_psc_endpoint] | ||
| resource "google_compute_address" "default" { | ||
| name = "psc-compute-address-${google_sql_database_instance.default.name}" | ||
| region = "us-central1" | ||
| address_type = "INTERNAL" | ||
| subnetwork = "default" # Replace value with the name of the subnet here. | ||
| address = "10.128.0.43" # Replace value with the IP address to reserve. | ||
loeng2023 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| data "google_sql_database_instance" "default" { | ||
| name = resource.google_sql_database_instance.default.name | ||
| } | ||
|
|
||
| resource "google_compute_forwarding_rule" "default" { | ||
| name = "psc-forwarding-rule-${google_sql_database_instance.default.name}" | ||
| region = "us-central1" | ||
| network = "default" | ||
| ip_address = google_compute_address.default.self_link | ||
| load_balancing_scheme = "" | ||
loeng2023 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| target = data.google_sql_database_instance.default.psc_service_attachment_link | ||
| } | ||
| # [END cloud_sql_mysql_instance_psc_endpoint] | ||
|
|
||
| # [END cloud_sql_mysql_instance_psa_psc] | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| # Copyright 2022 Google LLC | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| apiVersion: blueprints.cloud.google.com/v1alpha1 | ||
| kind: BlueprintTest | ||
| metadata: | ||
| name: sql_mysql_instance_psa_psc | ||
| spec: | ||
| skip: true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| # Copyright 2022 Google LLC | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| apiVersion: blueprints.cloud.google.com/v1alpha1 | ||
| kind: BlueprintTest | ||
| metadata: | ||
| name: sql_mysql_instance_psc | ||
| spec: | ||
| skip: true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,103 @@ | ||
| /** | ||
| * Copyright 2022 Google LLC | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| # [START cloud_sql_postgres_instance_psa_psc] | ||
|
|
||
| # [START vpc_postgres_instance_private_ip_network] | ||
loeng2023 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| resource "google_compute_network" "peering_network" { | ||
| name = "private-network" | ||
| auto_create_subnetworks = "false" | ||
| } | ||
| # [END vpc_postgres_instance_private_ip_network] | ||
|
|
||
| # [START vpc_postgres_instance_private_ip_address] | ||
| resource "google_compute_global_address" "private_ip_address" { | ||
| name = "private-ip-address" | ||
| purpose = "VPC_PEERING" | ||
| address_type = "INTERNAL" | ||
| prefix_length = 16 | ||
| network = google_compute_network.peering_network.id | ||
| } | ||
| # [END vpc_postgres_instance_private_ip_address] | ||
|
|
||
| # [START vpc_postgres_instance_private_ip_service_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_address.name] | ||
| } | ||
| # [END vpc_postgres_instance_private_ip_service_connection] | ||
|
|
||
| # [START cloud_sql_postgres_instance_psa_psc_instance] | ||
| resource "google_sql_database_instance" "default" { | ||
| name = "postgres-instance" | ||
| region = "us-central1" | ||
| database_version = "POSTGRES_14" | ||
loeng2023 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| depends_on = [google_service_networking_connection.default] | ||
|
|
||
| settings { | ||
| tier = "db-custom-2-7680" | ||
| availability_type = "REGIONAL" | ||
| backup_configuration { | ||
| enabled = true | ||
| } | ||
| ip_configuration { | ||
| psc_config { | ||
| psc_enabled = true | ||
| allowed_consumer_projects = [] # Add consumer project IDs here. | ||
| } | ||
| ipv4_enabled = false | ||
| private_network = google_compute_network.peering_network.id | ||
| } | ||
| } | ||
| deletion_protection = false # Set to "true" to prevent destruction of the resource | ||
loeng2023 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| # [END cloud_sql_postgres_instance_psa_psc_instance] | ||
|
|
||
| # [START cloud_sql_postgres_instance_private_ip_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 | ||
| } | ||
| # [END cloud_sql_postgres_instance_private_ip_routes] | ||
|
|
||
| # [START cloud_sql_postgres_instance_psc_endpoint] | ||
| resource "google_compute_address" "default" { | ||
| name = "psc-compute-address" | ||
| region = "us-central1" | ||
| address_type = "INTERNAL" | ||
| subnetwork = "default" # Replace value with the name of the subnet here. | ||
| address = "10.128.0.42" # Replace value with the IP address to reserve. | ||
| } | ||
|
|
||
| data "google_sql_database_instance" "default" { | ||
| name = resource.google_sql_database_instance.default.name | ||
| } | ||
|
|
||
| resource "google_compute_forwarding_rule" "default" { | ||
| name = "psc-forwarding-rule-${google_sql_database_instance.default.name}" | ||
| region = "us-central1" | ||
| network = "default" | ||
| ip_address = google_compute_address.default.self_link | ||
| load_balancing_scheme = "" | ||
| target = data.google_sql_database_instance.default.psc_service_attachment_link | ||
| } | ||
| # [END cloud_sql_postgres_instance_psc_endpoint] | ||
|
|
||
| # [END cloud_sql_postgres_instance_psa_psc] | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| # Copyright 2022 Google LLC | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| apiVersion: blueprints.cloud.google.com/v1alpha1 | ||
| kind: BlueprintTest | ||
| metadata: | ||
| name: sql_postgres_instance_psa_psc | ||
| spec: | ||
| skip: true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| # Copyright 2022 Google LLC | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| apiVersion: blueprints.cloud.google.com/v1alpha1 | ||
| kind: BlueprintTest | ||
| metadata: | ||
| name: sql_postgres_instance_psc | ||
| spec: | ||
| skip: true |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.