0
0
GCPcloud~30 mins

Read replicas in GCP - Mini Project: Build & Apply

Choose your learning style9 modes available
Setting Up Read Replicas in Google Cloud SQL
📖 Scenario: You are managing a Google Cloud SQL database for a growing web application. To improve read performance and reduce load on the primary database, you want to create read replicas.This project will guide you through creating a Cloud SQL instance, configuring a read replica, and setting the necessary parameters.
🎯 Goal: Build a Google Cloud SQL primary instance and a read replica instance using Terraform configuration files.This setup will help distribute read traffic and improve database scalability.
📋 What You'll Learn
Create a primary Cloud SQL instance with MySQL version 8.0
Define a variable for the instance region
Create a read replica instance linked to the primary instance
Configure the read replica with appropriate settings
💡 Why This Matters
🌍 Real World
Read replicas help distribute database read traffic, improving performance and scalability for applications with many users.
💼 Career
Cloud architects and DevOps engineers often configure read replicas to optimize database workloads and ensure high availability.
Progress0 / 4 steps
1
Create the primary Cloud SQL instance resource
Create a Terraform resource called google_sql_database_instance named primary_instance with name = "primary-db-instance", database_version = "MYSQL_8_0", and region = "us-central1". Use the settings block with tier = "db-f1-micro".
GCP
Need a hint?

Use the google_sql_database_instance resource with the exact name primary_instance. Set the name, database_version, and region as specified. Inside settings, set the tier to db-f1-micro.

2
Add a variable for the instance region
Create a Terraform variable called instance_region with default = "us-central1".
GCP
Need a hint?

Define a variable named instance_region with the default value "us-central1". Then update the region in the primary instance resource to use var.instance_region.

3
Create the read replica instance resource
Create a Terraform resource called google_sql_database_instance named read_replica with name = "read-replica-instance", region = var.instance_region, and database_version = "MYSQL_8_0". Add a replica_configuration block with replica_name = "read-replica-1" and primary_instance_name = google_sql_database_instance.primary_instance.name. Use the settings block with tier = "db-f1-micro".
GCP
Need a hint?

Create a new resource named read_replica of type google_sql_database_instance. Set the name, region, and database_version. Inside replica_configuration, set replica_name and link to the primary instance using primary_instance_name. Add settings with the tier.

4
Enable backup and maintenance window on the primary instance
Add a backup_configuration block to google_sql_database_instance.primary_instance with enabled = true. Also add a maintenance_window block with day = 7, hour = 3, and update_track = "stable".
GCP
Need a hint?

Inside the primary_instance resource, add a backup_configuration block with enabled = true. Also add a maintenance_window block with the specified day, hour, and update_track values.