Skip to content

Commit 5419ed7

Browse files
authored
Merge pull request #8 from GoogleCloudPlatform/development
added more journies for PSA and PSC
2 parents bd9449b + ef9a506 commit 5419ed7

79 files changed

Lines changed: 6857 additions & 256 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ go.mod
1010
go.sum
1111
**/*.log
1212
**/*plan*
13+
**/*.DS_Store

README.md

Lines changed: 51 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33

44
Streamline your Google Cloud SQL instance deployment and management with this comprehensive Terraform module repository. This repository simplifies Google Cloud networking configuration for Cloud SQL instances. It bundles Terraform modules to make it easier to create and manage Cloud SQL instances and all dependent resources, such as cloud networking resources, IAM policies and service accounts.
55

6-
This repository contains easy-to-use Terraform modules that would help you set up all the prerequisites components required to consume Cloud SQL with private IP in a GCP project. The modules make it easy to manage Cloud SQL and all relevant GCP resources.
7-
This solution will help different users like database administrators and application engineers who want to quickly configure Cloud SQL with cloud networking.
6+
This repository contains easy-to-use Terraform modules that would help you set up all the prerequisites components required to consume Cloud SQL with private IP in a GCP project. The modules make it easy to manage Cloud SQL and all relevant GCP resources. This solution will help different users like database administrators and application engineers who want to quickly configure Cloud SQL with cloud networking.
87

98
Here are some specific benefits of using this repository:
109

@@ -31,9 +30,20 @@ Once the Terraform configuration has been applied, your Cloud SQL instance will
3130

3231
Many examples are included in the [examples](./examples/) folder which describes the complete end-to-end examples covering different scenarios along with its implementation guide and architecture design.
3332

34-
1. [Host Service Project Scenario](./examples/1.Host-Service-Project) : This solution guides user through the steps to establish a host and a service project, create a Cloud SQL instance and a VM instance in the service project, and connect the VM instance to the Cloud SQL instance using the VM's private IP address. The host project contains the VPC, subnets, and firewall rules.
33+
1. [Host Service Project Scenario](./examples/1.Host-Service-Project) : This solution guides a user through the steps to establish a host and a service project, create a Cloud SQL instance and a VM instance in the service project, and connect the VM instance to the Cloud SQL instance using the VM's private IP address. The host project contains the VPC, subnets, and firewall rules.
3534

36-
2. [VPC across VPN Tunnel Scenario](./examples/2.VPC-Across-VPN) : This solution guides user to create a highly available (HA) VPN connection between a user project and a host project with a service project attached. The solution then establishes a Cloud SQL connection using the private IP address of Cloud SQL instance created in the service project and a VM instance created in the user project.
35+
36+
2. This section outlines two user journeys for Service Networking: using **HA-VPN** or **Dedicated Interconnect**.
37+
38+
2.1 [VPC across VPN Tunnel Scenario](./examples/2.VPC-Across-VPN) : This solution guides a user to create a highly available (HA) VPN connection between a user project and a host project with a service project attached. The solution then establishes a Cloud SQL connection using the private IP address of the Cloud SQL instance created in the service project and a VM instance created in the user project.
39+
40+
2.2. [Service Networking Across Interconnect](./examples/ServiceNetworkingAcrossInterconnect) : This solution helps the user to create a dedicated interconnect connection with redundancy & 99.9% availability between an on-premise environment and a GCP project. The solution establishes a Cloud SQL connection using the private IP address of a Cloud SQL instance created inside a GCP project and a VM instance present in the user on-premise environment.
41+
42+
3. [PSC across VPN Scenario](./examples/3.PSC) : This solution guides a user to create a PSC enabled Cloud SQL instance with a consumer and producer project setup having a compute VM instance created in the consumer project connecting to the Cloud SQL instance through PSC service endpoint. The consumer project contains the consumer VPC, service endpoint & firewall rules to connect to the SQL instance in the producer project.
43+
44+
4. [PSC across VPN Scenario](./examples/4.PSC-Across-VPN) : This solution guides a user to create a HA VPN connection between user and consumer project to connect to a PSC enabled Cloud SQL instance in a producer project from a compute VM instance through PSC service endpoint. The compute instance in the consumer project connects to the PSC service endpoint via the VPN connection. The PSC service endpoint connects to the Cloud SQL instance.
45+
46+
All [GA offerings](https://cloud.google.com/sql/docs/sqlserver/private-ip) for Cloud SQL (MySQL, PostgreSQL, MSSQL) are supported through our solutions.
3747

3848
## Variables
3949

@@ -63,7 +73,7 @@ Each providers.tf file carries information like service account to be impersonat
6373

6474
Following are sample commands that can be used to update the existing provider.tf.template file to create an provider.tf file.
6575

66-
1. For example1 - Host- Service project scenario
76+
- For example : 1.Host-Service-Project
6777

6878
```
6979
export _TF_SERVICE_ACCOUNT="<ENTER THE SERVICE ACCOUNT HERE>"
@@ -77,7 +87,7 @@ sed \
7787
examples/1.Host-Service-Project/provider.tf.template > examples/1.Host-Service-Project/provider.tf
7888
```
7989

80-
1. For example2 - VPC Across VPN scenario
90+
- For example : 2.VPC-Across-VPN
8191

8292
```
8393
export _TF_SERVICE_ACCOUNT="<ENTER THE SERVICE ACCOUNT HERE>"
@@ -91,76 +101,57 @@ sed \
91101
examples/2.VPC-Across-VPN/provider.tf.template >examples/2.VPC-Across-VPN/provider.tf
92102
```
93103

94-
## Testing
95-
96-
Following sections describes how the examples can be tested in a GCP environment.
97-
98-
99-
### Running locally
100-
While Running these locally(or in your development machines) make sure you have declared following as the environment variables.
104+
- For example : 3.PSC
101105

102106
```
103-
export TF_VAR_host_project_id=<HOST_PROJECT_ID>
104-
export TF_VAR_service_project_id=<SERVICE_PROJECT_ID>
105-
export TF_VAR_user_project_id=<USER_PROJECT_ID>
106-
```
107-
108-
### Unit Test
109-
110-
111-
#### Running all the unit test
112-
113-
1. cd REPO_NAME
114-
2. go mod init test
115-
3. go mod tidy
116-
4. **go test -v -json ./... | ./test-summary**
117-
118-
**Note :** test-summary is used to provide summary of the test results. More details [here](https://pkg.go.dev/gocloud.dev/internal/testing/test-summary)
107+
export _TF_SERVICE_ACCOUNT="<ENTER THE SERVICE ACCOUNT HERE>"
108+
export _TF_BUCKET_NAME="<ENTER THE GCS BUCKET NAME HERE>"
109+
export _TF_EXAMPLE3_PREFIX="<ENTER THE GCS PREFIX NAME HERE>"
119110
111+
sed \
112+
-e "s|ENTER_TF_SERVICE_ACCOUNT|$_TF_SERVICE_ACCOUNT|" \
113+
-e "s|ENTER_TF_BUCKET_NAME|$_TF_BUCKET_NAME|" \
114+
-e "s|ENTER_TF_EXAMPLE3_PREFIX|$_TF_EXAMPLE3_PREFIX|" \
115+
examples/3.PSC/provider.tf.template >examples/3.PSC/provider.tf
116+
```
120117

121-
#### Running Example specific test
122-
1. cd /tests/unit/examples/SCENARIO_NAME
123-
2. go mod init test
124-
3. go mod tidy
125-
4. **go test -timeout 12m -v**
118+
- For example : 4.PSC-Across-VPN
126119

127-
**e.g.** Here is an example demonstrating how a unit test for scenario 1 can be executed
128-
```
129-
cd /tests/unit/examples/1.Host-Service-Project
130-
go mod init test
131-
go mod tidy
132-
go test -timeout 12m -v
133-
```
120+
```
121+
export _TF_SERVICE_ACCOUNT="<ENTER THE SERVICE ACCOUNT HERE>"
122+
export _TF_BUCKET_NAME="<ENTER THE GCS BUCKET NAME HERE>"
123+
export _TF_EXAMPLE4_PREFIX="<ENTER THE GCS PREFIX NAME HERE>"
134124
135-
### Integration Test
125+
sed \
126+
-e "s|ENTER_TF_SERVICE_ACCOUNT|$_TF_SERVICE_ACCOUNT|" \
127+
-e "s|ENTER_TF_BUCKET_NAME|$_TF_BUCKET_NAME|" \
128+
-e "s|ENTER_TF_EXAMPLE4_PREFIX|$_TF_EXAMPLE4_PREFIX|" \
129+
examples/4.PSC-Across-VPN/provider.tf.template >examples/4.PSC-Across-VPN/provider.tf
130+
```
136131

137132

138-
#### Running all the integration test
133+
- For example : ServiceNetworkingAcrossInterconnect
139134

140-
1. cd REPO_NAME
141-
2. go mod init test
142-
3. go mod tidy
143-
4. **go test -v -json -timeout 60m ./... | ./test-summary**
135+
```
136+
export _TF_SERVICE_ACCOUNT="<ENTER THE SERVICE ACCOUNT HERE>"
137+
export _TF_BUCKET_NAME="<ENTER THE GCS BUCKET NAME HERE>"
138+
export _TF_EXAMPLE_SNAcrossIC_PREFIX="<ENTER THE GCS PREFIX NAME HERE>"
144139
145-
**Note :** test-summary is used to provide summary of the test results. More details [here](https://pkg.go.dev/gocloud.dev/internal/testing/test-summary)
140+
sed \
141+
-e "s|ENTER_TF_SERVICE_ACCOUNT|$_TF_SERVICE_ACCOUNT|" \
142+
-e "s|ENTER_TF_BUCKET_NAME|$_TF_BUCKET_NAME|" \
143+
-e "s|ENTER_TF_EXAMPLE_SNAcrossIC_PREFIX|$_TF_EXAMPLE_SNAcrossIC_PREFIX|" \
144+
examples/ServiceNetworkingAcrossInterconnect/provider.tf.template >examples/ServiceNetworkingAcrossInterconnect/provider.tf
145+
```
146146

147147

148-
#### Running Example specific test
149-
1. cd /tests/unit/examples/SCENARIO_NAME
150-
2. go mod init test
151-
3. go mod tidy
152-
4. **go test -timeout 60m -v**
148+
## Testing
153149

154-
**e.g.** Here is an example demonstrating how a unit test for scenario 1 can be executed
155-
```
156-
cd /tests/integration/examples/1.Host-Service-Project
157-
go mod init test
158-
go mod tidy
159-
go test -timeout 60m -v
160-
```
150+
For running the unit test cases and integration test cases, please refer to the [test](./test/README.md) documentation.
161151

162152

163153
## Installation
154+
164155
### Terraform
165156
Be sure you have the correct Terraform version (1.5.x), you can choose the binary here:
166157
- https://releases.hashicorp.com/terraform/

examples/1.Host-Service-Project/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ This example solution is a good starting point for anyone who needs to quickly a
2020

2121
## Pre-requisite
2222

23-
1. User should have terraform and gcloud installed in the machine from which they plan to execute this script. Here are the link that describes the [terraform installation](https://developer.hashicorp.com/terraform/tutorials/aws-get-started/install-cli) steps and [gcloud cli installation steps](https://cloud.google.com/sdk/docs/install) .
23+
1. User should have terraform and gcloud installed in the machine from which they plan to execute this script. Here are the link that describes the [terraform installation](https://developer.hashicorp.com/terraform/tutorials/gcp-get-started/install-cli) steps and [gcloud cli installation steps](https://cloud.google.com/sdk/docs/install) .
2424
2. User should have two GCP projects which will be used as part of this guide. First GCP project will act as a Host Project and the Second GCP Project will act as a Service Project.
2525
3. User planning to run this script should have following permissions asssigned to them in the respective projects as described below. User can either use webconsole or gcloud cli to assign these permission to the user identity using which these scripts will be executed. User can follow either step `3.a.` or `3.b.` or `3.c.` to complete this step.
2626
- **Host Project**
@@ -75,7 +75,7 @@ This command creates an execution plan, which lets you preview the changes that
7575
7676
## Examples
7777
78-
1. This example leverages the existing network and subnetwork. Network information like network_name, network_id and subnetword_id should be passed in the terraform.tfvars file. The terraform.tfvars should look like
78+
1. This example leverages the existing network and subnetwork. Network information like network_name, network_id and subnetwork_id should be passed in the terraform.tfvars file. The terraform.tfvars should look like
7979
```
8080
host_project_id = "<GCP-HOST-PROJECT-ID>"
8181
service_project_id = "<GCP-SERVICE-PROJECT-ID>"

examples/1.Host-Service-Project/cloudsql.tf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2023 Google LLC
1+
# Copyright 2023-2024 Google LLC
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.
@@ -17,6 +17,7 @@ module "sql-db" {
1717
name = var.cloudsql_instance_name
1818
database_version = var.database_version
1919
zone = var.zone
20+
region = var.region
2021
project_id = var.service_project_id
2122
ip_configuration = local.ip_configuration
2223
deletion_protection = var.deletion_protection

examples/2.VPC-Across-VPN/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Here is a brief overview of the things being created by the terraform solution :
3131

3232
## Pre-requisite
3333

34-
1. User should have terraform and gcloud installed in the machine from which they plan to execute this script. Here are the link that describes the [terraform installation](https://developer.hashicorp.com/terraform/tutorials/aws-get-started/install-cli) steps and [gcloud cli installation steps](https://cloud.google.com/sdk/docs/install) .
34+
1. User should have terraform and gcloud installed in the machine from which they plan to execute this script. Here are the link that describes the [terraform installation](https://developer.hashicorp.com/terraform/tutorials/gcp-get-started/install-cli) steps and [gcloud cli installation steps](https://cloud.google.com/sdk/docs/install) .
3535
2. User should have three GCP projects which will be used as part of this guide. First GCP project will act as a Host Project, the Second GCP Project will act as a Service Project and the Third GCP project will act as the user project.
3636
3. User planning to run this script should have following permissions asssigned to them in the respective projects as described below. User can either use webconsole or gcloud cli to assign these permission to the user identity using which these scripts will be executed. User can follow either step `3.a.` or `3.b.` or `3.c.` to complete this step.
3737
- **Host Project**
@@ -95,7 +95,7 @@ This command creates an execution plan, which lets you preview the changes that
9595
9696
## Examples
9797
98-
1. This example leverages the existing network and subnetwork. Network information like network_name, network_id and subnetword_id should be passed in the terraform.tfvars file. The terraform.tfvars should look like
98+
1. This example leverages the existing network and subnetwork. Network information like network_name, network_id and subnetwork_id should be passed in the terraform.tfvars file. The terraform.tfvars should look like
9999
```
100100
host_project_id = "<GCP-HOST-PROJECT-ID>"
101101
service_project_id = "<GCP-SERVICE-PROJECT-ID>"

examples/2.VPC-Across-VPN/cloudsql.tf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2023 Google LLC
1+
# Copyright 2023-2024 Google LLC
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.
@@ -17,6 +17,7 @@ module "sql-db" {
1717
name = var.cloudsql_instance_name
1818
database_version = var.database_version
1919
zone = var.zone
20+
region = var.region
2021
project_id = var.service_project_id
2122
ip_configuration = local.ip_configuration
2223
deletion_protection = var.deletion_protection

0 commit comments

Comments
 (0)