Skip to content

Commit 9359bbf

Browse files
authored
Merge pull request #46 from namusyaka/fix-44
avoid name conflicts when replicas recreation
2 parents 3ec25cf + 173a76b commit 9359bbf

File tree

15 files changed

+270
-235
lines changed

15 files changed

+270
-235
lines changed

modules/mysql/README.md

Lines changed: 86 additions & 84 deletions
Large diffs are not rendered by default.

modules/mysql/failover_replica.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
resource "google_sql_database_instance" "failover-replica" {
1818
count = "${var.failover_replica ? 1 : 0}"
1919
project = "${var.project_id}"
20-
name = "${var.name}-failover"
20+
name = "${var.name}-failover${var.failover_replica_name_suffix}"
2121
database_version = "${var.database_version}"
2222
region = "${var.region}"
2323
master_instance_name = "${google_sql_database_instance.default.name}"

modules/mysql/read_replica.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ locals {
3232
resource "google_sql_database_instance" "replicas" {
3333
count = "${var.read_replica_size}"
3434
project = "${var.project_id}"
35-
name = "${var.name}-replica${count.index}"
35+
name = "${var.name}-replica${var.read_replica_name_suffix}${count.index}"
3636
database_version = "${var.database_version}"
3737
region = "${var.region}"
3838
master_instance_name = "${google_sql_database_instance.default.name}"

modules/mysql/variables.tf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,11 @@ variable "read_replica_configuration" {
124124
default = {}
125125
}
126126

127+
variable "read_replica_name_suffix" {
128+
description = "The optional suffix to add to the read instance name"
129+
default = ""
130+
}
131+
127132
variable "read_replica_size" {
128133
description = "The size of read replicas"
129134
default = 0
@@ -211,6 +216,11 @@ variable "failover_replica" {
211216
default = false
212217
}
213218

219+
variable "failover_replica_name_suffix" {
220+
description = "The optional suffix to add to the failover instance name"
221+
default = ""
222+
}
223+
214224
variable "failover_replica_configuration" {
215225
description = "The replica configuration for the failover replica instance. In order to create a failover instance, need to specify this argument."
216226
default = {}

modules/postgresql/README.md

Lines changed: 63 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -6,72 +6,73 @@
66

77
| Name | Description | Type | Default | Required |
88
|------|-------------|:----:|:-----:|:-----:|
9-
| activation\_policy | The activation policy for the master instance.Can be either `ALWAYS`, `NEVER` or `ON_DEMAND`. | string | `"ALWAYS"` | no |
10-
| additional\_databases | A list of databases to be created in your cluster | list | `<list>` | no |
11-
| additional\_users | A list of users to be created in your cluster | list | `<list>` | no |
12-
| authorized\_gae\_applications | The authorized gae applications for the Cloud SQL instances | list | `<list>` | no |
13-
| availability\_type | The availability type for the master instance.This is only used to set up high availability for the PostgreSQL instance. Can be either `ZONAL` or `REGIONAL`. | string | `"ZONAL"` | no |
14-
| backup\_configuration | The backup configuration block of the Cloud SQL resources This argument will be passed through the master instance directrly.<br><br>See [more details](https://www.terraform.io/docs/providers/google/r/sql_database_instance.html). | map | `<map>` | no |
15-
| create\_timeout | The optional timout that is applied to limit long database creates. | string | `"10m"` | no |
16-
| database\_flags | The database flags for the master instance. See [more details](https://cloud.google.com/sql/docs/mysql/flags) | list | `<list>` | no |
17-
| database\_version | The database version to use | string | n/a | yes |
18-
| db\_charset | The charset for the default database | string | `""` | no |
19-
| db\_collation | The collation for the default database. Example: 'en_US.UTF8' | string | `""` | no |
20-
| db\_name | The name of the default database to create | string | `"default"` | no |
21-
| delete\_timeout | The optional timout that is applied to limit long database deletes. | string | `"10m"` | no |
22-
| disk\_autoresize | Configuration to increase storage size. | string | `"true"` | no |
23-
| disk\_size | The disk size for the master instance. | string | `"10"` | no |
24-
| disk\_type | The disk type for the master instance. | string | `"PD_SSD"` | no |
25-
| ip\_configuration | The ip configuration for the master instances. | map | `<map>` | no |
26-
| maintenance\_window\_day | The day of week (1-7) for the master instance maintenance. | string | `"1"` | no |
27-
| maintenance\_window\_hour | The hour of day (0-23) maintenance window for the master instance maintenance. | string | `"23"` | no |
28-
| maintenance\_window\_update\_track | The update track of maintenance window for the master instance maintenance.Can be either `canary` or `stable`. | string | `"canary"` | no |
29-
| name | The name of the Cloud SQL resources | string | n/a | yes |
30-
| pricing\_plan | The pricing plan for the master instance. | string | `"PER_USE"` | no |
31-
| project\_id | The project ID to manage the Cloud SQL resources | string | n/a | yes |
32-
| read\_replica\_activation\_policy | The activation policy for the read replica instances.Can be either `ALWAYS`, `NEVER` or `ON_DEMAND`. | string | `"ALWAYS"` | no |
33-
| read\_replica\_availability\_type | The availability type for the read replica instances.This is only used to set up high availability for the PostgreSQL instances. Can be either `ZONAL` or `REGIONAL`. | string | `"ZONAL"` | no |
34-
| read\_replica\_configuration | The replica configuration for use in read replica | map | `<map>` | no |
35-
| read\_replica\_crash\_safe\_replication | The crash safe replication is to indicates when crash-safe replication flags are enabled. | string | `"true"` | no |
36-
| read\_replica\_database\_flags | The database flags for the read replica instances. See [more details](https://cloud.google.com/sql/docs/mysql/flags) | list | `<list>` | no |
37-
| read\_replica\_disk\_autoresize | Configuration to increase storage size. | string | `"true"` | no |
38-
| read\_replica\_disk\_size | The disk size for the read replica instances. | string | `"10"` | no |
39-
| read\_replica\_disk\_type | The disk type for the read replica instances. | string | `"PD_SSD"` | no |
40-
| read\_replica\_ip\_configuration | The ip configuration for the read instances. | map | `<map>` | no |
41-
| read\_replica\_maintenance\_window\_day | The day of week (1-7) for the read replica instances maintenance. | string | `"1"` | no |
42-
| read\_replica\_maintenance\_window\_hour | The hour of day (0-23) maintenance window for the read replica instances maintenance. | string | `"23"` | no |
43-
| read\_replica\_maintenance\_window\_update\_track | The update track of maintenance window for the read replica instances maintenance.Can be either `canary` or `stable`. | string | `"canary"` | no |
44-
| read\_replica\_pricing\_plan | The pricing plan for the read replica instances. | string | `"PER_USE"` | no |
45-
| read\_replica\_replication\_type | The replication type for read replica instances. Can be one of ASYNCHRONOUS or SYNCHRONOUS. | string | `"SYNCHRONOUS"` | no |
46-
| read\_replica\_size | The size of read replicas | string | `"0"` | no |
47-
| read\_replica\_tier | The tier for the read replica instances. | string | `""` | no |
48-
| read\_replica\_user\_labels | The key/value labels for the read replica instances. | map | `<map>` | no |
49-
| read\_replica\_zones | The zones for the read replica instancess, it should be something like: `a,b,c`. Given zones are used rotationally for creating read replicas. | string | `""` | no |
50-
| region | The region of the Cloud SQL resources | string | `"us-central1"` | no |
51-
| tier | The tier for the master instance. | string | `"db-f1-micro"` | no |
52-
| update\_timeout | The optional timout that is applied to limit long database updates. | string | `"10m"` | no |
53-
| user\_labels | The key/value labels for the master instances. | map | `<map>` | no |
54-
| user\_name | The name of the default user | string | `"default"` | no |
55-
| user\_password | The password for the default user. If not set, a random one will be generated and available in the generated_user_password output variable. | string | `""` | no |
56-
| zone | The zone for the master instance, it should be something like: `a`, `c`. | string | n/a | yes |
9+
| activation_policy | The activation policy for the master instance.Can be either `ALWAYS`, `NEVER` or `ON_DEMAND`. | string | `ALWAYS` | no |
10+
| additional_databases | A list of databases to be created in your cluster | list | `<list>` | no |
11+
| additional_users | A list of users to be created in your cluster | list | `<list>` | no |
12+
| authorized_gae_applications | The authorized gae applications for the Cloud SQL instances | list | `<list>` | no |
13+
| availability_type | The availability type for the master instance.This is only used to set up high availability for the PostgreSQL instance. Can be either `ZONAL` or `REGIONAL`. | string | `ZONAL` | no |
14+
| backup_configuration | The backup configuration block of the Cloud SQL resources This argument will be passed through the master instance directrly.<br><br>See [more details](https://www.terraform.io/docs/providers/google/r/sql_database_instance.html). | map | `<map>` | no |
15+
| create_timeout | The optional timout that is applied to limit long database creates. | string | `10m` | no |
16+
| database_flags | The database flags for the master instance. See [more details](https://cloud.google.com/sql/docs/mysql/flags) | list | `<list>` | no |
17+
| database_version | The database version to use | string | - | yes |
18+
| db_charset | The charset for the default database | string | `` | no |
19+
| db_collation | The collation for the default database. Example: 'en_US.UTF8' | string | `` | no |
20+
| db_name | The name of the default database to create | string | `default` | no |
21+
| delete_timeout | The optional timout that is applied to limit long database deletes. | string | `10m` | no |
22+
| disk_autoresize | Configuration to increase storage size. | string | `true` | no |
23+
| disk_size | The disk size for the master instance. | string | `10` | no |
24+
| disk_type | The disk type for the master instance. | string | `PD_SSD` | no |
25+
| ip_configuration | The ip configuration for the master instances. | map | `<map>` | no |
26+
| maintenance_window_day | The day of week (1-7) for the master instance maintenance. | string | `1` | no |
27+
| maintenance_window_hour | The hour of day (0-23) maintenance window for the master instance maintenance. | string | `23` | no |
28+
| maintenance_window_update_track | The update track of maintenance window for the master instance maintenance.Can be either `canary` or `stable`. | string | `canary` | no |
29+
| name | The name of the Cloud SQL resources | string | - | yes |
30+
| pricing_plan | The pricing plan for the master instance. | string | `PER_USE` | no |
31+
| project_id | The project ID to manage the Cloud SQL resources | string | - | yes |
32+
| read_replica_activation_policy | The activation policy for the read replica instances.Can be either `ALWAYS`, `NEVER` or `ON_DEMAND`. | string | `ALWAYS` | no |
33+
| read_replica_availability_type | The availability type for the read replica instances.This is only used to set up high availability for the PostgreSQL instances. Can be either `ZONAL` or `REGIONAL`. | string | `ZONAL` | no |
34+
| read_replica_configuration | The replica configuration for use in read replica | map | `<map>` | no |
35+
| read_replica_crash_safe_replication | The crash safe replication is to indicates when crash-safe replication flags are enabled. | string | `true` | no |
36+
| read_replica_database_flags | The database flags for the read replica instances. See [more details](https://cloud.google.com/sql/docs/mysql/flags) | list | `<list>` | no |
37+
| read_replica_disk_autoresize | Configuration to increase storage size. | string | `true` | no |
38+
| read_replica_disk_size | The disk size for the read replica instances. | string | `10` | no |
39+
| read_replica_disk_type | The disk type for the read replica instances. | string | `PD_SSD` | no |
40+
| read_replica_ip_configuration | The ip configuration for the read instances. | map | `<map>` | no |
41+
| read_replica_maintenance_window_day | The day of week (1-7) for the read replica instances maintenance. | string | `1` | no |
42+
| read_replica_maintenance_window_hour | The hour of day (0-23) maintenance window for the read replica instances maintenance. | string | `23` | no |
43+
| read_replica_maintenance_window_update_track | The update track of maintenance window for the read replica instances maintenance.Can be either `canary` or `stable`. | string | `canary` | no |
44+
| read_replica_name_suffix | The optional suffix to add to the read instance name | string | `` | no |
45+
| read_replica_pricing_plan | The pricing plan for the read replica instances. | string | `PER_USE` | no |
46+
| read_replica_replication_type | The replication type for read replica instances. Can be one of ASYNCHRONOUS or SYNCHRONOUS. | string | `SYNCHRONOUS` | no |
47+
| read_replica_size | The size of read replicas | string | `0` | no |
48+
| read_replica_tier | The tier for the read replica instances. | string | `` | no |
49+
| read_replica_user_labels | The key/value labels for the read replica instances. | map | `<map>` | no |
50+
| read_replica_zones | The zones for the read replica instancess, it should be something like: `a,b,c`. Given zones are used rotationally for creating read replicas. | string | `` | no |
51+
| region | The region of the Cloud SQL resources | string | `us-central1` | no |
52+
| tier | The tier for the master instance. | string | `db-f1-micro` | no |
53+
| update_timeout | The optional timout that is applied to limit long database updates. | string | `10m` | no |
54+
| user_labels | The key/value labels for the master instances. | map | `<map>` | no |
55+
| user_name | The name of the default user | string | `default` | no |
56+
| user_password | The password for the default user. If not set, a random one will be generated and available in the generated_user_password output variable. | string | `` | no |
57+
| zone | The zone for the master instance, it should be something like: `a`, `c`. | string | - | yes |
5758

5859
## Outputs
5960

6061
| Name | Description |
6162
|------|-------------|
62-
| generated\_user\_password | The auto generated default user password if not input password was provided |
63-
| instance\_address | The IPv4 addesses assigned for the master instance |
64-
| instance\_connection\_name | The connection name of the master instance to be used in connection strings |
65-
| instance\_first\_ip\_address | The first IPv4 address of the addresses assigned. |
66-
| instance\_name | The instance name for the master instance |
67-
| instance\_self\_link | The URI of the master instance |
68-
| instance\_server\_ca\_cert | The CA certificate information used to connect to the SQL instance via SSL |
69-
| instance\_service\_account\_email\_address | The service account email address assigned to the master instance |
70-
| read\_replica\_instance\_names | The instance names for the read replica instances |
71-
| replicas\_instance\_connection\_names | The connection names of the replica instances to be used in connection strings |
72-
| replicas\_instance\_ip\_addresses | The IPv4 addresses assigned for the replica instances |
73-
| replicas\_instance\_self\_links | The URIs of the replica instances |
74-
| replicas\_instance\_server\_ca\_certs | The CA certificates information used to connect to the replica instances via SSL |
75-
| replicas\_instance\_service\_account\_email\_addresses | The service account email addresses assigned to the replica instances |
63+
| generated_user_password | The auto generated default user password if not input password was provided |
64+
| instance_address | The IPv4 addesses assigned for the master instance |
65+
| instance_connection_name | The connection name of the master instance to be used in connection strings |
66+
| instance_first_ip_address | The first IPv4 address of the addresses assigned. |
67+
| instance_name | The instance name for the master instance |
68+
| instance_self_link | The URI of the master instance |
69+
| instance_server_ca_cert | The CA certificate information used to connect to the SQL instance via SSL |
70+
| instance_service_account_email_address | The service account email address assigned to the master instance |
71+
| read_replica_instance_names | The instance names for the read replica instances |
72+
| replicas_instance_connection_names | The connection names of the replica instances to be used in connection strings |
73+
| replicas_instance_ip_addresses | The IPv4 addresses assigned for the replica instances |
74+
| replicas_instance_self_links | The URIs of the replica instances |
75+
| replicas_instance_server_ca_certs | The CA certificates information used to connect to the replica instances via SSL |
76+
| replicas_instance_service_account_email_addresses | The service account email addresses assigned to the replica instances |
7677

7778
[^]: (autogen_docs_end)

modules/postgresql/read_replica.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ locals {
3232
resource "google_sql_database_instance" "replicas" {
3333
count = "${var.read_replica_size}"
3434
project = "${var.project_id}"
35-
name = "${var.name}-replica${count.index}"
35+
name = "${var.name}-replica${var.read_replica_name_suffix}${count.index}"
3636
database_version = "${var.database_version}"
3737
region = "${var.region}"
3838
master_instance_name = "${google_sql_database_instance.default.name}"

modules/postgresql/variables.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,11 @@ variable "read_replica_size" {
126126
default = 0
127127
}
128128

129+
variable "read_replica_name_suffix" {
130+
description = "The optional suffix to add to the read instance name"
131+
default = ""
132+
}
133+
129134
variable "read_replica_tier" {
130135
description = "The tier for the read replica instances."
131136
default = ""

modules/private_service_access/README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,19 @@ that are connected to the same VPC.
1616

1717
| Name | Description | Type | Default | Required |
1818
|------|-------------|:----:|:-----:|:-----:|
19-
| address | First IP address of the IP range to allocate to CLoud SQL instances and other Private Service Access services. If not set, GCP will pick a valid one for you. | string | `""` | no |
20-
| ip\_version | IP Version for the allocation. Can be IPV4 or IPV6. | string | `""` | no |
19+
| address | First IP address of the IP range to allocate to CLoud SQL instances and other Private Service Access services. If not set, GCP will pick a valid one for you. | string | `` | no |
20+
| ip_version | IP Version for the allocation. Can be IPV4 or IPV6. | string | `` | no |
2121
| labels | The key/value labels for the IP range allocated to the peered network. | map | `<map>` | no |
22-
| prefix\_length | Prefix length of the IP range reserved for Cloud SQL instances and other Private Service Access services. Defaults to /16. | string | `"16"` | no |
23-
| project\_id | The project ID of the VPC network to peer. This can be a shared VPC host projec. | string | n/a | yes |
24-
| vpc\_network | Name of the VPC network to peer. | string | n/a | yes |
22+
| prefix_length | Prefix length of the IP range reserved for Cloud SQL instances and other Private Service Access services. Defaults to /16. | string | `16` | no |
23+
| project_id | The project ID of the VPC network to peer. This can be a shared VPC host projec. | string | - | yes |
24+
| vpc_network | Name of the VPC network to peer. | string | - | yes |
2525

2626
## Outputs
2727

2828
| Name | Description |
2929
|------|-------------|
3030
| address | First IP of the reserved range. |
31-
| google\_compute\_global\_address\_name | URL of the reserved range. |
32-
| peering\_completed | Use for enforce ordering between resource creation |
31+
| google_compute_global_address_name | URL of the reserved range. |
32+
| peering_completed | Use for enforce ordering between resource creation |
3333

3434
[^]: (autogen_docs_end)

0 commit comments

Comments
 (0)