Skip to content

feat(cloudsql-instance): allow overriding tier per read replica#28

Merged
Calvin-Cheng1 merged 2 commits into
google:mainfrom
piotr-tokaj:feat/cloudsql-instance-replica-tier
May 15, 2026
Merged

feat(cloudsql-instance): allow overriding tier per read replica#28
Calvin-Cheng1 merged 2 commits into
google:mainfrom
piotr-tokaj:feat/cloudsql-instance-replica-tier

Conversation

@piotr-tokaj
Copy link
Copy Markdown
Contributor

What

Adds an optional tier field to the per-replica object in var.replicas:

variable "replicas" {
  description = "Map of NAME=> {REGION, KMS_KEY, TIER} for additional read replicas. Tier defaults to the primary instance tier when unset. Set to null to disable replica creation."
  type = map(object({
    region              = string
    encryption_key_name = optional(string)
    tier                = optional(string)
  }))
  default  = {}
  nullable = false
}

and uses it on google_sql_database_instance.replicas:

tier = coalesce(each.value.tier, var.tier)

Why

Cloud SQL allows a read replica to have a different machine tier from its primary, and this is genuinely useful:

  • Cost — analytics / reporting replicas often handle a fraction of the primary's QPS and can run on a much smaller tier.
  • Validation — you can move a single replica to a bigger / smaller tier first to observe behaviour before resizing the primary.
  • Regional sizing — a replica in a cheaper or more constrained region may need a different tier than the primary.

Today the module hardcodes every replica to var.tier, so the only workaround is to manage replicas outside the module.

Compatibility

  • The new field is optional(string), so existing callers that pass replicas = { ... } without a tier key are unaffected: coalesce(null, var.tier) returns var.tier, which is exactly today's behaviour.
  • The field lives on the per-replica object, so different replicas can have different tiers (or inherit).
  • Does not touch the primary's tier handling.

Does not conflict with the sibling retain-backups change (#27) — that one touches var.tier-adjacent variables.tf only to add a separate variable and edits the settings {} block to wire it in; this PR's only main.tf change is the tier = coalesce(...) line, and its only variables.tf change is the replicas type/description.

Adds an optional "tier" field to the replicas map (default unset, in
which case the primary's var.tier is used via coalesce). This lets
users size read replicas independently of the primary - useful for
cost optimisation when replicas serve lighter analytics workloads, or
for validating a bigger/smaller machine type on a replica before
resizing the primary.

Made-with: Cursor
@google-cla
Copy link
Copy Markdown

google-cla Bot commented Apr 19, 2026

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@aghassemlouei aghassemlouei added the enhancement New feature or request label May 1, 2026
@aghassemlouei aghassemlouei moved this from Todo to In Review in stellar-engine May 1, 2026
Comment thread modules/cloudsql-instance/variables.tf
@piotr-tokaj piotr-tokaj requested a review from Calvin-Cheng1 May 15, 2026 10:03
Copy link
Copy Markdown
Collaborator

@Calvin-Cheng1 Calvin-Cheng1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Calvin-Cheng1 Calvin-Cheng1 merged commit 77f1953 into google:main May 15, 2026
1 check passed
@github-project-automation github-project-automation Bot moved this from In Review to Done in stellar-engine May 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants