Skip to content

Commit d0277dc

Browse files
author
Aaron Lane
authored
Merge pull request #70 from paulpalamarchuk/improve_master_authorized_networks_example
Add separated example for public instances
2 parents 27cdc22 + 657897d commit d0277dc

File tree

22 files changed

+267
-11
lines changed

22 files changed

+267
-11
lines changed

examples/mysql-and-postgres/README.md renamed to examples/mysql-and-postgres-private/README.md

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Cloud SQL Database Example
22

3-
This example shows how create Cloud SQL databases for for MySQL and PostgreSQL using the Terraform module.
3+
This example shows how create private Cloud SQL databases for for MySQL and PostgreSQL using the Terraform module.
44

55
**Figure 1.** *diagram of Google Cloud resources*
66

@@ -78,3 +78,29 @@ killall cloud_sql_proxy
7878
```bash
7979
terraform destroy
8080
```
81+
82+
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
83+
## Inputs
84+
85+
| Name | Description | Type | Default | Required |
86+
|------|-------------|:----:|:-----:|:-----:|
87+
| mysql\_version | | string | `"MYSQL_5_6"` | no |
88+
| network | | string | `"default"` | no |
89+
| network\_name | | string | `"mysql-psql-example"` | no |
90+
| postgresql\_version | | string | `"POSTGRES_9_6"` | no |
91+
| project\_id | | string | n/a | yes |
92+
| region | | string | `"us-central1"` | no |
93+
| zone | | string | `"us-central1-b"` | no |
94+
95+
## Outputs
96+
97+
| Name | Description |
98+
|------|-------------|
99+
| mysql\_conn | The connection name of the master instance to be used in connection strings |
100+
| mysql\_user\_pass | The password for the default user. If not set, a random one will be generated and available in the generated_user_password output variable. |
101+
| psql\_conn | The connection name of the master instance to be used in connection strings |
102+
| psql\_user\_pass | The password for the default user. If not set, a random one will be generated and available in the generated_user_password output variable. |
103+
| safer\_mysql\_conn | The connection name of the master instance to be used in connection strings |
104+
| safer\_mysql\_user\_pass | The password for the default user. If not set, a random one will be generated and available in the generated_user_password output variable. |
105+
106+
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
File renamed without changes.
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Cloud SQL Database Example
2+
3+
This example shows how create public Cloud SQL databases for for MySQL and PostgreSQL using the Terraform module.
4+
5+
## Run Terraform
6+
7+
Create resources with terraform:
8+
9+
```bash
10+
terraform init
11+
terraform plan
12+
terraform apply
13+
```
14+
15+
To remove all resources created by terraform:
16+
17+
```bash
18+
terraform destroy
19+
```
20+
21+
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
22+
## Inputs
23+
24+
| Name | Description | Type | Default | Required |
25+
|------|-------------|:----:|:-----:|:-----:|
26+
| authorized\_networks | List of mapped public networks authorized to access to the instances. Default - short range of GCP health-checkers IPs | list(map(string)) | `<list>` | no |
27+
| mysql\_version | The MySQL version to use. | string | `"MYSQL_5_6"` | no |
28+
| postgresql\_version | The PostgreSQL version to use. | string | `"POSTGRES_9_6"` | no |
29+
| project\_id | The ID of the project in which resources will be provisioned. | string | `"null"` | no |
30+
| region | The region to host the instance. | string | `"us-central1"` | no |
31+
32+
## Outputs
33+
34+
| Name | Description |
35+
|------|-------------|
36+
| mysql\_conn | The connection name of the master instance to be used in connection strings |
37+
| mysql\_user\_pass | The password for the default user. If not set, a random one will be generated and available in the generated_user_password output variable. |
38+
| psql\_conn | The connection name of the master instance to be used in connection strings |
39+
| psql\_user\_pass | The password for the default user. If not set, a random one will be generated and available in the generated_user_password output variable. |
40+
41+
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/**
2+
* Copyright 2019 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
provider "google" {
18+
version = "~> 2.13"
19+
}
20+
21+
provider "google-beta" {
22+
version = "~> 2.13"
23+
}
24+
25+
resource "random_id" "name" {
26+
byte_length = 2
27+
}
28+
29+
module "mysql-db" {
30+
source = "../../modules/mysql"
31+
name = "example-mysql-${random_id.name.hex}"
32+
database_version = var.mysql_version
33+
project_id = var.project_id
34+
zone = "c"
35+
region = var.region
36+
37+
ip_configuration = {
38+
ipv4_enabled = true
39+
private_network = null
40+
require_ssl = true
41+
authorized_networks = var.authorized_networks
42+
}
43+
44+
45+
database_flags = [
46+
{
47+
name = "log_bin_trust_function_creators"
48+
value = "on"
49+
},
50+
]
51+
}
52+
53+
module "postgresql-db" {
54+
source = "../../modules/postgresql"
55+
name = "example-postgresql-${random_id.name.hex}"
56+
database_version = var.postgresql_version
57+
project_id = var.project_id
58+
zone = "c"
59+
region = var.region
60+
61+
ip_configuration = {
62+
ipv4_enabled = true
63+
private_network = null
64+
require_ssl = true
65+
authorized_networks = var.authorized_networks
66+
}
67+
}
68+
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/**
2+
* Copyright 2019 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
output "mysql_conn" {
18+
value = module.mysql-db.instance_connection_name
19+
description = "The connection name of the master instance to be used in connection strings"
20+
}
21+
22+
output "mysql_user_pass" {
23+
value = module.mysql-db.generated_user_password
24+
description = "The password for the default user. If not set, a random one will be generated and available in the generated_user_password output variable."
25+
}
26+
27+
output "psql_conn" {
28+
value = module.postgresql-db.instance_connection_name
29+
description = "The connection name of the master instance to be used in connection strings"
30+
}
31+
32+
output "psql_user_pass" {
33+
value = module.postgresql-db.generated_user_password
34+
description = "The password for the default user. If not set, a random one will be generated and available in the generated_user_password output variable."
35+
}

0 commit comments

Comments
 (0)