Skip to content

sql: support in-place storage shrink for google_sql_database_instance#18327

Open
DrFaust92 wants to merge 1 commit into
GoogleCloudPlatform:mainfrom
DrFaust92:sql-in-place-storage-shrink
Open

sql: support in-place storage shrink for google_sql_database_instance#18327
DrFaust92 wants to merge 1 commit into
GoogleCloudPlatform:mainfrom
DrFaust92:sql-in-place-storage-shrink

Conversation

@DrFaust92

Copy link
Copy Markdown
Contributor

Summary

Reducing disk_size on google_sql_database_instance (with disk_autoresize disabled) previously forced the instance to be recreated — a destructive operation for a data disk. Cloud SQL now supports reducing storage in place via the dedicated Instances.PerformDiskShrink operation (GA for MySQL/PostgreSQL, and available for SQL Server).

This change wires that up:

  • diskSizeCutomizeDiff no longer calls ForceNew on a shrink; the shrink is kept as an in-place update.
  • On update, a disk_size decrease is carried out with Projects.Instances.PerformDiskShrink (the settings update keeps the current size, so it's a no-op for disk).
  • A pre-flight GetDiskShrinkConfig call returns a clear error when the requested size is below the instance's current minimum shrinkable size, instead of letting the shrink operation start and then fail.
  • disk_size field docs updated.

Increases are unaffected (still applied via the settings update). A shrink with disk_autoresize enabled continues to be ignored, as before.

Tests

Acceptance tests were run against real GCP:

  • TestAccSqlDatabaseInstance_storageShrink (new) — creates a 100GB instance and shrinks it in place to 90GB, asserting the disk size and that the instance is not recreated (same ID). PASS
  • TestAccSqlDatabaseInstance_DiskSizeAutoResizeWithDiskSize (updated) — the step that previously asserted a forced recreate now asserts an in-place update plan (PlanOnly + ExpectNonEmptyPlan). PASS

Note: storage shrink is not supported on shared-core machine types, so the new test uses a db-custom-* tier.

Release Note

sql: `google_sql_database_instance` now performs an in-place storage shrink when `disk_size` is reduced with `disk_autoresize` disabled, instead of forcing instance recreation

Reducing `disk_size` (with `disk_autoresize` disabled) previously forced
the instance to be recreated. Use the dedicated Instances.PerformDiskShrink
operation to shrink storage in place instead, with a pre-flight
GetDiskShrinkConfig check that returns a clear error when the requested
size is below the instance's minimum shrinkable size.
@modular-magician modular-magician added the awaiting-approval Pull requests that need reviewer's approval to run presubmit tests label Jul 19, 2026
@github-actions
github-actions Bot requested a review from shuyama1 July 19, 2026 02:24
@github-actions

Copy link
Copy Markdown

Googlers: For automatic test runs see go/terraform-auto-test-runs.

@shuyama1, a repository maintainer, has been assigned to review your changes. If you have not received review feedback within 2 business days, please leave a comment on this PR asking them to take a look.

You can help make sure that review is quick by doing a self-review and by running impacted tests locally.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting-approval Pull requests that need reviewer's approval to run presubmit tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants