Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
182 changes: 182 additions & 0 deletions mysql_instance_read_pool/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
/**
* Copyright 2025 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_mysql_create_read_pool]

resource "google_sql_database_instance" "primary" {
name = "mysql-primary"
database_version = "MYSQL_8_0"
region = "europe-west4"

instance_type = "CLOUD_SQL_INSTANCE"

# If you wish to, set deletion_protection to true to prevent
# accidental deletion of this instance as a result of removing the
# Terraform resource.
deletion_protection = false

settings {
tier = "db-perf-optimized-N-2"
edition = "ENTERPRISE_PLUS"

backup_configuration {
enabled = true
binary_log_enabled = true
}

ip_configuration {
ipv4_enabled = true
}
}
}

resource "google_sql_database_instance" "replica" {
name = "mysql-replica"
database_version = "MYSQL_8_0"
region = "europe-west4"

master_instance_name = google_sql_database_instance.primary.name
instance_type = "READ_POOL_INSTANCE"
node_count = 2

# If you wish to, set deletion_protection to true to prevent
# accidental deletion of this instance as a result of removing the
# Terraform resource.
deletion_protection = false

settings {
tier = "db-perf-optimized-N-2"
edition = "ENTERPRISE_PLUS"

ip_configuration {
ipv4_enabled = true
}
}
}

# [END cloud_sql_mysql_create_read_pool]

# [START cloud_sql_mysql_convert_read_replica_to_read_pool]

resource "google_sql_database_instance" "replica" {
name = "mysql-replica"
database_version = "MYSQL_8_0"
region = "europe-west4"

master_instance_name = google_sql_database_instance.primary.name
instance_type = "READ_POOL_INSTANCE"
node_count = 2

# If you wish to, set deletion_protection to true to prevent
# accidental deletion of this instance as a result of removing the
# Terraform resource.
deletion_protection = false

settings {
tier = "db-perf-optimized-N-2"
edition = "ENTERPRISE_PLUS"

ip_configuration {
ipv4_enabled = true
}
}
}

# [END cloud_sql_mysql_convert_read_replica_to_read_pool]

# [START cloud_sql_mysql_convert_read_pool_to_read_replica]

resource "google_sql_database_instance" "replica" {
name = "mysql-replica"
database_version = "MYSQL_8_0"
region = "europe-west4"

master_instance_name = google_sql_database_instance.primary.name
instance_type = "READ_REPLICA_INSTANCE"

# If you wish to, set deletion_protection to true to prevent
# accidental deletion of this instance as a result of removing the
# Terraform resource.
deletion_protection = false

settings {
tier = "db-perf-optimized-N-2"
edition = "ENTERPRISE_PLUS"
availability_type = "ZONAL"

ip_configuration {
ipv4_enabled = true
}
}
}

# [END cloud_sql_mysql_convert_read_pool_to_read_replica]

# [START cloud_sql_mysql_update_read_pool_node_count]

resource "google_sql_database_instance" "replica" {
name = "mysql-replica"
database_version = "MYSQL_8_0"
region = "europe-west4"

master_instance_name = google_sql_database_instance.primary.name
instance_type = "READ_POOL_INSTANCE"
node_count = 4

# If you wish to, set deletion_protection to true to prevent
# accidental deletion of this instance as a result of removing the
# Terraform resource.
deletion_protection = false

settings {
tier = "db-perf-optimized-N-2"
edition = "ENTERPRISE_PLUS"

ip_configuration {
ipv4_enabled = true
}
}
}

# [END cloud_sql_mysql_update_read_pool_node_count]

# [START cloud_sql_mysql_edit_read_pool_configuration]

resource "google_sql_database_instance" "replica" {
name = "mysql-replica"
database_version = "MYSQL_8_0"
region = "europe-west4"

master_instance_name = google_sql_database_instance.primary.name
instance_type = "READ_POOL_INSTANCE"
node_count = 2

# If you wish to, set deletion_protection to true to prevent
# accidental deletion of this instance as a result of removing the
# Terraform resource.
deletion_protection = false

settings {
tier = "db-perf-optimized-N-4"
edition = "ENTERPRISE_PLUS"

ip_configuration {
ipv4_enabled = true
}
}
}

# [END cloud_sql_mysql_edit_read_pool_configuration]
20 changes: 20 additions & 0 deletions mysql_instance_read_pool/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Copyright 2025 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_read_pool
spec:
skip: true