Skip to content

Commit

Permalink
feat: Rework replicas to use for_each and new configuration style
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Replica configuration has been reworked. Please see the upgrade guide for details.
  • Loading branch information
Dev25 committed Jun 5, 2020
1 parent 7c8c799 commit 5e1ae20
Show file tree
Hide file tree
Showing 23 changed files with 238 additions and 1,226 deletions.
102 changes: 49 additions & 53 deletions examples/mysql-ha/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

provider "google" {
version = "~> 3.5"
version = "~> 3.22"
}

provider "null" {
Expand All @@ -37,8 +37,22 @@ locals {
See https://cloud.google.com/sql/docs/mysql/delete-instance for details.
*/
instance_name = "${var.mysql_ha_name}-${random_id.instance_name_suffix.hex}"

read_replica_ip_configuration = {
ipv4_enabled = true
require_ssl = false
private_network = null
authorized_networks = [
{
name = "${var.project_id}-cidr"
value = var.mysql_ha_external_ip_range
},
]
}

}


module "mysql" {
source = "../../modules/mysql"
name = local.instance_name
Expand All @@ -54,12 +68,7 @@ module "mysql" {
maintenance_window_hour = 12
maintenance_window_update_track = "stable"

database_flags = [
{
name = "long_query_time"
value = 1
},
]
database_flags = [{ name = "long_query_time", value = 1 }]

user_labels = {
foo = "bar"
Expand All @@ -84,56 +93,43 @@ module "mysql" {
}

// Read replica configurations
read_replica_name_suffix = "-test"
read_replica_size = 3
read_replica_tier = "db-n1-standard-1"
read_replica_zones = "a,b,c"
read_replica_activation_policy = "ALWAYS"
read_replica_crash_safe_replication = true
read_replica_disk_autoresize = true
read_replica_disk_type = "PD_HDD"
read_replica_replication_type = "SYNCHRONOUS"
read_replica_maintenance_window_day = 1
read_replica_maintenance_window_hour = 22
read_replica_maintenance_window_update_track = "stable"

read_replica_user_labels = {
bar = "baz"
}

read_replica_database_flags = [
read_replica_name_suffix = "-test"
read_replicas = [
{
name = "long_query_time"
value = "1"
name = "0"
zone = "us-central1-a"
tier = "db-n1-standard-1"
ip_configuration = local.read_replica_ip_configuration
database_flags = [{ name = "long_query_time", value = 1 }]
disk_autoresize = null
disk_size = null
disk_type = "PD_HDD"
user_labels = { bar = "baz" }
},
{
name = "1"
zone = "us-central1-b"
tier = "db-n1-standard-1"
ip_configuration = local.read_replica_ip_configuration
database_flags = [{ name = "long_query_time", value = 1 }]
disk_autoresize = null
disk_size = null
disk_type = "PD_HDD"
user_labels = { bar = "baz" }
},
{
name = "2"
zone = "us-central1-c"
tier = "db-n1-standard-1"
ip_configuration = local.read_replica_ip_configuration
database_flags = [{ name = "long_query_time", value = 1 }]
disk_autoresize = null
disk_size = null
disk_type = "PD_HDD"
user_labels = { bar = "baz" }
},
]

read_replica_configuration = {
dump_file_path = "gs://${var.project_id}.appspot.com/tmp"
connect_retry_interval = 5
ca_certificate = null
client_certificate = null
client_key = null
failover_target = null
master_heartbeat_period = null
password = null
ssl_cipher = null
username = null
verify_server_certificate = null
}

read_replica_ip_configuration = {
ipv4_enabled = true
require_ssl = false
private_network = null
authorized_networks = [
{
name = "${var.project_id}-cidr"
value = var.mysql_ha_external_ip_range
},
]
}

db_name = var.mysql_ha_name
db_charset = "utf8mb4"
db_collation = "utf8mb4_general_ci"
Expand Down
4 changes: 2 additions & 2 deletions examples/mysql-private/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
*/

provider "google" {
version = "~> 3.5"
version = "~> 3.22"
}

provider "google-beta" {
version = "~> 3.5"
version = "~> 3.22"
}

provider "null" {
Expand Down
2 changes: 1 addition & 1 deletion examples/mysql-public/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

provider "google" {
version = "~> 3.5"
version = "~> 3.22"
}

provider "null" {
Expand Down
99 changes: 47 additions & 52 deletions examples/postgresql-ha/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

provider "google" {
version = "~> 3.5"
version = "~> 3.22"
}

provider "null" {
Expand All @@ -37,6 +37,18 @@ locals {
See https://cloud.google.com/sql/docs/mysql/delete-instance for details.
*/
instance_name = "${var.pg_ha_name}-${random_id.instance_name_suffix.hex}"

read_replica_ip_configuration = {
ipv4_enabled = true
require_ssl = false
private_network = null
authorized_networks = [
{
name = "${var.project_id}-cidr"
value = var.pg_ha_external_ip_range
},
]
}
}

module "pg" {
Expand All @@ -54,12 +66,7 @@ module "pg" {
maintenance_window_hour = 12
maintenance_window_update_track = "stable"

database_flags = [
{
name = "autovacuum"
value = "off"
},
]
database_flags = [{ name = "autovacuum", value = "off" }]

user_labels = {
foo = "bar"
Expand All @@ -83,56 +90,44 @@ module "pg" {
}

// Read replica configurations
read_replica_name_suffix = "-test"
read_replica_size = 3
read_replica_tier = "db-custom-2-13312"
read_replica_zones = "a,b,c"
read_replica_activation_policy = "ALWAYS"
read_replica_crash_safe_replication = true
read_replica_disk_autoresize = true
read_replica_disk_type = "PD_HDD"
read_replica_replication_type = "SYNCHRONOUS"
read_replica_maintenance_window_day = 1
read_replica_maintenance_window_hour = 22
read_replica_maintenance_window_update_track = "stable"

read_replica_user_labels = {
bar = "baz"
}
read_replica_name_suffix = "-test"

read_replica_database_flags = [
read_replicas = [
{
name = "0"
zone = "us-central1-a"
tier = "db-custom-2-13312"
ip_configuration = local.read_replica_ip_configuration
database_flags = [{ name = "autovacuum", value = "off" }]
disk_autoresize = null
disk_size = null
disk_type = "PD_HDD"
user_labels = { bar = "baz" }
},
{
name = "1"
zone = "us-central1-b"
tier = "db-custom-2-13312"
ip_configuration = local.read_replica_ip_configuration
database_flags = [{ name = "autovacuum", value = "off" }]
disk_autoresize = null
disk_size = null
disk_type = "PD_HDD"
user_labels = { bar = "baz" }
},
{
name = "autovacuum"
value = "off"
name = "2"
zone = "us-central1-c"
tier = "db-custom-2-13312"
ip_configuration = local.read_replica_ip_configuration
database_flags = [{ name = "autovacuum", value = "off" }]
disk_autoresize = null
disk_size = null
disk_type = "PD_HDD"
user_labels = { bar = "baz" }
},
]

read_replica_configuration = {
dump_file_path = "gs://${var.project_id}.appspot.com/tmp"
connect_retry_interval = 5
ca_certificate = null
client_certificate = null
client_key = null
failover_target = null
master_heartbeat_period = null
password = null
ssl_cipher = null
username = null
verify_server_certificate = null
}

read_replica_ip_configuration = {
ipv4_enabled = true
require_ssl = false
private_network = null
authorized_networks = [
{
name = "${var.project_id}-cidr"
value = var.pg_ha_external_ip_range
},
]
}

db_name = var.pg_ha_name
db_charset = "UTF8"
db_collation = "en_US.UTF8"
Expand Down
2 changes: 1 addition & 1 deletion examples/postgresql-public/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

provider "google" {
version = "~> 3.5"
version = "~> 3.22"
}

provider "google-beta" {
Expand Down
42 changes: 1 addition & 41 deletions modules/mysql/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,6 @@
| disk\_size | The disk size for the master instance | number | `"10"` | no |
| disk\_type | The disk type for the master instance. | string | `"PD_SSD"` | no |
| encryption\_key\_name | The full path to the encryption key used for the CMEK disk encryption | string | `"null"` | no |
| failover\_replica | Specify true if the failover instance is required | bool | `"false"` | no |
| failover\_replica\_activation\_policy | The activation policy for the failover replica instance. Can be either `ALWAYS`, `NEVER` or `ON_DEMAND`. | string | `"ALWAYS"` | no |
| failover\_replica\_configuration | The replica configuration for the failover replica instance. In order to create a failover instance, need to specify this argument. | object | `<map>` | no |
| failover\_replica\_crash\_safe\_replication | The crash safe replication is to indicates when crash-safe replication flags are enabled. | bool | `"true"` | no |
| failover\_replica\_database\_flags | The database flags for the failover replica instance. See [more details](https://cloud.google.com/sql/docs/mysql/flags) | object | `<list>` | no |
| failover\_replica\_disk\_autoresize | Configuration to increase storage size. | bool | `"true"` | no |
| failover\_replica\_disk\_size | The disk size for the failover replica instance. | number | `"10"` | no |
| failover\_replica\_disk\_type | The disk type for the failover replica instance. | string | `"PD_SSD"` | no |
| failover\_replica\_ip\_configuration | The ip configuration for the failover replica instances. | object | `<map>` | no |
| failover\_replica\_maintenance\_window\_day | The day of week (1-7) for the failover replica instance maintenance. | number | `"1"` | no |
| failover\_replica\_maintenance\_window\_hour | The hour of day (0-23) maintenance window for the failover replica instance maintenance. | number | `"23"` | no |
| failover\_replica\_maintenance\_window\_update\_track | The update track of maintenance window for the failover replica instance maintenance. Can be either `canary` or `stable`. | string | `"canary"` | no |
| failover\_replica\_name\_suffix | The optional suffix to add to the failover instance name | string | `""` | no |
| failover\_replica\_pricing\_plan | The pricing plan for the failover replica instance. | string | `"PER_USE"` | no |
| failover\_replica\_replication\_type | The replication type for the failover replica instance. Can be one of ASYNCHRONOUS or SYNCHRONOUS. | string | `"SYNCHRONOUS"` | no |
| failover\_replica\_tier | The tier for the failover replica instance. | string | `""` | no |
| failover\_replica\_user\_labels | The key/value labels for the failover replica instance. | map(string) | `<map>` | no |
| failover\_replica\_zone | The zone for the failover replica instance, it should be something like: `a`, `c`. | string | `""` | no |
| ip\_configuration | The ip_configuration settings subblock | object | `<map>` | no |
| maintenance\_window\_day | The day of week (1-7) for the master instance maintenance. | number | `"1"` | no |
| maintenance\_window\_hour | The hour of day (0-23) maintenance window for the master instance maintenance. | number | `"23"` | no |
Expand All @@ -49,24 +31,8 @@
| pricing\_plan | The pricing plan for the master instance. | string | `"PER_USE"` | no |
| project\_id | The project ID to manage the Cloud SQL resources | string | n/a | yes |
| random\_instance\_name | Sets random suffix at the end of the Cloud SQL resource name | bool | `"false"` | no |
| read\_replica\_activation\_policy | The activation policy for the read replica instances. Can be either `ALWAYS`, `NEVER` or `ON_DEMAND`. | string | `"ALWAYS"` | no |
| read\_replica\_configuration | The replica configuration for use in all read replica instances. | object | `<map>` | no |
| read\_replica\_crash\_safe\_replication | The crash safe replication is to indicates when crash-safe replication flags are enabled. | bool | `"true"` | no |
| read\_replica\_database\_flags | The database flags for the read replica instances. See [more details](https://cloud.google.com/sql/docs/mysql/flags) | object | `<list>` | no |
| read\_replica\_disk\_autoresize | Configuration to increase storage size. | bool | `"true"` | no |
| read\_replica\_disk\_size | The disk size for the read replica instances. | number | `"10"` | no |
| read\_replica\_disk\_type | The disk type for the read replica instances. | string | `"PD_SSD"` | no |
| read\_replica\_ip\_configuration | The ip configuration for the read replica instances. | object | `<map>` | no |
| read\_replica\_maintenance\_window\_day | The day of week (1-7) for the read replica instances maintenance. | number | `"1"` | no |
| read\_replica\_maintenance\_window\_hour | The hour of day (0-23) maintenance window for the read replica instances maintenance. | number | `"23"` | no |
| 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 |
| read\_replica\_name\_suffix | The optional suffix to add to the read instance name | string | `""` | no |
| read\_replica\_pricing\_plan | The pricing plan for the read replica instances. | string | `"PER_USE"` | no |
| read\_replica\_replication\_type | The replication type for read replica instances. Can be one of ASYNCHRONOUS or SYNCHRONOUS. | string | `"SYNCHRONOUS"` | no |
| read\_replica\_size | The size of read replicas | number | `"0"` | no |
| read\_replica\_tier | The tier for the read replica instances. | string | `""` | no |
| read\_replica\_user\_labels | The key/value labels for the read replica instances. | map(string) | `<map>` | no |
| 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 |
| read\_replicas | List of read replicas to create | object | `<list>` | no |
| region | The region of the Cloud SQL resources | string | `"us-central1"` | no |
| tier | The tier for the master instance. | string | `"db-n1-standard-1"` | no |
| update\_timeout | The optional timout that is applied to limit long database updates. | string | `"10m"` | no |
Expand All @@ -80,12 +46,6 @@

| Name | Description |
|------|-------------|
| failover-replica\_instance\_connection\_name | The connection name of the failover-replica instance to be used in connection strings |
| failover-replica\_instance\_first\_ip\_address | The first IPv4 address of the addresses assigned for the failover-replica instance |
| failover-replica\_instance\_name | The instance name for the failover replica instance |
| failover-replica\_instance\_self\_link | The URI of the failover-replica instance |
| failover-replica\_instance\_server\_ca\_cert | The CA certificate information used to connect to the failover-replica instance via SSL |
| failover-replica\_instance\_service\_account\_email\_address | The service account email addresses assigned to the failover-replica instance |
| generated\_user\_password | The auto generated default user password if not input password was provided |
| instance\_connection\_name | The connection name of the master instance to be used in connection strings |
| instance\_first\_ip\_address | The first IPv4 address of the addresses assigned for the master instance. |
Expand Down

0 comments on commit 5e1ae20

Please sign in to comment.